當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpEntityEnclosingRequestBase類代碼示例

本文整理匯總了Java中org.apache.http.client.methods.HttpEntityEnclosingRequestBase的典型用法代碼示例。如果您正苦於以下問題:Java HttpEntityEnclosingRequestBase類的具體用法?Java HttpEntityEnclosingRequestBase怎麽用?Java HttpEntityEnclosingRequestBase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpEntityEnclosingRequestBase類屬於org.apache.http.client.methods包,在下文中一共展示了HttpEntityEnclosingRequestBase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: matches

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入依賴的package包/類
@Override
public boolean matches(Request request) {
    try {
        HttpEntity entity = ((HttpEntityEnclosingRequestBase) request.getHttpRequest()).getEntity();
        if (entity == null) {
            return false;
        }
        String message = EntityUtils.toString(entity);
        return matcher.matches(message);
    } catch (IOException e) {
        return false;
    }
}
 
開發者ID:PawelAdamski,項目名稱:HttpClientMock,代碼行數:14,代碼來源:BodyMatcher.java

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

示例3: executeCallback

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入依賴的package包/類
private void executeCallback(HttpEntityEnclosingRequestBase request, String json, FutureCallback<HttpResponse> httpCallback) {
	if (json != null && json.length() > 0) {
		request.addHeader("Content-Type", "application/json");
		if (!this.httpCompress) {
			request.setEntity(generateStringEntity(json));
		} else {
			request.addHeader("Accept-Encoding", "gzip, deflate");
			request.setEntity(generateGZIPCompressEntity(json));
		}
	}

	FutureCallback<HttpResponse> responseCallback = null;
	if (httpCallback != null) {
		unCompletedTaskNum.incrementAndGet();
		responseCallback = this.httpResponseCallbackFactory.wrapUpBaseHttpFutureCallback(httpCallback);
	}

	httpclient.execute(request,responseCallback);
}
 
開發者ID:aliyun,項目名稱:HiTSDB-Client,代碼行數:20,代碼來源:HttpClient.java

