本文整理汇总了Java中com.ning.http.client.Response.getResponseBody方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getResponseBody方法的具体用法?Java Response.getResponseBody怎么用?Java Response.getResponseBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ning.http.client.Response
的用法示例。
在下文中一共展示了Response.getResponseBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public BrokerResponse get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
try {
LOGGER.debug("Sending query {} to {}", _query, _url);
Response httpResponse = _response.get(timeout, unit);
LOGGER.debug("Completed query, HTTP status is {}", httpResponse.getStatusCode());
if (httpResponse.getStatusCode() != 200) {
throw new PinotClientException("Pinot returned HTTP status " + httpResponse.getStatusCode() +
", expected 200");
}
String responseBody = httpResponse.getResponseBody();
return BrokerResponse.fromJson(new JSONObject(responseBody));
} catch (Exception e) {
throw new ExecutionException(e);
}
}
示例2: getSentiment
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public SentimentProbability getSentiment(final String quote, final String context) {
LOGGER.debug("Fetching sentiment for quote: " + quote);
SentimentProbability sentimentProbability = null;
try {
final HashMap<String, Collection<String>> parameters = Maps.newHashMap();
parameters.put("language", Lists.newArrayList("dutch"));
parameters.put("text", Lists.newArrayList(quote + " " + context));
final Response response = this.asyncHttpClient.preparePost(SENTIMENT_ENDPOINT).setParameters(parameters).execute().get(10, TimeUnit.SECONDS);
final String responseBody = response.getResponseBody();
ObjectMapper objectMapper = new ObjectMapper();
sentimentProbability = objectMapper.readValue(responseBody, SentimentProbability.class);
} catch (Exception e) {
LOGGER.error("Fetch sentiment failed!", e);
}
return sentimentProbability;
}
示例3: getContents
import com.ning.http.client.Response; //导入方法依赖的package包/类
public Optional<String> getContents(String user, String repo, String path, Optional<String> ref) {
try {
final BoundRequestBuilder builder = asyncHttpClient.prepareGet(String.format("%s/repos/%s/%s/contents/%s", baseUrl, user, repo, path))
.addHeader("Accept", "application/vnd.github.v3.raw");
if (ref.isPresent()) {
builder.addQueryParameter("ref", ref.get());
}
if (accessToken.isPresent()) {
builder.addQueryParameter("access_token", accessToken.get());
}
final Response response = builder.execute().get();
if (response.getStatusCode() == 200) {
return Optional.of(response.getResponseBody());
} else if (response.getStatusCode() == 404) {
return Optional.absent();
} else {
throw new RuntimeException(response.getResponseBody()); // TODO: better exception
}
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
示例4: getResponseBody
import com.ning.http.client.Response; //导入方法依赖的package包/类
public static String getResponseBody(Response response) {
try {
return response.getResponseBody(Utils.getCharset());
} catch (IOException e) {
throw new BadContentException();
}
}
示例5: onCompleted
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public Void onCompleted(final Response response) throws Exception {
final URI requestUri = response.getUri();
try {
if (!response.hasResponseStatus()) {
sendError(response, "the response didn't have a response status");
return null;
}
final int httpStatusCode = response.getStatusCode();
if (httpStatusCode != HttpStatus.SC_OK) {
return handleFailureHttpStatus(response, requestUri, httpStatusCode);
} else {
if(returnType.equals(Void.class)){
httpResponseHandler.sendMessage(Message.obtain(httpResponseHandler, HttpRequestTask.SUCCESS, 0, 0));
} else {
if (checkResponseBody(response)) return null;
final String responseValue = response.getResponseBody(request.getBodyEncoding());
Logger.getInstance().d("ResponseBody: " + responseValue);
Object result;
if(returnType.equals(String.class)) {
result = responseValue;
} else if(returnType.equals(Character.class)) {
result = responseValue.charAt(0);
} else {
result = new ObjectMapper().readValue(responseValue, returnType);
}
httpResponseHandler.sendMessage(Message.obtain(httpResponseHandler, HttpRequestTask.SUCCESS, 0, 0, result));
}
return null;
}
} catch (Exception e) {
sendError(response, e.toString());
return null;
}
}
示例6: onCompleted
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public Response onCompleted(Response response) throws Exception {
if (response.getStatusCode() < 200 || response.getStatusCode() > 206)
throw new RuntimeException("Unexpected Buttercoin API response: " + response.getStatusCode() + " " + response.getStatusText() + " " + response.getResponseBody("UTF-8"));
return response;
}
示例7: onResult
import com.ning.http.client.Response; //导入方法依赖的package包/类
public void onResult(int id, Response response) {
try {
// TODO: Handle status codes other than 200...
int httpStatus = response.getStatusCode();
log.logEndProcessingStepNonBlocking(id, httpStatus);
// If many requests completes at the same time the following code must be executed in sequence for one thread at a time
// Since we don't have any Actor-like mechanism to rely on (for the time being...) we simply ensure that the code block is executed by one thread at a time by an old school synchronized block
// Since the processing in the block is very limited it will not cause a bottleneck.
synchronized (result) {
// Count down, aggregate answer and return if all answers (also cancel timer)...
int noOfRes = noOfResults.incrementAndGet();
// Perform the aggregation...
log.logMessage("Safely adding response #" + id);
result += response.getResponseBody() + '\n';
if (noOfRes >= noOfCalls) {
onAllCompleted();
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:callistaenterprise,项目名称:blog-non-blocking-rest-service-with-spring-mvc,代码行数:30,代码来源:AggregatorEventHandler.java
示例8: getResponseBody
import com.ning.http.client.Response; //导入方法依赖的package包/类
private String getResponseBody(Response response) {
try {
return response.getResponseBody();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例9: extractResponseBody
import com.ning.http.client.Response; //导入方法依赖的package包/类
private String extractResponseBody(Response response) {
try {
return response.getResponseBody();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例10: setResponse
import com.ning.http.client.Response; //导入方法依赖的package包/类
public void setResponse(String endpoint, Response response) throws IOException {
Integer statusCode = response.getStatusCode();
String httpResponse = response.getResponseBody();
List<Cookie> cookies = response.getCookies();
this.response = new HttpResponse(statusCode, httpResponse, cookies);
}
示例11: handleFeedResponse
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
protected void handleFeedResponse(Response response) throws IOException {
String sResponse = response.getResponseBody();
TitanListResponse lResponse =
GSON.fromJson(sResponse, TitanListResponse.class);
if (lResponse.isSuccess()) {
List<JsonObject> statusUpdates = lResponse.getValue();
((RequestFeed) _request).setResult((statusUpdates == null)
? 0
: statusUpdates.size());
} else {
_request.setError(new IllegalStateException(sResponse));
}
}
示例12: handleFollowResponse
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
protected void handleFollowResponse(Response response) throws IOException {
String sResponse = response.getResponseBody();
TitanBooleanResponse bResponse =
GSON.fromJson(sResponse, TitanBooleanResponse.class);
if (bResponse.isSuccess()) {
((RequestFollow) _request).setResult(bResponse.getValue());
} else {
_request.setError(new IllegalStateException(sResponse));
}
}
示例13: handlePostResponse
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
protected void handlePostResponse(Response response) throws IOException {
String sResponse = response.getResponseBody();
TitanLongResponse lResponse =
GSON.fromJson(sResponse, TitanLongResponse.class);
if (lResponse.isSuccess()) {
((RequestPost) _request).setResult(lResponse.getValue() != 0L);
} else {
_request.setError(new IllegalStateException(sResponse));
}
}
示例14: handleUnfollowResponse
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
protected void handleUnfollowResponse(Response response) throws IOException {
String sResponse = response.getResponseBody();
TitanBooleanResponse bResponse =
GSON.fromJson(sResponse, TitanBooleanResponse.class);
if (bResponse.isSuccess()) {
((RequestUnfollow) _request).setResult(bResponse.getValue());
} else {
_request.setError(new IllegalStateException(sResponse));
}
}
示例15: handleFeedResponse
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
protected void handleFeedResponse(Response response) throws IOException {
String sResponse = response.getResponseBody();
try {
JSONObject jsonResponse = (JSONObject) jsonParser.parse(sResponse);
JSONArray activities = (JSONArray) jsonResponse.get("feeds");
((RequestFeed) _request).setResult(activities.size());
} catch (ParseException e) {
System.err.println(sResponse);
_request.setError(new IllegalStateException(e));
}
}