Java Code Examples for org.apache.http.client.methods.HttpEntityEnclosingRequestBase#getEntity()

The following examples show how to use org.apache.http.client.methods.HttpEntityEnclosingRequestBase#getEntity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestReify.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static protected void reportRequest(RequestConfig cfg, HttpRequestBase req) {
  System.err.println("========= TestSide =========\n");
  System.err.println("Headers:\n");
  for (Header h : req.getAllHeaders()) {
    System.err.printf("\t%s = %s%n", h.getName(), h.getValue());
  }
  if ("post".equalsIgnoreCase(req.getMethod())) {
    HttpEntityEnclosingRequestBase b = (HttpEntityEnclosingRequestBase) req;
    HttpEntity he = b.getEntity();
    List<NameValuePair> content = null;
    try {
      String s = EntityUtils.toString(he);
      System.err.println(s);
    } catch (IOException e) {
      return;
    }
  }
  System.err.println("=========\n");
  System.err.flush();
}
 
Example 2
Source File: ApacheHttpClient4Signer.java    From oauth1-signer-java with MIT License 6 votes vote down vote up
public void sign(HttpRequestBase req) throws IOException {
  String payload = null;
  Charset charset = Charset.defaultCharset();
  if (HttpEntityEnclosingRequestBase.class.isAssignableFrom(req.getClass())) {
    HttpEntityEnclosingRequestBase requestBase = (HttpEntityEnclosingRequestBase) req;
    HttpEntity entity = requestBase.getEntity();
    if (entity.getContentLength() > 0) {
      if (!entity.isRepeatable()) {
        throw new IOException(
            "The signer needs to read the request payload but the input stream of this request cannot be read multiple times. Please provide the payload using a separate argument or ensure that the entity is repeatable.");
      }
      ContentType contentType = ContentType.get(entity);
      charset = contentType.getCharset();
      payload = EntityUtils.toString(entity, contentType.getCharset());
    }
  }

  String authHeader = OAuth.getAuthorizationHeader(req.getURI(), req.getMethod(), payload, charset, consumerKey, signingKey);
  req.setHeader(OAuth.AUTHORIZATION_HEADER_NAME, authHeader);
}
 
Example 3
Source File: ResultErrorHandler.java    From springboot-security-wechat with Apache License 2.0 6 votes vote down vote up
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);
	}
}
 
Example 4
Source File: LocalHttpClient.java    From springboot-security-wechat with Apache License 2.0 5 votes vote down vote up
/**
 * 日志记录
 * @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;
}