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


Java HttpEntityEnclosingRequest.getEntity方法代码示例

本文整理汇总了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" ) );
    }
}
 
开发者ID:peter-mount,项目名称:filesystem,代码行数:22,代码来源:SaveContentAction.java

示例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);
        }

    }
}
 
开发者ID:zalando-stups,项目名称:put-it-to-rest,代码行数:21,代码来源:GzippingHttpRequestInterceptor.java

示例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());
    }
}
 
开发者ID:intuit,项目名称:karate,代码行数:30,代码来源:RequestLoggingInterceptor.java

示例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());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:AbstractHttpClientConnection.java

示例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));
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:8,代码来源:NHttpFileServer.java

示例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();
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:13,代码来源:DefaultBHttpClientConnection.java

示例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());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:28,代码来源:TestProtocolDeviations.java

示例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();
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:58,代码来源:AndroidHttpClient.java

示例9: HttpEntityEnclosingRequestWrapper

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
public HttpEntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request) {
    super(request);
    this.entity = request.getEntity();
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:5,代码来源:HttpRequestWrapper.java

示例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));
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:7,代码来源:RequestEntityProxy.java

示例11: HttpEntityEnclosingRequestWrapper

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
HttpEntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request, final HttpHost target) {
    super(request, target);
    this.entity = request.getEntity();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:5,代码来源:HttpRequestWrapper.java


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