本文整理汇总了Java中org.apache.http.HttpEntityEnclosingRequest.getEntity方法的典型用法代码示例。如果您正苦于以下问题:Java HttpEntityEnclosingRequest.getEntity方法的具体用法?Java HttpEntityEnclosingRequest.getEntity怎么用?Java HttpEntityEnclosingRequest.getEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.HttpEntityEnclosingRequest
的用法示例。
在下文中一共展示了HttpEntityEnclosingRequest.getEntity方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Override
public void apply( Request request )
throws HttpException,
IOException
{
Path path = request.getAttribute( "path" );
HttpRequest req = request.getHttpRequest();
if( path != null && req instanceof HttpEntityEnclosingRequest ) {
HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) req;
HttpEntity entity = entityRequest.getEntity();
Files.copy( entity.getContent(), path, StandardCopyOption.REPLACE_EXISTING );
request.getHttpResponse().setStatusCode( HttpStatus.SC_OK );
request.getHttpResponse().setEntity( new StringEntity( "OK" ) );
}
else {
request.getHttpResponse().setStatusCode( HttpStatus.SC_BAD_REQUEST );
request.getHttpResponse().setEntity( new StringEntity( "BAD REQUEST" ) );
}
}
示例2: process
import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
if (request instanceof HttpEntityEnclosingRequest) {
final HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
final HttpEntity entity = entityRequest.getEntity();
if (entity != null) {
final GzipCompressingEntity zippedEntity = new GzipCompressingEntity(entity);
entityRequest.setEntity(zippedEntity);
request.removeHeaders(HTTP.CONTENT_ENCODING);
request.addHeader(zippedEntity.getContentEncoding());
request.removeHeaders(HTTP.CONTENT_LEN);
request.removeHeaders(HTTP.TRANSFER_ENCODING);
request.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
}
}
}
示例3: process
import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Override
public void process(org.apache.http.HttpRequest request, HttpContext httpContext) throws HttpException, IOException {
HttpRequest actual = new HttpRequest();
int id = counter.incrementAndGet();
String uri = (String) httpContext.getAttribute(ApacheHttpClient.URI_CONTEXT_KEY);
String method = request.getRequestLine().getMethod();
actual.setUri(uri);
actual.setMethod(method);
StringBuilder sb = new StringBuilder();
sb.append('\n').append(id).append(" > ").append(method).append(' ').append(uri).append('\n');
LoggingUtils.logHeaders(sb, id, '>', request, actual);
if (request instanceof HttpEntityEnclosingRequest) {
HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
HttpEntity entity = entityRequest.getEntity();
if (LoggingUtils.isPrintable(entity)) {
LoggingEntityWrapper wrapper = new LoggingEntityWrapper(entity); // todo optimize, preserve if stream
if (context.logger.isDebugEnabled()) {
String buffer = FileUtils.toString(wrapper.getContent());
sb.append(buffer).append('\n');
}
actual.setBody(wrapper.getBytes());
entityRequest.setEntity(wrapper);
}
}
context.setPrevRequest(actual);
if (context.logger.isDebugEnabled()) {
context.logger.debug(sb.toString());
}
}
示例4: sendRequestEntity
import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
public void sendRequestEntity(final HttpEntityEnclosingRequest request)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
assertOpen();
if (request.getEntity() == null) {
return;
}
this.entityserializer.serialize(
this.outbuffer,
request,
request.getEntity());
}
示例5: entityRequest
import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
public ConsumingNHttpEntity entityRequest(
final HttpEntityEnclosingRequest request,
final HttpContext context) throws HttpException, IOException {
return new ConsumingNHttpEntityTemplate(
request.getEntity(),
new FileWriteListener(useFileChannels));
}
示例6: sendRequestEntity
import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
public void sendRequestEntity(final HttpEntityEnclosingRequest request)
throws HttpException, IOException {
Args.notNull(request, "HTTP request");
ensureOpen();
final HttpEntity entity = request.getEntity();
if (entity == null) {
return;
}
final OutputStream outstream = prepareOutput(request);
entity.writeTo(outstream);
outstream.close();
}
示例7: testOPTIONSRequestsWithBodiesAndNoContentTypeHaveOneSupplied
import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Test
public void testOPTIONSRequestsWithBodiesAndNoContentTypeHaveOneSupplied() throws Exception {
final BasicHttpEntityEnclosingRequest options = new BasicHttpEntityEnclosingRequest("OPTIONS",
"/", HTTP_1_1);
options.setEntity(body);
options.setHeader("Content-Length", "1");
final Capture<HttpRequestWrapper> reqCap = new Capture<HttpRequestWrapper>();
EasyMock.expect(
mockBackend.execute(
EasyMock.eq(route),
EasyMock.capture(reqCap),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
replayMocks();
impl.execute(route, HttpRequestWrapper.wrap(options), context, null);
verifyMocks();
final HttpRequest forwarded = reqCap.getValue();
Assert.assertTrue(forwarded instanceof HttpEntityEnclosingRequest);
final HttpEntityEnclosingRequest reqWithBody = (HttpEntityEnclosingRequest) forwarded;
final HttpEntity reqBody = reqWithBody.getEntity();
Assert.assertNotNull(reqBody);
Assert.assertNotNull(reqBody.getContentType());
}
示例8: toCurl
import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
/**
* Generates a cURL command equivalent to the given request.
*/
private static String toCurl(HttpUriRequest request, boolean logAuthToken) throws IOException {
StringBuilder builder = new StringBuilder();
builder.append("curl ");
for (Header header: request.getAllHeaders()) {
if (!logAuthToken
&& (header.getName().equals("Authorization") ||
header.getName().equals("Cookie"))) {
continue;
}
builder.append("--header \"");
builder.append(header.toString().trim());
builder.append("\" ");
}
URI uri = request.getURI();
// If this is a wrapped request, use the URI from the original
// request instead. getURI() on the wrapper seems to return a
// relative URI. We want an absolute URI.
if (request instanceof RequestWrapper) {
HttpRequest original = ((RequestWrapper) request).getOriginal();
if (original instanceof HttpUriRequest) {
uri = ((HttpUriRequest) original).getURI();
}
}
builder.append("\"");
builder.append(uri);
builder.append("\"");
if (request instanceof HttpEntityEnclosingRequest) {
HttpEntityEnclosingRequest entityRequest =
(HttpEntityEnclosingRequest) request;
HttpEntity entity = entityRequest.getEntity();
if (entity != null && entity.isRepeatable()) {
if (entity.getContentLength() < 1024) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
entity.writeTo(stream);
String entityString = stream.toString();
// TODO: Check the content type, too.
builder.append(" --data-ascii \"")
.append(entityString)
.append("\"");
} else {
builder.append(" [TOO MUCH DATA TO INCLUDE]");
}
}
}
return builder.toString();
}
示例9: HttpEntityEnclosingRequestWrapper
import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
public HttpEntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request) {
super(request);
this.entity = request.getEntity();
}
示例10: enhance
import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
static void enhance(final HttpEntityEnclosingRequest request) {
final HttpEntity entity = request.getEntity();
if (entity != null && !entity.isRepeatable() && !isEnhanced(entity)) {
request.setEntity(new RequestEntityProxy(entity));
}
}
示例11: HttpEntityEnclosingRequestWrapper
import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
HttpEntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request, final HttpHost target) {
super(request, target);
this.entity = request.getEntity();
}