当前位置: 首页>>代码示例>>Java>>正文


Java HttpResponseBodyPart类代码示例

本文整理汇总了Java中com.ning.http.client.HttpResponseBodyPart的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseBodyPart类的具体用法?Java HttpResponseBodyPart怎么用?Java HttpResponseBodyPart使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpResponseBodyPart类属于com.ning.http.client包,在下文中一共展示了HttpResponseBodyPart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onBodyPartReceived

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
@Override
public STATE onBodyPartReceived(final HttpResponseBodyPart bodyPart) throws Exception {

  if (responseMaxSize > 0) {
    responseSizesAggregated += bodyPart.length();
    if (responseSizesAggregated > responseMaxSize) {
      onThrowable(new RuntimeException("Response size is bigger than the limit: " + responseMaxSize));
      return STATE.ABORT;
    }
  }

  final com.ning.http.client.Response ningResponse = new NettyResponse(status, headers, singletonList(bodyPart));
  final TypedResponse<T> response = new NingResponse<>(ningResponse, type, marshallingStrategy);

  try {
    // making sure that we can unmarshall the response
    response.getTypedBody();
  } catch (final Exception e) {
    // if the unmarshall failed, no reason to continuing the stream
    onThrowable(e);
    return STATE.ABORT;
  }

  target.onNext(response);
  return STATE.CONTINUE;
}
 
开发者ID:outbrain,项目名称:ob1k,代码行数:27,代码来源:NingHttpTypedStreamHandler.java

示例2: onBodyPartReceived

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
@Override
public STATE onBodyPartReceived(final HttpResponseBodyPart bodyPart) throws Exception {

  if (responseMaxSize > 0) {
    responseSizesAggregated += bodyPart.length();
    if (responseSizesAggregated > responseMaxSize) {
      onThrowable(new RuntimeException("Response size is bigger than the limit: " + responseMaxSize));
      return STATE.ABORT;
    }
  }

  final com.ning.http.client.Response ningResponse = new NettyResponse(status, headers, Collections.singletonList(bodyPart));
  final Response response = new NingResponse<>(ningResponse, null, null);

  target.onNext(response);
  return STATE.CONTINUE;
}
 
开发者ID:outbrain,项目名称:ob1k,代码行数:18,代码来源:NingHttpStreamHandler.java

示例3: onBodyPartReceived

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
public com.ning.http.client.AsyncHandler.STATE onBodyPartReceived(
		HttpResponseBodyPart bodyPart) throws Exception {
	String contType = testCase.getExpectedResContentType();
	if(isMatchesContentType(MediaType.APPLICATION_JSON_TYPE, contType) || isMatchesContentType(MediaType.APPLICATION_XML_TYPE, contType)
			|| isMatchesContentType(MediaType.TEXT_PLAIN_TYPE, contType) || isMatchesContentType(MediaType.TEXT_HTML_TYPE, contType)
			|| isMatchesContentType(MediaType.TEXT_XML_TYPE, contType))
	{
		builder.accumulate(bodyPart);
	}
	else
	{
		bodyPart.writeTo(NullOutputStream.NULL_OUTPUT_STREAM);
	}
	testCaseReport.setResponseContentType(contType);
	return STATE.CONTINUE;
}
 
开发者ID:sumeetchhetri,项目名称:gatf,代码行数:17,代码来源:TestCaseExecutorUtil.java

示例4: onBodyPartReceived

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
@Override
public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
    // write body parts to stream, which we will bind to the Camel Exchange in onComplete
    int wrote = bodyPart.writeTo(os);
    if (log.isTraceEnabled()) {
        log.trace("{} onBodyPartReceived {} bytes", exchange.getExchangeId(), wrote);
    }
    contentLength += wrote;
    return STATE.CONTINUE;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:AhcProducer.java

示例5: transactionMarker

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:35,代码来源:AsyncHttpClientPluginIT.java

示例6: onBodyPartReceived

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
    
    String chunk = new String(bodyPart.getBodyPartBytes()).trim();
    if (chunk.length() != 0) {
        chunks.add(chunk);
    }
    return STATE.CONTINUE;
}
 
开发者ID:lantunes,项目名称:fixd,代码行数:9,代码来源:TestServerFixture.java

示例7: onBodyPartReceived

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
public AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
  // body arrived, flush headers
  if (!responseSet) {
    response = responseBuilder.build();
    responseSet = true;
    headersArrived.countDown();
  }
  bodyPart.writeTo(output);
  return AsyncHandler.STATE.CONTINUE;
}
 
