当前位置: 首页>>代码示例>>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;未经允许,请勿转载。