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


Java HttpEntityEnclosingRequest.setEntity方法代码示例

本文整理汇总了Java中org.apache.http.HttpEntityEnclosingRequest.setEntity方法的典型用法代码示例。如果您正苦于以下问题:Java HttpEntityEnclosingRequest.setEntity方法的具体用法?Java HttpEntityEnclosingRequest.setEntity怎么用?Java HttpEntityEnclosingRequest.setEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.HttpEntityEnclosingRequest的用法示例。


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

示例1: testSimpleSigner

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Test
public void testSimpleSigner() throws Exception {
    HttpEntityEnclosingRequest request =
            new BasicHttpEntityEnclosingRequest("GET", "/query?a=b");
    request.setEntity(new StringEntity("I'm an entity"));
    request.addHeader("foo", "bar");
    request.addHeader("content-length", "0");

    HttpCoreContext context = new HttpCoreContext();
    context.setTargetHost(HttpHost.create("localhost"));

    createInterceptor().process(request, context);

    assertEquals("bar", request.getFirstHeader("foo").getValue());
    assertEquals("wuzzle", request.getFirstHeader("Signature").getValue());
    assertNull(request.getFirstHeader("content-length"));
}
 
开发者ID:awslabs,项目名称:aws-request-signing-apache-interceptor,代码行数:18,代码来源:AWSRequestSigningApacheInterceptorTest.java

示例2: testEncodedUriSigner

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Test
public void testEncodedUriSigner() throws Exception {
    HttpEntityEnclosingRequest request =
            new BasicHttpEntityEnclosingRequest("GET", "/foo-2017-02-25%2Cfoo-2017-02-26/_search?a=b");
    request.setEntity(new StringEntity("I'm an entity"));
    request.addHeader("foo", "bar");
    request.addHeader("content-length", "0");

    HttpCoreContext context = new HttpCoreContext();
    context.setTargetHost(HttpHost.create("localhost"));

    createInterceptor().process(request, context);

    assertEquals("bar", request.getFirstHeader("foo").getValue());
    assertEquals("wuzzle", request.getFirstHeader("Signature").getValue());
    assertNull(request.getFirstHeader("content-length"));
    assertEquals("/foo-2017-02-25%2Cfoo-2017-02-26/_search", request.getFirstHeader("resourcePath").getValue());
}
 
开发者ID:awslabs,项目名称:aws-request-signing-apache-interceptor,代码行数:19,代码来源:AWSRequestSigningApacheInterceptorTest.java

示例3: executeInternal

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Override
protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers, byte[] bufferedOutput)
		throws IOException {

	HttpComponentsClientHttpRequest.addHeaders(this.httpRequest, headers);

	if (this.httpRequest instanceof HttpEntityEnclosingRequest) {
		HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest;
		HttpEntity requestEntity = new NByteArrayEntity(bufferedOutput);
		entityEnclosingRequest.setEntity(requestEntity);
	}

	final HttpResponseFutureCallback callback = new HttpResponseFutureCallback();
	final Future<HttpResponse> futureResponse =
			this.httpClient.execute(this.httpRequest, this.httpContext, callback);
	return new ClientHttpResponseFuture(futureResponse, callback);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:HttpComponentsAsyncClientHttpRequest.java

示例4: pushContent

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
private void pushContent(HttpUriRequest request, String contentType, String contentEncoding, byte[] content) {

		// TODO: check other preconditions?
		if (contentType != null && content != null && request instanceof HttpEntityEnclosingRequest) {
			BasicHttpEntity entity = new BasicHttpEntity();
			entity.setContent(new ByteArrayInputStream(content));
			entity.setContentLength(content.length);
			entity.setChunked(false);
			if (contentEncoding != null)
				entity.setContentEncoding(contentEncoding);
			entity.setContentType(contentType);
			HttpEntityEnclosingRequest rr = (HttpEntityEnclosingRequest) request;
			rr.setEntity(entity);
		}

	}
 
开发者ID:RestComm,项目名称:camelgateway,代码行数:17,代码来源:CamelGatewaySbb.java

示例5: consumesBodyOf100ContinueResponseIfItArrives

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Test
public void consumesBodyOf100ContinueResponseIfItArrives() throws Exception {
    final HttpEntityEnclosingRequest req = new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
    final int nbytes = 128;
    req.setHeader("Content-Length","" + nbytes);
    req.setHeader("Content-Type", "application/octet-stream");
    final HttpEntity postBody = new ByteArrayEntity(HttpTestUtils.getRandomBytes(nbytes));
    req.setEntity(postBody);
    final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);

    final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_CONTINUE, "Continue");
    final Flag closed = new Flag();
    final ByteArrayInputStream bais = makeTrackableBody(nbytes, closed);
    resp.setEntity(new InputStreamEntity(bais, -1));

    try {
        impl.ensureProtocolCompliance(wrapper, resp);
    } catch (final ClientProtocolException expected) {
    }
    assertTrue(closed.set || bais.read() == -1);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestResponseProtocolCompliance.java

