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


Java HttpEntityEnclosingRequestBase.getEntity方法代码示例

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


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

示例1: doHandle

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
protected void doHandle(String uriId,HttpUriRequest request,Object result){
	if(this.isError(result)){
		String content = null;
		if(request instanceof HttpEntityEnclosingRequestBase){
			HttpEntityEnclosingRequestBase request_base = (HttpEntityEnclosingRequestBase)request;
			HttpEntity entity = request_base.getEntity();
			//MULTIPART_FORM_DATA 请求类型判断
			if(entity.getContentType().toString().indexOf(ContentType.MULTIPART_FORM_DATA.getMimeType()) == -1){
				try {
					content = EntityUtils.toString(entity);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if(logger.isErrorEnabled()){
				logger.error("URI[{}] {} Content:{} Result:{}",
						uriId,
						request.getURI(),
						content == null ? "multipart_form_data" : content,
						result == null? null : JsonUtil.toJSONString(result));
			}
		}
		this.handle(uriId,request.getURI().toString(),content,result);
	}
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:26,代码来源:ResultErrorHandler.java

示例2: testWithBody

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
@Test
public void testWithBody() throws Exception {
    final InputStream bodyStream = mock(InputStream.class);

    testBuilder.body(bodyStream, "plain/text")
            .digestSha1("checksum")
            .filename("file.txt")
            .slug("slug_value")
            .perform();

    final ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);
    verify(client).executeRequest(eq(uri), requestCaptor.capture());

    final HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) requestCaptor.getValue();
    final HttpEntity bodyEntity = request.getEntity();
    assertEquals(bodyStream, bodyEntity.getContent());

    assertEquals("plain/text", request.getFirstHeader(CONTENT_TYPE).getValue());
    assertEquals("sha1=checksum", request.getFirstHeader(DIGEST).getValue());
    assertEquals("slug_value", request.getFirstHeader(SLUG).getValue());
    assertEquals("attachment; filename=\"file.txt\"", request.getFirstHeader(CONTENT_DISPOSITION).getValue());
}
 
开发者ID:fcrepo4-exts,项目名称:fcrepo-java-client,代码行数:23,代码来源:PostBuilderTest.java

示例3: testWithBodyMultipleChecksums

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
@Test
public void testWithBodyMultipleChecksums() throws Exception {
    final InputStream bodyStream = mock(InputStream.class);

    testBuilder.body(bodyStream, "plain/text")
            .digestSha1("checksum")
            .digestSha256("checksum256")
            .perform();

    final ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);
    verify(client).executeRequest(eq(uri), requestCaptor.capture());

    final HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) requestCaptor.getValue();
    final HttpEntity bodyEntity = request.getEntity();
    assertEquals(bodyStream, bodyEntity.getContent());

    assertEquals("plain/text", request.getFirstHeader(CONTENT_TYPE).getValue());
    assertEquals("sha1=checksum, sha256=checksum256", request.getFirstHeader(DIGEST).getValue());
}
 
开发者ID:fcrepo4-exts,项目名称:fcrepo-java-client,代码行数:20,代码来源:PostBuilderTest.java

示例4: testWithBody

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
@Test
public void testWithBody() throws Exception {
    final InputStream bodyStream = mock(InputStream.class);

    testBuilder.body(bodyStream, "plain/text")
            .digestSha1("checksum")
            .filename("file.txt")
            .perform();

    final ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);
    verify(client).executeRequest(eq(uri), requestCaptor.capture());

    final HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) requestCaptor.getValue();
    final HttpEntity bodyEntity = request.getEntity();
    assertEquals(bodyStream, bodyEntity.getContent());

    assertEquals("plain/text", request.getFirstHeader(CONTENT_TYPE).getValue());
    assertEquals("sha1=checksum", request.getFirstHeader(DIGEST).getValue());
    assertEquals("attachment; filename=\"file.txt\"", request.getFirstHeader(CONTENT_DISPOSITION).getValue());
}
 
开发者ID:fcrepo4-exts,项目名称:fcrepo-java-client,代码行数:21,代码来源:PutBuilderTest.java

示例5: testWithModificationHeaders

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
@Test
public void testWithModificationHeaders() throws Exception {
    final InputStream bodyStream = mock(InputStream.class);

    final String etag = "123456";
    final String lastModified = "Mon, 19 May 2014 19:44:59 GMT";
    testBuilder.body(bodyStream, "plain/text")
            .ifMatch(etag)
            .ifUnmodifiedSince(lastModified)
            .perform();

    final ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);
    verify(client).executeRequest(eq(uri), requestCaptor.capture());

    final HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) requestCaptor.getValue();
    final HttpEntity bodyEntity = request.getEntity();
    assertEquals(bodyStream, bodyEntity.getContent());

    assertEquals("plain/text", request.getFirstHeader(CONTENT_TYPE).getValue());
    assertEquals(etag, request.getFirstHeader(IF_MATCH).getValue());
    assertEquals(lastModified, request.getFirstHeader(IF_UNMODIFIED_SINCE).getValue());
}
 
