com.ning.http.client.Response.getResponseBodyAsStream()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中com.ning.http.client.Response.getResponseBodyAsStream方法的一些代码示例,展示了Response.getResponseBodyAsStream的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getResponseBodyAsStream方法的具体详情如下:
包路径:com.ning.http.client.Response
类名称:Response
方法名:getResponseBodyAsStream

Response.getResponseBodyAsStream介绍

[英]Returns an input stream for the response body. Note that you should not try to get this more than once, and that you should not close the stream.
[中]返回响应主体的输入流。请注意,您不应多次尝试获取此消息,并且不应关闭流。

代码示例

代码示例来源:origin: killbill/killbill

private boolean isAuthenticated(final Response oktaRawResponse) {
  try {
    final Map oktaResponse = mapper.readValue(oktaRawResponse.getResponseBodyAsStream(), Map.class);
    if ("SUCCESS".equals(oktaResponse.get("status"))) {
      return true;
    } else {
      log.warn("Okta authentication failed: " + oktaResponse);
      return false;
    }
  } catch (final IOException e) {
    log.warn("Unable to read response from Okta");
    throw new AuthenticationException(e);
  }
}

代码示例来源:origin: killbill/killbill

private Set<String> getGroups(final Response oktaRawResponse) {
  try {
    final List<Map> oktaResponse = mapper.readValue(oktaRawResponse.getResponseBodyAsStream(), new TypeReference<List<Map>>() {});
    final Set<String> groups = new HashSet<String>();
    for (final Map group : oktaResponse) {
      final Object groupProfile = group.get("profile");
      if (groupProfile != null && groupProfile instanceof Map) {
        groups.add((String) ((Map) groupProfile).get("name"));
      }
    }
    return groups;
  } catch (final IOException e) {
    log.warn("Unable to read response from Okta");
    throw new AuthorizationException(e);
  }
}

代码示例来源:origin: killbill/killbill

private String findOktaUserId(final String login) {
  final String path;
  try {
    path = "/api/v1/users/" + URLEncoder.encode(login, "UTF-8");
  } catch (final UnsupportedEncodingException e) {
    // Should never happen
    throw new IllegalStateException(e);
  }
  final Response oktaRawResponse = doGetRequest(path);
  try {
    final Map oktaResponse = mapper.readValue(oktaRawResponse.getResponseBodyAsStream(), Map.class);
    return (String) oktaResponse.get("id");
  } catch (final IOException e) {
    log.warn("Unable to read response from Okta");
    throw new AuthorizationException(e);
  }
}

代码示例来源:origin: com.ning/async-http-client

public InputStream getResponseBodyAsStream() throws IOException {
  return response.getResponseBodyAsStream();
}

代码示例来源:origin: HubSpot/Singularity

