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