Examples of JSONResponse


Examples of com.almende.eve.rpc.jsonrpc.JSONResponse

            // to add namespace to method name for JSON-RPC.
            if (method.getName().equals("getId")) {
              return proxyId;
            } else if (method.getName().equals("receive")
                && args.length > 1) {
              JSONResponse response = null;
              if (args[0] != null) {
                response = receive(args[0]);
              }
              if (response != null) {
                JsonNode id = null;
                if (response.getId() != null) {
                  id = response.getId();
                }
                final AsyncCallbackQueue<JSONResponse> cbs = host
                    .getCallbackQueue(proxyId,
                        JSONResponse.class);
                if (cbs != null) {
                  final AsyncCallback<JSONResponse> callback = cbs
                      .pull(id);
                  if (callback != null) {
                    if (response.getError() != null) {
                      callback.onFailure(response
                          .getError());
                    } else {
                      callback.onSuccess(response);
                    }
                  }
                }
              }
              return null;
            } else {
             
              final JSONRequest request = JSONRPC.createRequest(
                  method, args);
             
              final SyncCallback<JSONResponse> callback = new SyncCallback<JSONResponse>();
              final AsyncCallbackQueue<JSONResponse> cbs = host
                  .getCallbackQueue(proxyId,
                      JSONResponse.class);
              if (cbs != null) {
                cbs.push(request.getId(), "", callback);
              }
              try {
                host.sendAsync(receiverUrl, request, agent,
                    null);
              } catch (final IOException e1) {
                throw new JSONRPCException(
                    CODE.REMOTE_EXCEPTION, "", e1);
              }
             
              JSONResponse response;
              try {
                response = callback.get();
              } catch (final Exception e) {
                throw new JSONRPCException(
                    CODE.REMOTE_EXCEPTION, "", e);
              }
              final JSONRPCException err = response.getError();
              if (err != null) {
                throw err;
              } else if (response.getResult() != null
                  && !method.getReturnType()
                      .equals(Void.TYPE)) {
                return TypeUtil.inject(response.getResult(),
                    method.getGenericReturnType());
              } else {
                return null;
              }
            }
View Full Code Here

Examples of com.almende.eve.rpc.jsonrpc.JSONResponse

              + agentId + " request=" + json + ", sender="
              + from.getId());
         
          // invoke the agent
          JSONRequest request = new JSONRequest(json);
          JSONResponse response = agentFactory.receive(agentId,
              request, params);
         
          // reply to message
          Message msg = new MessageBuilder().withRecipientJids(from)
              .withFromJid(to).withBody(response.toString())
              .build();
          xmpp.sendMessage(msg);
        } else {
          throw new Exception(
              "Request does not contain a valid JSON-RPC request or response");
        }
      } catch (Exception err) {
        // generate JSON error response
        JSONRPCException jsonError = new JSONRPCException(
            JSONRPCException.CODE.INTERNAL_ERROR, err.getMessage());
        JSONResponse response = new JSONResponse(jsonError);
       
        // send exception as response
        Message msg = new MessageBuilder().withRecipientJids(from)
            .withFromJid(to).withBody(response.toString()).build();
        xmpp.sendMessage(msg);
      }
    }
  }
View Full Code Here

Examples of com.almende.eve.rpc.jsonrpc.JSONResponse

              return method.invoke(agent, args);
            }
            else {
              // remote agent
              JSONRequest request = JSONRPC.createRequest(method, args);
              JSONResponse response = send(senderId, receiverUrl, request);
             
              JSONRPCException err = response.getError();
              if (err != null) {
                throw err;
              }
              else if (response.getResult() != null &&
                  !method.getReturnType().equals(Void.TYPE)) {
                return response.getResult(method.getReturnType());
              }
              else {
                return null;
              }
            }
View Full Code Here

