本文整理汇总了Java中org.eclipse.jetty.client.api.Result类的典型用法代码示例。如果您正苦于以下问题:Java Result类的具体用法?Java Result怎么用?Java Result使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Result类属于org.eclipse.jetty.client.api包,在下文中一共展示了Result类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onResponseComplete
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
protected void onResponseComplete(Result result, byte[] content) {
LOG.trace("onResponseComplete");
done.countDown();
this.response = result.getResponse();
this.responseContent = content;
if (callback == null) {
// this is only for the async callback
return;
}
try {
jettyBinding.populateResponse(exchange, this);
} catch (Exception e) {
exchange.setException(e);
} finally {
callback.done(false);
}
}
示例2: onResponseComplete
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
protected void onResponseComplete(Result result, byte[] content, String contentType) {
LOG.trace("onResponseComplete");
done.countDown();
this.response = result.getResponse();
this.responseContent = content;
if (callback == null) {
// this is only for the async callback
return;
}
try {
jettyBinding.populateResponse(exchange, this);
} catch (Exception e) {
exchange.setException(e);
} finally {
callback.done(false);
}
}
示例3: downloadStringAsync
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
public void downloadStringAsync(String url, Consumer<DownloadStringAsyncCompletedArgs> consumer) {
newRequest(url)
.timeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)
.send(new BufferingResponseListener() {
@Override
public void onComplete(Result result) {
if (!result.isFailed() && result.getResponse().getStatus() == 200) {
try {
consumer.accept(new DownloadStringAsyncCompletedArgs(getContentAsString(), null));
} catch (Exception e) {
System.err.println("\n" + getContentAsString());
e.printStackTrace();
}
} else {
consumer.accept(new DownloadStringAsyncCompletedArgs(null, "ERROR"));
}
}
});
}
示例4: fireResponse
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
private void fireResponse(CapturingRequest request, int errorCode, String responseText, int resultSize, ObservableObserver observer, boolean successfulResponse) throws InterruptedException {
Response.CompleteListener listener = request.awaitSend(1000, TimeUnit.MILLISECONDS);
assertNotNull(listener);
InputStreamResponseListener responseListener = (InputStreamResponseListener) listener;
Result result = mock(Result.class);
Response response = mock(Response.class);
when(result.getResponse()).thenReturn(response);
when(result.isSucceeded()).thenReturn(successfulResponse);
when(result.isFailed()).thenReturn(!successfulResponse);
HttpFields headers = mock(HttpFields.class);
when(response.getHeaders()).thenReturn(headers);
when(headers.get(HttpHeader.CONTENT_LENGTH)).thenReturn(String.valueOf(resultSize));
when(response.getStatus()).thenReturn(errorCode);
when(response.getVersion()).thenReturn(HttpVersion.HTTP_1_1);
// fire that event
responseListener.onHeaders(response);
responseListener.onContent(response, ByteBuffer.allocate(0));
responseListener.onComplete(result);
assertTrue(observer.getLatch().await(1000, TimeUnit.MILLISECONDS));
}
示例5: onComplete
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
@Override
public void onComplete(Result result) {
emit(new ReactiveResponse.Event(ReactiveResponse.Event.Type.COMPLETE, request.getReactiveResponse()));
if (result.isSucceeded()) {
succeed();
} else {
fail(result.getFailure());
}
}
示例6: onComplete
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
@Override
public void onComplete(Result result) {
if (result.isSucceeded()) {
content.complete();
} else {
content.fail(result.getFailure());
}
}
示例7: testOnComplete
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
@Test
public void testOnComplete() {
CompleteListener sut = new CompleteListener();
Result result = mock(Result.class);
Response response = mock(Response.class);
when(response.getVersion()).thenReturn(HttpVersion.HTTP_2);
when(result.getResponse()).thenReturn(response);
sut.onComplete(result);
verify(result, times(1)).getResponse();
verify(response, times(1)).getVersion();
}
示例8: onComplete
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
@Override
public void onComplete(Result result) {
if (result.isSucceeded())
onResponseSuccess(request, response, result.getResponse());
else
onResponseFailure(request, response, result.getResponse(), result.getFailure());
if (LOG.isDebugEnabled()) LOG.debug("{} proxying complete", getRequestId(request));
}
示例9: requestProxyService
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
public void requestProxyService(HttpServletRequest request, DeferredResult<ResponseEntity> deferredResult) {
this.deferredResult = deferredResult;
long start = System.currentTimeMillis();
this.responseInfo = (ResponseInfo) request.getAttribute(Const.RESPONSE_INFO_DATA);
Request proxyRequest = nettyClientFactory.getNettyClient().newRequest(responseInfo.getRequestURI());
setHeaderAndQueryInfo(proxyRequest, responseInfo).send(new BufferingResponseListener() {
@Override
public void onComplete(Result result) {
if (!result.isFailed()) {
ResponseEntity responseEntity;
if (logger.isDebugEnabled()){
logger.debug("Http Time " + (System.currentTimeMillis() - start));
}
HttpFields responseHeaders = result.getResponse().getHeaders();
if (responseHeaders.contains(HttpHeader.CONTENT_TYPE)) {
String contentTypeValue = responseHeaders.get(HttpHeader.CONTENT_TYPE);
if ( contentTypeValue.split(CONST_CONTENT_TYPE_EXTRACT_DELIMITER)[0]
.equals(responseInfo.getRequestAccept().split(CONST_CONTENT_TYPE_EXTRACT_DELIMITER)[0])){
responseEntity =
new ResponseEntity(Json.parse(getContentAsString(Charset.forName(Const.SERVER_DEFAULT_ENCODING_TYPE))), HttpStatus.OK);
deferredResult.setResult(responseEntity);
}
}
deferredResult.setErrorResult(new ProxyServiceFailException(ERROR_MESSAGE_WRONG_CONTENT_TYPE));
}
}
@Override
public void onFailure(Response response, Throwable failure) {
deferredResult.setErrorResult(new ProxyServiceFailException("", failure));
}
});
}
示例10: sendToZeppelinHubWithoutResponseBody
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
private String sendToZeppelinHubWithoutResponseBody(Request request) throws IOException {
request.send(new Response.CompleteListener() {
@Override
public void onComplete(Result result) {
Request req = result.getRequest();
LOG.info("ZeppelinHub {} {} returned with status {}: {}", req.getMethod(),
req.getURI(), result.getResponse().getStatus(), result.getResponse().getReason());
}
});
return StringUtils.EMPTY;
}
示例11: onComplete
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
@Override
public void onComplete(Result result) {
// Extract results.
Map<String, Object> data = (Map<String, Object>) JSON.parse(utf8Content.toString());
if (data != null) {
Object[] results = (Object[]) data.get("results");
if (results != null) {
for (Object o : results) {
onLocationFound((Map<String, Object>) o);
}
}
}
doComplete();
}
示例12: onComplete
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
@Override
public void onComplete(Result result) {
// Remove this request from list of running requests
runningRequests.remove(mRequestId);
if (result.isFailed() && result.getResponse().getStatus() != HttpStatus.OK_200) {
logger.warn("Jetty request {} failed: {}", mRequestId, result.getFailure().getMessage());
logger.warn("{}", result.getRequestFailure().getMessage());
logger.warn("{}", result.getResponseFailure().getMessage());
}
/**
* What is this? In some cases where latency is very low the myopenhab service
* can receive responseFinished before the headers or content are received and I
* cannot find another workaround to prevent it.
*/
ThreadPoolManager.getScheduledPool(THREADPOOL_OPENHABCLOUD).schedule(new Runnable() {
@Override
public void run() {
JSONObject responseJson = new JSONObject();
try {
responseJson.put("id", mRequestId);
socket.emit("responseFinished", responseJson);
logger.debug("Finished responding to request {}", mRequestId);
} catch (JSONException e) {
logger.error("{}", e.getMessage());
}
}
}, 1, TimeUnit.MILLISECONDS);
}
示例13: onComplete
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
@Override
public void onComplete(Result result) {
if (result.isSucceeded())
complete.succeeded();
else
complete.failed(result.getFailure());
}
示例14: onComplete
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
@Override
public void onComplete(final Result result) {
final Throwable failure = result.getFailure();
if (failure != null) {
_response.setFailure(failure);
} else {
final Response response = result.getResponse();
handleResponse(response);
}
}
示例15: onComplete
import org.eclipse.jetty.client.api.Result; //导入依赖的package包/类
@Override
public void onComplete(Result result){
if (result.isSucceeded())
onResponseSuccess(request, response, result.getResponse());
else
onResponseFailure(request, response, result.getResponse(), result.getFailure());
_log.debug("{} proxying complete", getRequestId(request));
}