當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。