示例6: testDigestAuthenticationQopAuthOrAuthIntNonRepeatableEntity

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Test
public void testDigestAuthenticationQopAuthOrAuthIntNonRepeatableEntity() throws Exception {
    final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
            "qop=\"auth,auth-int\"";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
    request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1));
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final DigestScheme authscheme = new DigestScheme();
    final HttpContext context = new BasicHttpContext();
    authscheme.processChallenge(authChallenge);
    final Header authResponse = authscheme.authenticate(cred, request, context);

    Assert.assertEquals("Post:/", authscheme.getA2());

    final Map<String, String> table = parseAuthResponse(authResponse);
    Assert.assertEquals("username", table.get("username"));
    Assert.assertEquals("realm1", table.get("realm"));
    Assert.assertEquals("/", table.get("uri"));
    Assert.assertEquals("auth", table.get("qop"));
    Assert.assertEquals("f2a3f18799759d4f1a1c068b92b573cb", table.get("nonce"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestDigestScheme.java

示例7: testInvalidatesRelativeUrisInContentLocationHeadersOnPUTs

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Test
public void testInvalidatesRelativeUrisInContentLocationHeadersOnPUTs() throws Exception {
    final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
    putRequest.setEntity(HttpTestUtils.makeBody(128));
    putRequest.setHeader("Content-Length","128");

    final String relativePath = "/content";
    putRequest.setHeader("Content-Location",relativePath);

    final String theUri = "http://foo.example.com:80/";
    cacheEntryHasVariantMap(new HashMap<String,String>());

    cacheReturnsEntryForUri(theUri);

    impl.flushInvalidatedCacheEntries(host, putRequest);

    verify(mockEntry).getVariantMap();
    verify(mockStorage).getEntry(theUri);
    verify(mockStorage).removeEntry(theUri);
    verify(mockStorage).removeEntry("http://foo.example.com:80/content");
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestCacheInvalidator.java

示例8: doPost

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
/**
 * Send a HTTP POST request to the specified URL
 *
 * @param url         Target endpoint URL
 * @param headers     Any HTTP headers that should be added to the request
 * @param payload     Content payload that should be sent
 * @param contentType Content-type of the request
 * @return Returned HTTP response
 * @throws IOException If an error occurs while making the invocation
 */
public HttpResponse doPost(String url, final Map<String, String> headers,
                           final String payload, String contentType) throws IOException {
    HttpUriRequest request = new HttpPost(url);
    setHeaders(headers, request);
    HttpEntityEnclosingRequest entityEncReq = (HttpEntityEnclosingRequest) request;
    final boolean zip = headers != null && "gzip".equals(headers.get(HttpHeaders.CONTENT_ENCODING));

    EntityTemplate ent = new EntityTemplate(new ContentProducer() {
        public void writeTo(OutputStream outputStream) throws IOException {
            OutputStream out = outputStream;
            if (zip) {
                out = new GZIPOutputStream(outputStream);
            }
            out.write(payload.getBytes());
            out.flush();
            out.close();
        }
    });
    ent.setContentType(contentType);
    if (zip) {
        ent.setContentEncoding("gzip");
    }
    entityEncReq.setEntity(ent);
    return client.execute(request);
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:36,代码来源:SimpleHttpClient.java

示例9: doPatch

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
/**
 * Send a HTTP PATCH request to the specified URL
 *
 * @param url         Target endpoint URL
 * @param headers     Any HTTP headers that should be added to the request
 * @param payload     Content payload that should be sent
 * @param contentType Content-type of the request
 * @return Returned HTTP response
 * @throws IOException If an error occurs while making the invocation
 */
public HttpResponse doPatch(String url, final Map<String, String> headers,
                            final String payload, String contentType) throws IOException {
    HttpUriRequest request = new HttpPatch(url);
    setHeaders(headers, request);
    HttpEntityEnclosingRequest entityEncReq = (HttpEntityEnclosingRequest) request;
    final boolean zip = headers != null && "gzip".equals(headers.get(HttpHeaders.CONTENT_ENCODING));

    EntityTemplate ent = new EntityTemplate(new ContentProducer() {
        public void writeTo(OutputStream outputStream) throws IOException {
            OutputStream out = outputStream;
            if (zip) {
                out = new GZIPOutputStream(outputStream);
            }
            out.write(payload.getBytes());
            out.flush();
            out.close();
        }
    });
    ent.setContentType(contentType);
    if (zip) {
        ent.setContentEncoding("gzip");
    }
    entityEncReq.setEntity(ent);
    return client.execute(request);
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:36,代码来源:SimpleHttpClient.java

示例10: testDigestAuthenticationQopAuthInt

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Test
public void testDigestAuthenticationQopAuthInt() throws Exception {
    final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
            "qop=\"auth,auth-int\"";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
    request.setEntity(new StringEntity("abc\u00e4\u00f6\u00fcabc", HTTP.DEF_CONTENT_CHARSET));
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final DigestScheme authscheme = new DigestScheme();
    final HttpContext context = new BasicHttpContext();
    authscheme.processChallenge(authChallenge);
    final Header authResponse = authscheme.authenticate(cred, request, context);

    Assert.assertEquals("Post:/:acd2b59cd01c7737d8069015584c6cac", authscheme.getA2());

    final Map<String, String> table = parseAuthResponse(authResponse);
    Assert.assertEquals("username", table.get("username"));
    Assert.assertEquals("realm1", table.get("realm"));
    Assert.assertEquals("/", table.get("uri"));
    Assert.assertEquals("auth-int", table.get("qop"));
    Assert.assertEquals("f2a3f18799759d4f1a1c068b92b573cb", table.get("nonce"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestDigestScheme.java

示例11: testInvalidatesUrisInLocationHeadersOnPUTs

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Test
public void testInvalidatesUrisInLocationHeadersOnPUTs() throws Exception {
    final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
    putRequest.setEntity(HttpTestUtils.makeBody(128));
    putRequest.setHeader("Content-Length","128");

    final String contentLocation = "http://foo.example.com/content";
    putRequest.setHeader("Location",contentLocation);

    final String theUri = "http://foo.example.com:80/";
    cacheEntryHasVariantMap(new HashMap<String,String>());

    cacheReturnsEntryForUri(theUri);

    impl.flushInvalidatedCacheEntries(host, putRequest);

    verify(mockEntry).getVariantMap();
    verify(mockStorage).getEntry(theUri);
    verify(mockStorage).removeEntry(theUri);
    verify(mockStorage).removeEntry(cacheKeyGenerator.canonicalizeUri(contentLocation));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestCacheInvalidator.java

示例12: doPut

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
/**
 * Send a HTTP PUT request to the specified URL
 *
 * @param url         Target endpoint URL
 * @param headers     Any HTTP headers that should be added to the request
 * @param payload     Content payload that should be sent
 * @param contentType Content-type of the request
 * @return Returned HTTP response
 * @throws IOException If an error occurs while making the invocation
 */
public HttpResponse doPut(String url, final Map<String, String> headers,
                          final String payload, String contentType) throws IOException {
    HttpUriRequest request = new HttpPut(url);
    setHeaders(headers, request);
    HttpEntityEnclosingRequest entityEncReq = (HttpEntityEnclosingRequest) request;
    final boolean zip = headers != null && "gzip".equals(headers.get(HttpHeaders.CONTENT_ENCODING));

    EntityTemplate ent = new EntityTemplate(new ContentProducer() {
        public void writeTo(OutputStream outputStream) throws IOException {
            OutputStream out = outputStream;
            if (zip) {
                out = new GZIPOutputStream(outputStream);
            }
            out.write(payload.getBytes());
            out.flush();
            out.close();
        }
    });
    ent.setContentType(contentType);
    if (zip) {
        ent.setContentEncoding("gzip");
    }
    entityEncReq.setEntity(ent);
    return client.execute(request);
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:36,代码来源:SimpleHttpClient.java

示例13: makeRequest

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
private void makeRequest(HttpClientConnection conn, String body, Map<String, String> headers)
    throws IOException, HttpException {
  HttpEntityEnclosingRequest req = new HttpPost("/");
  req.setHeaders(
      new Header[] {
        new BasicHeader(HeaderMapper.SERVICE, SERVICE),
        new BasicHeader(HeaderMapper.PROCEDURE, ECHO_PROCEDURE),
        new BasicHeader(HeaderMapper.CALLER, CLIENT),
        new BasicHeader(HeaderMapper.ENCODING, RawEncoding.ENCODING),
        new BasicHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(body.length()))
      });
  headers.forEach(req::setHeader);
  req.setEntity(new ByteArrayEntity(body.getBytes(Charsets.UTF_8)));
  conn.sendRequestHeader(req);
  conn.sendRequestEntity(req);
  conn.flush();

  HttpResponse res = conn.receiveResponseHeader();
  assertEquals(HttpStatus.SC_OK, res.getStatusLine().getStatusCode());

  conn.receiveResponseEntity(res);
  String echo = EntityUtils.toString(res.getEntity(), Charsets.UTF_8);
  assertEquals(body, echo);
}
 
开发者ID:yarpc,项目名称:yarpc-java,代码行数:25,代码来源:HttpConnectionReuseTest.java

示例14: 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

示例15: executeInternal

import org.apache.http.HttpEntityEnclosingRequest; //导入方法依赖的package包/类
@Override
protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
	addHeaders(this.httpRequest, headers);

	if (this.httpRequest instanceof HttpEntityEnclosingRequest) {
		HttpEntityEnclosingRequest entityEnclosingRequest =
				(HttpEntityEnclosingRequest) this.httpRequest;
		HttpEntity requestEntity = new ByteArrayEntity(bufferedOutput);
		entityEnclosingRequest.setEntity(requestEntity);
	}
	CloseableHttpResponse httpResponse = this.httpClient.execute(this.httpRequest, this.httpContext);
	return new HttpComponentsClientHttpResponse(httpResponse);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:HttpComponentsClientHttpRequest.java


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