예제 #1
0
  public Post fetch(Session session, NextRequest next) {
    LOGGER.debug(
        ((next == null) ? "Initial request" : "next request: " + next)
            + "/n Session: "
            + session.toString());
    WebTarget target = createInitialFetchTarget();

    if (next != null) {
      target = fillNextParameters(next, target);
    }

    Invocation.Builder request = target.request();

    request = appendCookies(session, request);

    Response response =
        request.post(
            Entity.entity(
                new NextToken.NextTokenBuilder().createNextToken(),
                MediaType.APPLICATION_JSON_TYPE));

    response.bufferEntity();
    try {
      String responseJson = response.readEntity(String.class);
      LOGGER.debug("Full response: " + responseJson);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    Post post = response.readEntity(Post.class);
    response.close();

    return post;
  }
예제 #2
0
  protected Object handleResponse(Message outMessage, Class<?> serviceCls) throws Throwable {
    try {
      Response r = setResponseBuilder(outMessage, outMessage.getExchange()).build();
      ((ResponseImpl) r).setOutMessage(outMessage);
      getState().setResponse(r);

      Method method = outMessage.getExchange().get(Method.class);
      checkResponse(method, r, outMessage);
      if (method.getReturnType() == Void.class || method.getReturnType() == Void.TYPE) {
        return null;
      }
      if (method.getReturnType() == Response.class
          && (r.getEntity() == null
              || InputStream.class.isAssignableFrom(r.getEntity().getClass())
                  && ((InputStream) r.getEntity()).available() == 0)) {
        return r;
      }
      if (PropertyUtils.isTrue(
          super.getConfiguration().getResponseContext().get(BUFFER_PROXY_RESPONSE))) {
        r.bufferEntity();
      }

      Class<?> returnType = method.getReturnType();
      Type genericType =
          InjectionUtils.processGenericTypeIfNeeded(
              serviceCls, returnType, method.getGenericReturnType());
      returnType = InjectionUtils.updateParamClassToTypeIfNeeded(returnType, genericType);
      return readBody(r, outMessage, returnType, genericType, method.getDeclaredAnnotations());
    } finally {
      ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
    }
  }
예제 #3
0
 public JSONObject getAdapters(final String namespace) {
   final Response resp = infoService.getAdapters(namespace);
   resp.bufferEntity();
   return JSONObject.fromObject(resp.readEntity(String.class));
 }