Examples of com.almende.eve.rpc.jsonrpc.JSONResponse

  // TOOD: cleanup this method?
  public JSONResponse invoke(String receiverId,
      JSONRequest request, RequestParams requestParams) throws Exception {
    Agent receiver = getAgent(receiverId);
    if (receiver != null) {
      JSONResponse response = JSONRPC.invoke(receiver, request, requestParams);
      receiver.destroy();
      return response;
    }
    else {
      throw new Exception("Agent with id '" + receiverId + "' not found");
View Full Code Here

Examples of com.almende.eve.rpc.jsonrpc.JSONResponse

    if (agentId != null) {
      // local agent, invoke locally
      // TODO: provide Sender in requestParams
      RequestParams requestParams = new RequestParams();
      requestParams.put(Sender.class, null);
      JSONResponse response = invoke(agentId, request, requestParams);
      return response;
    }
    else {
      TransportService service = null;
      String protocol = null;
      int separator = receiverUrl.indexOf(":");
      if (separator != -1) {
        protocol = receiverUrl.substring(0, separator);
        service = getTransportService(protocol);
      }
      if (service != null) {
        JSONResponse response = service.send(senderId, receiverUrl, request);
        return response;
      }
      else {
        throw new ProtocolException(
          "No transport service configured for protocol '" + protocol + "'.");
View Full Code Here

Examples of com.almende.eve.transform.rpc.formats.JSONResponse

   * java.net.URI, java.lang.String)
   */
  @Access(AccessType.UNAVAILABLE)
  @Override
  public void receive(final Object msg, final URI senderUrl, final String tag) {
    final JSONResponse response = rpc.invoke(msg, senderUrl);
    if (response != null) {
      try {
        transport.send(senderUrl, response.toString(), tag);
      } catch (final IOException e) {
        LOG.log(Level.WARNING, "Couldn't send message", e);
      }
    }
  }
View Full Code Here

Examples of com.jcabi.http.response.JsonResponse

     * Main entry point.
     * @param args Command line arguments
     */
    public static void main(final String[] args) throws Exception {
        final Github github = new RtGithub();
        final JsonResponse resp = github.entry()
            .uri().path("/search/repositories")
            .queryParam("q", "java").back()
            .fetch()
            .as(JsonResponse.class);
        final List<JsonObject> items = resp.json().readObject()
            .getJsonArray("items")
            .getValuesAs(JsonObject.class);
        for (final JsonObject item : items) {
            System.out.println(
                String.format(
View Full Code Here

Examples of com.jcabi.http.response.JsonResponse

     */
    @Test
    public void readNonUnicode() throws Exception {
        final Response resp = new FakeRequest()
            .withBody("{\"help\": \"\u001Fblah\u0001cwhoa\u0000!\"}").fetch();
        final JsonResponse response = new JsonResponse(resp);
        MatcherAssert.assertThat(
            response.json().readObject().getString("help"),
            Matchers.is("\u001Fblah\u0001cwhoa\u0000!")
        );
    }
View Full Code Here

Examples of com.wyn.rest.server.data.JSONResponse

    return notesService.listNotes();
  }
 
  @RequestMapping(value="insert", method=RequestMethod.PUT, consumes=MediaType.APPLICATION_JSON_VALUE)
  public @ResponseBody JSONResponse put(@RequestBody NoteList notes) {
    JSONResponse response = new JSONResponse();
   
    try {
      notesService.saveNotes(notes);
      response.setStatusCode(201);
      response.setMessage("Success");
     
    } catch (Exception e) {
      response.setStatusCode(500);
      response.setMessage("Internal Server ERROR. Message: "+e.getMessage());
      e.printStackTrace();
    }
   
    return response;
  }
View Full Code Here

Examples of it.eng.spagobi.utilities.service.JSONResponse

        }         
      }
     
     
     
      JSONResponse jsonResponse = null;
      if(uresolvedReferenceErrors.size() > 0) {
        SpagoBIEngineServiceException validationException;
        String msg = "Unresolved reference error: ";
        for(int i = 0; i < uresolvedReferenceErrors.size(); i++) {
          String error = (String)uresolvedReferenceErrors.get(i);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.