本文整理匯總了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;
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
示例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));
}
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
}
示例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);
}
示例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);
}
}
示例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);
}
}