开发者ID:fcrepo4-exts,项目名称:fcrepo-java-client,代码行数:23,代码来源:PutBuilderTest.java

示例6: loggerRequest

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
/**
 * 日志记录
 * @param request request
 * @return log request id
 */
private static String loggerRequest(HttpUriRequest request){
	String id = UUID.randomUUID().toString();
	if(logger.isInfoEnabled()||logger.isDebugEnabled()){
		if(request instanceof HttpEntityEnclosingRequestBase){
			HttpEntityEnclosingRequestBase request_base = (HttpEntityEnclosingRequestBase)request;
			HttpEntity entity = request_base.getEntity();
			String content = null;
			//MULTIPART_FORM_DATA 请求类型判断
			if(entity.getContentType().toString().indexOf(ContentType.MULTIPART_FORM_DATA.getMimeType()) == -1){
				try {
					content = EntityUtils.toString(entity);
				} catch (Exception e) {
					e.printStackTrace();
					logger.error(e.getMessage());
				}
			}
			logger.info("URI[{}] {} {} ContentLength:{} Content:{}",
		    id,
			request.getURI().toString(),
			entity.getContentType(),
			entity.getContentLength(),
			content == null?"multipart_form_data":content);
		}else{
			logger.info("URI[{}] {}",id,request.getURI().toString());
		}
	}
	return id;
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:34,代码来源:LocalHttpClient.java

示例7: testAttachment

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
@Test
public void testAttachment() throws Exception {
    final InputStream bodyStream = mock(InputStream.class);
    testBuilder.body(bodyStream, "plain/text").filename(null).perform();

    final ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);
    verify(client).executeRequest(eq(uri), requestCaptor.capture());

    final HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) requestCaptor.getValue();
    final HttpEntity bodyEntity = request.getEntity();
    assertEquals(bodyStream, bodyEntity.getContent());
    assertEquals("attachment", request.getFirstHeader(CONTENT_DISPOSITION).getValue());
}
 
开发者ID:fcrepo4-exts,项目名称:fcrepo-java-client,代码行数:14,代码来源:PostBuilderTest.java

示例8: testBodyNoType

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
@Test
public void testBodyNoType() throws Exception {
    final InputStream bodyStream = mock(InputStream.class);

    testBuilder.body(bodyStream).perform();

    final ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);
    verify(client).executeRequest(eq(uri), requestCaptor.capture());

    final HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) requestCaptor.getValue();
    final HttpEntity bodyEntity = request.getEntity();
    assertEquals(bodyStream, bodyEntity.getContent());
    assertEquals("application/octet-stream", request.getFirstHeader(CONTENT_TYPE).getValue());
}
 
开发者ID:fcrepo4-exts,项目名称:fcrepo-java-client,代码行数:15,代码来源:PostBuilderTest.java

示例9: testDisposition

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
@Test
public void testDisposition() throws Exception {
    final InputStream bodyStream = mock(InputStream.class);
    testBuilder.body(bodyStream, "plain/text").filename(null).perform();

    final ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);
    verify(client).executeRequest(eq(uri), requestCaptor.capture());

    final HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) requestCaptor.getValue();
    final HttpEntity bodyEntity = request.getEntity();
    assertEquals(bodyStream, bodyEntity.getContent());
    assertEquals("attachment", request.getFirstHeader(CONTENT_DISPOSITION).getValue());
}
 
开发者ID:fcrepo4-exts,项目名称:fcrepo-java-client,代码行数:14,代码来源:PutBuilderTest.java

示例10: testSearchAutomaticallyUsesPost

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
@SuppressWarnings("unused")
@Test
public void testSearchAutomaticallyUsesPost() throws Exception {

	String msg = getPatientFeedWithOneResult();

	ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
	when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
	when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
	when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
	when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));

	IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");

	String longValue = StringUtils.leftPad("", 20000, 'B');

	//@formatter:off
	Bundle response = client.search()
			.forResource("Patient")
			.where(Patient.NAME.matches().value(longValue))
			.execute();
	//@formatter:on

	assertEquals("http://example.com/fhir/Patient/_search", capt.getValue().getURI().toString());

	HttpEntityEnclosingRequestBase enc = (HttpEntityEnclosingRequestBase) capt.getValue();
	UrlEncodedFormEntity ent = (UrlEncodedFormEntity) enc.getEntity();
	String string = IOUtils.toString(ent.getContent());
	ourLog.info(string);
	assertEquals("name=" + longValue, string);
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:32,代码来源:GenericClientTest.java

