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


Java BasicHttpEntity.setChunked方法代码示例

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


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

示例1: pushContent

import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的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

示例2: testLargePostChunked

import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
@Test
public void testLargePostChunked() throws Exception
{

	byte[] testData = new byte[128*1024];
	for (int i=0; i<testData.length; i++)
		testData[i] = (byte) (i%255);
	
	HttpPost post = new HttpPost("http://localhost:8192/");
	ResponseHandler<byte[]> responseHandler = new BasicResponseHandler();
	
	BasicHttpEntity entity = new BasicHttpEntity();
	entity.setChunked(true);
	entity.setContent(new ByteArrayInputStream(testData));
	post.setEntity(entity);
	
	byte[] responseBody = httpclient.execute(post, responseHandler);

	Assert.assertArrayEquals(testData, responseBody);
}
 
开发者ID:EricssonResearch,项目名称:trap,代码行数:21,代码来源:POSTIntegrationTests.java

示例3: commit

import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
public void commit() throws IOException, HttpException {
    if (this.commited) {
        return;
    }
    this.commited = true;
    
    this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, this.conn);
    this.context.setAttribute(ExecutionContext.HTTP_RESPONSE, this.response);
    
    BasicHttpEntity entity = new BasicHttpEntity();
    entity.setChunked(true);
    entity.setContentType(this.contentType);
    
    this.response.setEntity(entity);
    
    this.httpproc.process(this.response, this.context);
    this.conn.sendResponse(this.response);
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:19,代码来源:AxisHttpResponseImpl.java

示例4: doDeserialize

import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
/**
 * Creates a {@link BasicHttpEntity} based on properties of the given
 * message. The content of the entity is created by wrapping
 * {@link SessionInputBuffer} with a content decoder depending on the
 * transfer mechanism used by the message.
 * <p>
 * This method is called by the public
 * {@link #deserialize(SessionInputBuffer, HttpMessage)}.
 *
 * @param inbuffer the session input buffer.
 * @param message the message.
 * @return HTTP entity.
 * @throws HttpException in case of HTTP protocol violation.
 * @throws IOException in case of an I/O error.
 */
protected BasicHttpEntity doDeserialize(
        final SessionInputBuffer inbuffer,
        final HttpMessage message) throws HttpException, IOException {
    BasicHttpEntity entity = new BasicHttpEntity();

    long len = this.lenStrategy.determineLength(message);
    if (len == ContentLengthStrategy.CHUNKED) {
        entity.setChunked(true);
        entity.setContentLength(-1);
        entity.setContent(new ChunkedInputStream(inbuffer));
    } else if (len == ContentLengthStrategy.IDENTITY) {
        entity.setChunked(false);
        entity.setContentLength(-1);
        entity.setContent(new IdentityInputStream(inbuffer));
    } else {
        entity.setChunked(false);
        entity.setContentLength(len);
        entity.setContent(new ContentLengthInputStream(inbuffer, len));
    }

    Header contentTypeHeader = message.getFirstHeader(HTTP.CONTENT_TYPE);
    if (contentTypeHeader != null) {
        entity.setContentType(contentTypeHeader);
    }
    Header contentEncodingHeader = message.getFirstHeader(HTTP.CONTENT_ENCODING);
    if (contentEncodingHeader != null) {
        entity.setContentEncoding(contentEncodingHeader);
    }
    return entity;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:EntityDeserializer.java

示例5: getRequest

import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
@Override
protected HttpRequestBase getRequest(AccessProfile accessProfile) {
    HttpPost post = new HttpPost("/3/image");
    BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(stream);
    if (length > 0)
        entity.setContentLength(length);
    entity.setChunked(length <= 0);
    entity.setContentType("image/*");
    post.setEntity(entity);
    return post;
}
 
开发者ID:cab404,项目名称:maud,代码行数:13,代码来源:Imgur.java

示例6: newChunkedPost

import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
private static HttpPost newChunkedPost(String resource, byte[] bytes) {
    BasicHttpEntity basic = new BasicHttpEntity();
    basic.setChunked(true);
    basic.setContentLength(-1);
    basic.setContent(new ByteArrayInputStream(bytes));

    HttpPost post = new HttpPost(ServiceConfiguration.SERVICE_URL + "/" + resource);
    post.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM);
    post.setEntity(basic);
    return post;
}
 
开发者ID:redbooth,项目名称:baseline,代码行数:12,代码来源:TestHttpRequestHandler.java

示例7: generateRequest

import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
@Override
public HttpRequest generateRequest() throws IOException, HttpException {
    final BasicHttpEntity entity = new BasicHttpEntity();

    entity.setContentLength(this.getContentLength());
    entity.setContentType(this.getContentType());
    entity.setChunked(false);

    return this.createRequest(this.mRequest.getUri(), entity);
}
 
开发者ID:mwaylabs,项目名称:relution-jenkins-plugin,代码行数:11,代码来源:ZeroCopyFileRequestProducer.java

示例8: shouldSuccessfullyPostAndReceiveResponseAfterMakingUnsuccessfulPost

import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
@Test
public void shouldSuccessfullyPostAndReceiveResponseAfterMakingUnsuccessfulPost() throws Exception {
    // unsuccessful
    // how does this test work, you ask?
    // well, there's only one request processing
    // thread on the server so if that thread locks up waiting
    // for bytes that never come, even if the stream is closed
    // then the *second* request will time out.
    try {
        HttpPost post0 = new HttpPost(ServiceConfiguration.SERVICE_URL + "/" + Resources.BASIC_RESOURCE + "/data1");
        post0.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN);
        BasicHttpEntity basic = new BasicHttpEntity();
        basic.setChunked(true);
        basic.setContentLength(-1);
        basic.setContent(new InputStream() {

            private int counter = 0;

            @Override
            public int read() throws IOException {
                if (counter < (3 * 1024 * 1024)) {
                    counter++;
                    return 'a';
                } else {
                    throw new IOException("read failed");
                }
            }
        });
        post0.setEntity(basic);

        Future<HttpResponse> future0 = client.getClient().execute(post0, null);
        future0.get();
    } catch (Exception e) {
        // noop
    }

    // successful
    HttpPost post = new HttpPost(ServiceConfiguration.SERVICE_URL + "/" + Resources.BASIC_RESOURCE + "/data1");
    post.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN);
    post.setEntity(HttpUtils.writeStringToEntity("data2"));

    Future<HttpResponse> future = client.getClient().execute(post, null);
    HttpResponse response = future.get(10, TimeUnit.SECONDS);

    assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_OK));
    assertThat(HttpUtils.readStreamToString(response.getEntity().getContent()), equalTo("data1-data2"));
}
 
开发者ID:redbooth,项目名称:baseline,代码行数:48,代码来源:TestHttpRequestHandler.java

示例9: attachAssetToResponse

import org.apache.http.entity.BasicHttpEntity; //导入方法依赖的package包/类
private void attachAssetToResponse(HttpResponse response, InputStream inputStream, String filename) throws IOException {
    BasicHttpEntity body = new BasicHttpEntity();
    body.setContent(inputStream);
    body.setChunked(true);
    response.setEntity(body);
}
 
开发者ID:dinocore1,项目名称:MiniWeb,代码行数:7,代码来源:AssetsFileHandler.java


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