开发者ID:apache,项目名称:tez,代码行数:11,代码来源:TezBodyDeferringAsyncHandler.java

示例8: prepareResponse

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
public Response prepareResponse(HttpResponseStatus status, HttpResponseHeaders headers, List<HttpResponseBodyPart> bodyParts) {
    return new JDKResponse(status, headers, bodyParts);
}
 
开发者ID:yongbeam,项目名称:Android-kakaologin-gradle-sample,代码行数:4,代码来源:SimpleAsyncHttpProvider.java

示例9: onBodyPartReceived

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
@Override
public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Exception {
	// Don't store the content anyway, saving memory. We want to receive it, but nothing else.
	return STATE.CONTINUE;
}
 
开发者ID:paulwellnerbou,项目名称:chronicreplay,代码行数:6,代码来源:LoggingAsyncCompletionHandler.java

示例10: executeAndTransformRequest

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
private ComposableFuture<com.ning.http.client.Response> executeAndTransformRequest() {

    try {
      prepareRequestBody();
    } catch (final IOException e) {
      return fromError(e);
    }

    final Request ningRequest = ningRequestBuilder.build();

    if (log.isTraceEnabled()) {
      final String body = ningRequest.getByteData() == null
        ? ningRequest.getStringData() :
        new String(ningRequest.getByteData(), Charset.forName(charset));

      log.trace("Sending HTTP call to {}: headers=[{}], body=[{}]", ningRequest.getUrl(), ningRequest.getHeaders(), body);
    }

    final Provider<com.ning.http.client.Response> provider = new Provider<com.ning.http.client.Response>() {
      private boolean aborted = false;
      private long size;

      @Override
      public ListenableFuture<com.ning.http.client.Response> provide() {
        return asyncHttpClient.executeRequest(ningRequest, new AsyncCompletionHandler<com.ning.http.client.Response>() {
          @Override
          public com.ning.http.client.Response onCompleted(final com.ning.http.client.Response response) throws Exception {
            if (aborted) {
              throw new RuntimeException("Response size is bigger than the limit: " + responseMaxSize);
            }
            return response;
          }

          @Override
          public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Exception {
            if (responseMaxSize > 0) {
              size += content.length();
              if (size > responseMaxSize) {
                aborted = true;
                return STATE.ABORT;
              }
            }
            return super.onBodyPartReceived(content);
          }
        });
      }
    };

    return fromListenableFuture(provider);
  }
 
开发者ID:outbrain,项目名称:ob1k,代码行数:51,代码来源:NingRequestBuilder.java

示例11: HTTPAsyncPost

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
public HTTPAsyncPost(AsyncHttpClient client, HTTPLogObject http_log) {

		RequestBuilder builder = new RequestBuilder("POST");
		url_request = http_log.getURLRequest();

		HTTPUtils util = new HTTPUtils();
		builder = util.buildDefaultHeaders(builder, http_log);
		
		// Add additional POST headers, if specified
		builder = util.buildCustomPOSTHeaders(builder, http_log);
		
		builder.addHeader("User-Agent", http_log.getUseragent());
		
		String one_time_payload = POSTPayloadCache.instance.fetchPayload(http_log.getRequest());
		logger.debug("Here is the randomized payload: " + one_time_payload);
		builder.setBody(one_time_payload);

		Request request = builder.setUrl(http_log.getURLRequest()).build();

		AsyncHandler<Response> asyncHandler = new AsyncHandler<Response>() {
			private final Response.ResponseBuilder builder = new Response.ResponseBuilder();

			public STATE onBodyPartReceived(final HttpResponseBodyPart content)
					throws Exception {
				builder.accumulate(content);
				return STATE.CONTINUE;
			}

			public STATE onStatusReceived(final HttpResponseStatus status)
					throws Exception {
				builder.accumulate(status);
				return STATE.CONTINUE;
			}

			public STATE onHeadersReceived(final HttpResponseHeaders headers)
					throws Exception {
				builder.accumulate(headers);
				return STATE.CONTINUE;	
			}

			public Response onCompleted() throws Exception {
				logger.debug("POST - " + url_request + " - "
						+ builder.build().getStatusCode());
				return builder.build();
			}

			@Override
			public void onThrowable(Throwable t) {
				logger.error(t.getMessage());
			}
		};

		try {
			client.executeRequest(request, asyncHandler);
		} catch (IOException e) {
			logger.error(e.getMessage());
		}
	}
 