示例11: testSearchUsingPost

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
@SuppressWarnings("unused")
@Test
public void testSearchUsingPost() throws Exception {

	String msg = getPatientFeedWithOneResult();

	ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
	when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
	when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
	when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
	when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));

	IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");

	//@formatter:off
	Bundle response = client.search()
			.forResource("Patient")
			.where(Patient.NAME.matches().value("james"))
			.usingStyle(SearchStyleEnum.POST)
			.execute();
	//@formatter:on

	assertEquals("http://example.com/fhir/Patient/_search", capt.getValue().getURI().toString());

	HttpEntityEnclosingRequestBase enc = (HttpEntityEnclosingRequestBase) capt.getValue();
	UrlEncodedFormEntity ent = (UrlEncodedFormEntity) enc.getEntity();
	String string = IOUtils.toString(ent.getContent());
	ourLog.info(string);
	assertEquals("name=james", string);
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:31,代码来源:GenericClientTest.java

示例12: sendEntityData

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
/**
 * Creates the entity data to be sent.
 * <p>
 * If there is a file entry with a non-empty MIME type we use that to
 * set the request Content-Type header, otherwise we default to whatever
 * header is present from a Header Manager.
 * <p>
 * If the content charset {@link #getContentEncoding()} is null or empty 
 * we use the HC4 default provided by {@link HTTP#DEF_CONTENT_CHARSET} which is
 * ISO-8859-1.
 * 
 * @param entity to be processed, e.g. PUT or PATCH
 * @return the entity content, may be empty
 * @throws  UnsupportedEncodingException for invalid charset name
 * @throws IOException cannot really occur for ByteArrayOutputStream methods
 */
protected String sendEntityData( HttpEntityEnclosingRequestBase entity) throws IOException {
    // Buffer to hold the entity body
    StringBuilder entityBody = new StringBuilder(1000);
    boolean hasEntityBody = false;

    final HTTPFileArg[] files = getHTTPFiles();
    // Allow the mimetype of the file to control the content type
    // This is not obvious in GUI if you are not uploading any files,
    // but just sending the content of nameless parameters
    final HTTPFileArg file = files.length > 0? files[0] : null;
    String contentTypeValue = null;
    if(file != null && file.getMimeType() != null && file.getMimeType().length() > 0) {
        contentTypeValue = file.getMimeType();
        entity.setHeader(HEADER_CONTENT_TYPE, contentTypeValue); // we provide the MIME type here
    }

    // Check for local contentEncoding (charset) override; fall back to default for content body
    // we do this here rather so we can use the same charset to retrieve the data
    final String charset = getContentEncoding(HTTP.DEF_CONTENT_CHARSET.name());

    // Only create this if we are overriding whatever default there may be
    // If there are no arguments, we can send a file as the body of the request

    if(!hasArguments() && getSendFileAsPostBody()) {
        hasEntityBody = true;

        // If getSendFileAsPostBody returned true, it's sure that file is not null
        File reservedFile = FileServer.getFileServer().getResolvedFile(files[0].getPath());
        FileEntity fileRequestEntity = new FileEntity(reservedFile); // no need for content-type here
        entity.setEntity(fileRequestEntity);
    }
    // If none of the arguments have a name specified, we
    // just send all the values as the entity body
    else if(getSendParameterValuesAsPostBody()) {
        hasEntityBody = true;

        // Just append all the parameter values, and use that as the entity body
        StringBuilder entityBodyContent = new StringBuilder();
        for (JMeterProperty jMeterProperty : getArguments()) {
            HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
            // Note: if "Encoded?" is not selected, arg.getEncodedValue is equivalent to arg.getValue
            if (charset != null) {
                entityBodyContent.append(arg.getEncodedValue(charset));
            } else {
                entityBodyContent.append(arg.getEncodedValue());
            }
        }
        StringEntity requestEntity = new StringEntity(entityBodyContent.toString(), charset);
        entity.setEntity(requestEntity);
    }
    // Check if we have any content to send for body
    if(hasEntityBody) {
        // If the request entity is repeatable, we can send it first to
        // our own stream, so we can return it
        final HttpEntity entityEntry = entity.getEntity();
        if(entityEntry.isRepeatable()) {
            entityBody.append("<actual file content, not shown here>");
        }
        else { // this probably cannot happen
            entityBody.append("<RequestEntity was not repeatable, cannot view what was sent>");
        }
    }
    return entityBody.toString(); // may be the empty string
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:81,代码来源:HTTPHC4Impl.java


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