Package com.baidu.gson

Examples of com.baidu.gson.JsonElement


  public String invoke(String host, String[] serviceAndMethod, String input)
      throws Throwable {
    try {
      int id = counter.getAndIncrement();
      JsonElement request = makeRequest(id, serviceAndMethod, input);
      byte[] reqBytes = serialize(request);
      // log.debug("request bytes size is " + reqBytes.length);
     
      String url = host + serviceAndMethod[0];
     
      log.info("input: " + input);
      log.info("url: " + url);
     
      HttpURLConnection connection = (HttpURLConnection) new URL(url)
          .openConnection();
      if (_connectTimeout > 0) {
        connection.setConnectTimeout(_connectTimeout);
      }
      if (_readTimeout > 0) {
        connection.setReadTimeout(_readTimeout);
      }
      sendRequest(reqBytes, connection);
      byte[] resBytes = null;
      resBytes = readResponse(connection);
      JsonElement resJson = deserialize(resBytes);
//      return parseResult(id, resJson, method);
      return resJson.toString();
    } catch (IOException e) {
      throw new InternalErrorException(e);
    }
  }
View Full Code Here


      throws Exception {
    JsonObject res = (JsonObject) ele;
    if (!res.get("jsonrpc").getAsString().equals("2.0")) {
      throw new InternalErrorException();
    }
    JsonElement result = res.get("result");
    if (result != null) {
      if (res.get("id").getAsInt() != id) {
        throw new InternalErrorException("no id in response");
      } else {
        return gson.fromJson(result, method.getGenericReturnType());
      }
    } else {
      JsonElement e = res.get("error");
      if (e != null) {
        JsonRpcException jre = exceptionHandler.deserialize(e);
        if (jre instanceof ServerErrorException) {
          String msg = jre.getMessage();
          Class<?>[] exp_types = method.getExceptionTypes();
View Full Code Here

TOP

Related Classes of com.baidu.gson.JsonElement

Copyright © 2018 www.massapicom. 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.