开发者ID:broamski,项目名称:cantilever,代码行数:59,代码来源:HTTPAsyncPost.java

示例12: HTTPAsyncGet

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
public HTTPAsyncGet(AsyncHttpClient client, HTTPLogObject http_log) {

		RequestBuilder builder = new RequestBuilder("GET");
		url_request = http_log.getURLRequest();
		
		HTTPUtils util = new HTTPUtils();
		builder = util.buildDefaultHeaders(builder, http_log);

		// Add additional GET headers, if specified
		builder = util.buildCustomGETHeaders(builder, http_log);
		
		builder.addHeader("User-Agent", http_log.getUseragent());
		
		Request request = builder.setUrl(url_request).build();

		AsyncHandler<Response> asyncHandler = new AsyncHandler<Response>() {
			private final Response.ResponseBuilder builder = new Response.ResponseBuilder();

			public STATE onBodyPartReceived(final HttpResponseBodyPart content)
					throws Exception {
				builder.accumulate(content);
				return STATE.CONTINUE;
			}

			public STATE onStatusReceived(final HttpResponseStatus status)
					throws Exception {
				builder.accumulate(status);
				return STATE.CONTINUE;
			}

			public STATE onHeadersReceived(final HttpResponseHeaders headers)
					throws Exception {
				builder.accumulate(headers);
				return STATE.CONTINUE;
			}

			public Response onCompleted() throws Exception {
				logger.debug("GET - " + url_request + " - "
						+ builder.build().getStatusCode());
				return builder.build();
			}

			@Override
			public void onThrowable(Throwable t) {
				logger.error(t.getMessage());
			}
		};

		try {
			client.executeRequest(request, asyncHandler);
		} catch (IOException e) {
			logger.error(e.getMessage());
		}
	}
 
开发者ID:broamski,项目名称:cantilever,代码行数:55,代码来源:HTTPAsyncGet.java

示例13: sse

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
public String sse(final String path, final int count) throws Exception {
  CountDownLatch latch = new CountDownLatch(count);
  String result = client.prepareGet("http://localhost:" + port + path)
      .addHeader("Content-Type", MediaType.sse.name())
      .addHeader("last-event-id", count + "")
      .execute(new AsyncHandler<String>() {

        StringBuilder sb = new StringBuilder();

        @Override
        public void onThrowable(final Throwable t) {
          t.printStackTrace();
        }

        @Override
        public AsyncHandler.STATE onBodyPartReceived(final HttpResponseBodyPart bodyPart)
            throws Exception {
          sb.append(new String(bodyPart.getBodyPartBytes(), StandardCharsets.UTF_8));
          latch.countDown();
          return AsyncHandler.STATE.CONTINUE;
        }

        @Override
        public AsyncHandler.STATE onStatusReceived(final HttpResponseStatus responseStatus)
            throws Exception {
          assertEquals(200, responseStatus.getStatusCode());
          return AsyncHandler.STATE.CONTINUE;
        }

        @Override
        public AsyncHandler.STATE onHeadersReceived(final HttpResponseHeaders headers)
            throws Exception {
          FluentCaseInsensitiveStringsMap h = headers.getHeaders();
          assertEquals("close", h.get("Connection").get(0).toLowerCase());
          assertEquals("text/event-stream; charset=utf-8",
              h.get("Content-Type").get(0).toLowerCase());
          return AsyncHandler.STATE.CONTINUE;
        }

        @Override
        public String onCompleted() throws Exception {
          return sb.toString();
        }
      }).get();

  latch.await();
  return result;
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:49,代码来源:SseFeature.java

示例14: onBodyPartReceived

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Exception {
    //System.out.println("body part received!");
    System.out.println("thread name: " + Thread.currentThread().getName());
    return super.onBodyPartReceived(content);
}
 
开发者ID:AlgeFramework,项目名称:alge-core,代码行数:6,代码来源:MyRealAsyncCompletionHandler.java

示例15: onBodyPartReceived

import com.ning.http.client.HttpResponseBodyPart; //导入依赖的package包/类
@Override
public STATE onBodyPartReceived(HttpResponseBodyPart httpResponseBodyPart) throws Exception {
    builder.accumulate(httpResponseBodyPart);
    return STATE.CONTINUE;

}
 
开发者ID:AlgeFramework,项目名称:alge-core,代码行数:7,代码来源:GenericAsyncHandler.java


注:本文中的com.ning.http.client.HttpResponseBodyPart类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。