com.ning.http.client.HttpResponseHeaders Java Examples
The following examples show how to use
com.ning.http.client.HttpResponseHeaders.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NingHttpResponseBuilder.java From junit-servers with MIT License | 6 votes |
@Override public Response build() { Uri uri = Uri.create("http://localhost:8080/"); AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().build(); AsyncHttpProvider provider = new JDKAsyncHttpProvider(config); HttpURLConnection conn = createFakeUrlConnection(); HttpResponseStatus status = new ResponseStatus(uri, config, conn); HttpResponseHeaders headers = new ResponseHeaders(uri, conn, provider); final List<HttpResponseBodyPart> bodyParts; if (body != null) { byte[] bodyBytes = body.getBytes(defaultCharset()); HttpResponseBodyPart part = new ResponseBodyPart(bodyBytes, true); bodyParts = singletonList(part); } else { bodyParts = emptyList(); } return new JDKResponse(status, headers, bodyParts); }
Example #2
Source File: LoggingAsyncHandlerWrapper.java From parsec-libraries with Apache License 2.0 | 5 votes |
/** * onHeadersReceived. * @param headers headers * @return STATE * @throws Exception exception */ @Override public STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception { builder.accumulate(headers); ParsecAsyncProgressTimer.progressTime(progress, ParsecAsyncProgressTimer.TimerOpCode.TIMER_STARTTRANSFER); return asyncHandler.onHeadersReceived(headers); }
Example #3
Source File: AsyncHttpClientPluginIT.java From glowroot with Apache License 2.0 | 5 votes |
@Override public void transactionMarker() throws Exception { AsyncHttpClient asyncHttpClient = new AsyncHttpClient(); final CountDownLatch latch = new CountDownLatch(1); final AtomicInteger statusCode = new AtomicInteger(); asyncHttpClient.prepareGet("http://localhost:" + getPort() + "/hello3/") .execute(new AsyncHandler<Response>() { @Override public STATE onBodyPartReceived(HttpResponseBodyPart part) { return null; } @Override public Response onCompleted() throws Exception { latch.countDown(); return null; } @Override public STATE onHeadersReceived(HttpResponseHeaders headers) { return null; } @Override public STATE onStatusReceived(HttpResponseStatus status) { statusCode.set(status.getStatusCode()); return null; } @Override public void onThrowable(Throwable t) {} }); latch.await(); asyncHttpClient.close(); if (statusCode.get() != 200) { throw new IllegalStateException("Unexpected status code: " + statusCode); } }
Example #4
Source File: UrlResourceCacheTest.java From writelatex-git-bridge with MIT License | 5 votes |
private void respondWithContentLength(long cl, long actual) throws ExecutionException { when(http.get(any(), any())).thenAnswer(invoc -> { Object[] args = invoc.getArguments(); //noinspection unchecked ((FunctionT< HttpResponseHeaders, Boolean, SizeLimitExceededException >) args[1]).apply(withContentLength(cl)); return new byte[CastUtil.assumeInt(actual)]; }); }
Example #5
Source File: TaskResource.java From Singularity with Apache License 2.0 | 5 votes |
@Override public STATE onHeadersReceived(HttpResponseHeaders headers) { LOG.trace( "Proxying download of {} from Mesos: Headers={}", requestBuilder.build().getUrl(), headers.getHeaders() ); return STATE.CONTINUE; }
Example #6
Source File: SSEConnection.java From blueocean-plugin with MIT License | 4 votes |
@Override public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { // we don't care about any header return STATE.CONTINUE; }
Example #7
Source File: NettyAsyncHttpProvider.java From ck with Apache License 2.0 | 4 votes |
public Response prepareResponse(final HttpResponseStatus status, final HttpResponseHeaders headers, final Collection<HttpResponseBodyPart> bodyParts) { return new NettyAsyncResponse(status,headers,bodyParts); }
Example #8
Source File: NettyAsyncHttpProvider.java From ck with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private final boolean updateHeadersAndInterrupt(AsyncHandler handler, HttpResponseHeaders c) throws Exception { return handler.onHeadersReceived(c) != STATE.CONTINUE; }
Example #9
Source File: NingHttpTypedStreamHandler.java From ob1k with Apache License 2.0 | 4 votes |
@Override public STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception { this.headers = headers; return STATE.CONTINUE; }
Example #10
Source File: NingHttpStreamHandler.java From ob1k with Apache License 2.0 | 4 votes |
@Override public STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception { this.headers = headers; return STATE.CONTINUE; }
Example #11
Source File: UrlResourceCacheTest.java From writelatex-git-bridge with MIT License | 4 votes |
private static HttpResponseHeaders withContentLength(long cl) { return NingHttpHeaders .builder() .addHeader("Content-Length", String.valueOf(cl)) .build(); }
Example #12
Source File: AsyncHttpClientTest.java From vw-webservice with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void doTest(Request request) throws InterruptedException, ExecutionException, IOException { final PipedOutputStream pipedOutputStream = new PipedOutputStream(); final PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream); AsyncHandler<Response> asyncHandler = new AsyncHandler<Response>() { private final Response.ResponseBuilder builder = new Response.ResponseBuilder(); @Override public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { content.writeTo(pipedOutputStream); return STATE.CONTINUE; } @Override public STATE onStatusReceived(final HttpResponseStatus status) throws Exception { builder.accumulate(status); return STATE.CONTINUE; } @Override public STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception { builder.accumulate(headers); return STATE.CONTINUE; } @Override public Response onCompleted() throws Exception { LOGGER.info("On complete called!"); pipedOutputStream.flush(); pipedOutputStream.close(); return builder.build(); } @Override public void onThrowable(Throwable arg0) { // TODO Auto-generated method stub LOGGER.error("Error: {}", arg0); onTestFailed(); } }; Future<Void> readingThreadFuture = Executors.newCachedThreadPool().submit(new Callable<Void>() { @Override public Void call() throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(pipedInputStream)); String readPrediction; int numPredictionsRead = 0; while ((readPrediction = reader.readLine()) != null) { //LOGGER.info("Got prediction: {}", readPrediction); numPredictionsRead++; } LOGGER.info("Read a total of {} predictions", numPredictionsRead); Assert.assertEquals(roundsOfDataToSubmit * 272274, numPredictionsRead); return null; } }); Builder config = new AsyncHttpClientConfig.Builder(); config.setRequestTimeoutInMs(-1); //need to set this to -1, to indicate wait forever. setting to 0 actually means a 0 ms timeout! AsyncHttpClient client = new AsyncHttpClient(config.build()); client.executeRequest(request, asyncHandler).get(); readingThreadFuture.get(); //verify no exceptions occurred when reading predictions client.close(); Assert.assertFalse(getTestFailed()); }
Example #13
Source File: TezBodyDeferringAsyncHandler.java From tez with Apache License 2.0 | 4 votes |
public AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { responseBuilder.accumulate(headers); return AsyncHandler.STATE.CONTINUE; }
Example #14
Source File: NingHttpClientFacade.java From writelatex-git-bridge with MIT License | 2 votes |
/** * Performs a GET request * @param url the target URL * @param handler handler for the response headers. Returning false * aborts the request. * @return */ <E extends Exception> byte[] get( String url, FunctionT<HttpResponseHeaders, Boolean, E> handler ) throws ExecutionException;