本文整理匯總了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();
}