Package com.baidu.rpc.exception

Examples of com.baidu.rpc.exception.InternalErrorException


      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


          in = httpconnection.getInputStream();
        }
      }
      int len = httpconnection.getContentLength();
      if (len <= 0) {
        throw new InternalErrorException("no response to get.");
      }
      resBytes = new byte[len];
      int offset = 0;
      while (offset < resBytes.length) {
        int bytesRead = in.read(resBytes, offset, resBytes.length
            - offset);
        if (bytesRead == -1)
          break; // end of stream
        offset += bytesRead;
      }
      if (offset <= 0) {
        throw new InternalErrorException("there is no service to "
            + connection.getURL());
      }
      // log.debug("response bytes size is " + offset);
    } catch (IOException e) {
      throw new InternalErrorException(e);
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException e) {
          throw new InternalErrorException(e);
        }
      }
    }
    return resBytes;
  }
View Full Code Here

          + reqBytes.length);
      httpconnection.connect();
      out = httpconnection.getOutputStream();
      out.write(reqBytes);
    } catch (Exception e) {
      throw new InternalErrorException(e);
    } finally {
      if (out != null) {
        try {
          out.close();
        } catch (IOException e) {
          throw new InternalErrorException(e);
        }
      }
    }
  }
View Full Code Here

  @Deprecated
  protected Object parseResult(int id, JsonElement ele, Method method)
      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();
          for (Class<?> exp_type : exp_types) {
            if (msg.equals(exp_type.getSimpleName())) {
              Exception custom_exp = (Exception) exp_type
                  .newInstance();
              custom_exp.initCause(jre.getCause());
              throw custom_exp;
            }
          }
        }
        throw jre;
      } else {
        throw new InternalErrorException("no error or result returned");
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.baidu.rpc.exception.InternalErrorException

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.