throw new WebApplicationException(response.getResponseBody(Charsets.UTF_8.toString()), response.getStatusCode());
} else {
 return objectMapper.readValue(response.getResponseBodyAsStream(), clazz);

代码示例来源:origin: com.ning/async-http-client

@Override
public final T onCompleted() throws Exception {
  if (status != null) {
    Response response = status.prepareResponse(headers, bodies);
    Document document = null;
    if (status.getStatusCode() == 207) {
      document = readXMLResponse(response.getResponseBodyAsStream());
    }
    return onCompleted(new WebDavResponse(status.prepareResponse(headers, bodies), document));
  } else {
    throw new IllegalStateException("Status is null");
  }
}

代码示例来源:origin: HubSpot/Singularity

public Collection<MesosFileObject> browse(String slaveHostname, String fullPath) throws SlaveNotFoundException {
 try {
  PerRequestConfig timeoutConfig = new PerRequestConfig();
  timeoutConfig.setRequestTimeoutInMs((int) configuration.getSandboxHttpTimeoutMillis());
  Response response = asyncHttpClient
    .prepareGet(String.format("http://%s:5051/files/browse", slaveHostname))
    .setPerRequestConfig(timeoutConfig)
    .addQueryParameter("path", fullPath)
    .execute()
    .get();
  if (response.getStatusCode() == 404) {
   return Collections.emptyList();
  }
  if (response.getStatusCode() != 200) {
   throw new RuntimeException(String.format("Got HTTP %s from Mesos slave", response.getStatusCode()));
  }
  return objectMapper.readValue(response.getResponseBodyAsStream(), MESOS_FILE_OBJECTS);
 } catch (ConnectException ce) {
  throw new SlaveNotFoundException(ce);
 } catch (Exception e) {
  if (e.getCause().getClass() == ConnectException.class) {
   throw new SlaveNotFoundException(e);
  } else {
   throw Throwables.propagate(e);
  }
 }
}

代码示例来源:origin: play/play-java

/**
 * Get the response body as a stream
 * @return The stream to read the response body from
 */
public InputStream getBodyAsStream() {
  try {
    return ahcResponse.getResponseBodyAsStream();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: io.sphere.sdk.jvm/sdk-http-ahc-1_8

private byte[] unzip(final Response response) throws IOException {
  final InputStream autoCloseInputStream = new AutoCloseInputStream(new GZIPInputStream(response.getResponseBodyAsStream()));
  return IOUtils.toByteArray(autoCloseInputStream);
}

代码示例来源:origin: play/play-java

/**
 * Get the response body as a {@link Document DOM document}
 * @return a DOM document
 */
public Document asXml() {
  try {
    return play.libs.XML.fromInputStream(ahcResponse.getResponseBodyAsStream(), "utf-8");
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

private byte[] unzip(final Response response) throws IOException {
  final InputStream autoCloseInputStream = new AutoCloseInputStream(new GZIPInputStream(response.getResponseBodyAsStream()));
  return IOUtils.toByteArray(autoCloseInputStream);
}

代码示例来源:origin: org.mule.services/mule-service-http

private void handleIfNecessary() {
  if (!handled.getAndSet(true)) {
   response = responseBuilder.build();
   try {
    future.complete(httpResponseCreator.create(response, input.orElse(response.getResponseBodyAsStream())));
   } catch (IOException e) {
    future.completeExceptionally(e);
   }
  }
 }
}

代码示例来源:origin: org.mule.services/mule-service-http

@Override
public Response onCompleted(Response response) throws Exception {
 try {
  future.complete(httpResponseCreator.create(response, response.getResponseBodyAsStream()));
 } catch (Throwable t) {
  onThrowable(t);
 }
 return null;
}

代码示例来源:origin: net.adamcin.granite/granite-client-packman

@Override public SimpleResponse onCompleted(Response response) throws Exception {
    return AbstractPackageManagerClient.parseSimpleResponse(
        response.getStatusCode(),
        response.getStatusText(),
        response.getResponseBodyAsStream(),
        getResponseEncoding(response),
        true
    );
  }
};

代码示例来源:origin: net.adamcin.granite/granite-client-packman

@Override public DetailedResponse onCompleted(Response response) throws Exception {
    return AbstractPackageManagerClient.parseDetailedResponse(
        response.getStatusCode(),
        response.getStatusText(),
        response.getResponseBodyAsStream(),
        getResponseEncoding(response),
        listener
    );
  }
});

代码示例来源:origin: net.adamcin.granite/granite-client-packman

@Override public ListResponse onCompleted(Response response) throws Exception {
    return AbstractPackageManagerClient.parseListResponse(
        response.getStatusCode(),
        response.getStatusText(),
        response.getResponseBodyAsStream(),
        getResponseEncoding(response)
    );
  }
};

代码示例来源:origin: net.adamcin.granite/granite-client-packman

@Override public SimpleResponse onCompleted(Response response) throws Exception {
    return AbstractPackageManagerClient.parseSimpleResponse(
        response.getStatusCode(),
        response.getStatusText(),
        response.getResponseBodyAsStream(),
        getResponseEncoding(response)
    );
  }
};

代码示例来源:origin: stackoverflow.com

//imports
import java.util.concurrent.Future;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder;
import com.ning.http.client.Response;

//request
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
BoundRequestBuilder prepareGet = asyncHttpClient.prepareGet(url);
Future<Response> fResponse = prepareGet.execute();
Response r = fResponse.get();
InputStream responseBodyAsStream = r.getResponseBodyAsStream();

return ok(responseBodyAsStream).as('image/png');

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "standalone", "default_provider" })
  public void testPutEmptyBody() throws Throwable {
    try (AsyncHttpClient client = getAsyncHttpClient(null)) {
      Response response = client.preparePut(getTargetUrl()).setBody("String").execute().get();

      assertNotNull(response);
      assertEquals(response.getStatusCode(), 204);
      assertEquals(response.getResponseBody(), "");
      assertTrue(response.getResponseBodyAsStream() instanceof InputStream);
      assertEquals(response.getResponseBodyAsStream().read(), -1);
    }
  }
}

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "online", "default_provider", "async" })
public void asyncUrlWithoutPathTest() throws Throwable {
  try (AsyncHttpClient client = getAsyncHttpClient(new Builder().build())) {
    Response r = client.prepareGet("http://www.google.com").execute().get();
    r.getResponseBody();
    r.getResponseBodyAsStream();
  }
}

相关文章