示例4: wrapEntity

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入依賴的package包/類
private HttpRequestBase wrapEntity(SdkHttpFullRequest request,
                                   HttpEntityEnclosingRequestBase entityEnclosingRequest) {

    /*
     * We should never reuse the entity of the previous request, since
     * reading from the buffered entity will bypass reading from the
     * original request content. And if the content contains InputStream
     * wrappers that were added for validation-purpose (e.g.
     * Md5DigestCalculationInputStream), these wrappers would never be
     * read and updated again after AmazonHttpClient resets it in
     * preparation for the retry. Eventually, these wrappers would
     * return incorrect validation result.
     */
    if (request.content().isPresent()) {
        HttpEntity entity = new RepeatableInputStreamRequestEntity(request);
        if (request.headers().get(HttpHeaders.CONTENT_LENGTH) == null) {
            entity = ApacheUtils.newBufferedHttpEntity(entity);
        }
        entityEnclosingRequest.setEntity(entity);
    }

    return entityEnclosingRequest;
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:24,代碼來源:ApacheHttpRequestFactory.java

示例5: syncPut

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入依賴的package包/類
public String syncPut(String url, Header[] headers, HttpEntity entity, String contentType, String defaultEncoding)
		throws ClientProtocolException, IOException {
	HttpEntityEnclosingRequestBase request = addEntityToRequestBase(new HttpPut(url), entity);
	if (headers != null)
		request.setHeaders(headers);
	if (contentType != null) {
		request.setHeader("Content-Type", contentType);
	}
	return parseResponse(syncExec(request), defaultEncoding);
}
 
開發者ID:ROKOLabs,項目名稱:ROKO.Stickers-Android,代碼行數:11,代碼來源:AsyncHttpClient.java

示例6: sendInternal

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入依賴的package包/類
private HttpClientOauthResponse sendInternal() throws Exception
{
    String urlToGo = getCompleteUrl();

    HttpClient client = httpClientProvider.getHttpClient();

    // always POST when doing oauth dance on bitbucket
    // see DefaultAp10Api#getAccessTokenVerb or getRequestTokenVerb
    HttpRequestBase requestMethod = new HttpPost();
    requestMethod.setURI(new URI(urlToGo));
    
    setHeaders(requestMethod);
    setPayloadParams((HttpEntityEnclosingRequestBase) requestMethod);
    
    HttpResponse response = null;

    response = client.execute(requestMethod);

    return new HttpClientOauthResponse(response, requestMethod);
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:21,代碼來源:HttpClientOauthRequest.java

示例7: createEntityBase

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入依賴的package包/類
/**
 * 根據請求信息創建HttpEntityEnclosingRequestBase.
 *
 * @param cls     類型Class
 * @param url     URL
 * @param headers Http請求頭信息
 * @param params  請求參數列表
 * @return HttpEntityEnclosingRequestBase
 */
protected HttpEntityEnclosingRequestBase createEntityBase(final Class<? extends HttpEntityEnclosingRequestBase> cls, final String url,
                                                          final Map<String, String> headers, final Map<String, String> params) {
    try {
        final HttpEntityEnclosingRequestBase entityBase = ReflectUtils.newInstance(cls, url);
        if (!CollectionUtils.isEmpty(headers)) {
            headers.forEach((key, value) -> entityBase.addHeader(key, value));
        }

        final List<NameValuePair> pairs = covertParams2Nvps(params);
        entityBase.setEntity(new UrlEncodedFormEntity(pairs, this.conf.getCharset()));
        return entityBase;
    } catch (final Throwable e) {
        throw new HttpClientInvokeException(e.getMessage(), e);
    }
}
 
開發者ID:nano-projects,項目名稱:nano-framework,代碼行數:25,代碼來源:AbstractHttpClient.java

示例8: addPostParams

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入依賴的package包/類
private void addPostParams(HttpEntityEnclosingRequestBase request) throws UnsupportedEncodingException {
    final MultipartEntityBuilder multipartBuilder = MultipartEntityBuilder.create();
    List<NameValuePair> formParams = new ArrayList<>();
    postVariables.forEach((name, values) -> values.forEach(value -> {
        if (multipart) {
            if (value.startsWith("@")) {
                File f = new File(value.substring(1));
                multipartBuilder.addBinaryBody(name, f, ContentType.DEFAULT_BINARY, f.getName());
            } else {
                multipartBuilder.addTextBody(name, value);
            }
        } else {
            formParams.add(new BasicNameValuePair(name, value));
        }
    }));
    if (multipart) {
        request.setEntity(multipartBuilder.build());
    } else {
        request.setEntity(new UrlEncodedFormEntity(formParams));
    }
}
 
開發者ID:Adobe-Consulting-Services,項目名稱:curly,代碼行數:22,代碼來源:ActionRunner.java

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

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

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

示例12: buildBodyParameters

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入依賴的package包/類
@Override
void buildBodyParameters(HttpRequestBase request) {
	List<NameValuePair> fields = new ArrayList<NameValuePair>();
	for (Node field : getFormParams()) {
		String name = XMLCrawler.getAttributeValue("name", field);
		String value = XMLCrawler.getAttributeValue("value", field);
		// System.out.println(name+"="+value);
		NameValuePair nvp = new BasicNameValuePair(name, value);
		fields.add(nvp);
	}
	try {
		((HttpEntityEnclosingRequestBase) request).setEntity(new UrlEncodedFormEntity(fields));
	} catch (UnsupportedEncodingException e) {
		System.out.println("Error encoding URL." + e.getMessage());
	}

}
 
開發者ID:OWASP,項目名稱:Benchmark,代碼行數:18,代碼來源:ServletTestCaseRequest.java

示例13: getHTTPPatch

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入依賴的package包/類
public static HttpEntityEnclosingRequestBase getHTTPPatch(String url) throws PageException	{
	// try to load the class, perhaps class does not exists with older jars
	Class clazz = ClassUtil.loadClass(
			HttpEntityEnclosingRequestBase.class.getClassLoader(),
			"org.apache.http.client.methods.HttpPatch",null);
	if(clazz==null) throw new ApplicationException("cannot load class [org.apache.http.client.methods.HttpPatch], you have to update your apache-commons-http*** jars");
	try {
		return (HttpEntityEnclosingRequestBase) ClassUtil.loadInstance(clazz,new Object[]{url});
	}
	catch(Throwable t) {
		ExceptionUtil.rethrowIfNecessary(t);
       	throw Caster.toPageException(t);
	}
	
	
	//FUTURE if we have the new jar for sure return new HttpPatch(url);
}
 
開發者ID:lucee,項目名稱:Lucee,代碼行數:18,代碼來源:HTTPPatchFactory.java

示例14: setEntityIfNonEmptyBody

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入依賴的package包/類
/**
 * 如果request的請求體不為空,進行設置請求體信息
 * @param httpRequest
 * @param request
 * @throws AuthFailureError
 */
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
        Request<?> request) throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:HttpClientStack.java

示例15: setEntityIfNonEmptyBody

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入依賴的package包/類
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
        Request<?> request) throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:HttpClientStack.java


注:本文中的org.apache.http.client.methods.HttpEntityEnclosingRequestBase類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。