本文整理匯總了Java中org.apache.commons.httpclient.methods.EntityEnclosingMethod類的典型用法代碼示例。如果您正苦於以下問題:Java EntityEnclosingMethod類的具體用法?Java EntityEnclosingMethod怎麽用?Java EntityEnclosingMethod使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
EntityEnclosingMethod類屬於org.apache.commons.httpclient.methods包,在下文中一共展示了EntityEnclosingMethod類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleMultipartPost
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
/**
* Sets up the given {@link org.apache.commons.httpclient.methods.PostMethod} to send the same multipart POST data
* as was sent in the given {@link HttpServletRequest}
*
* @param postMethodProxyRequest The {@link org.apache.commons.httpclient.methods.PostMethod} that we are configuring to send a
* multipart POST request
* @param httpServletRequest The {@link HttpServletRequest} that contains the multipart
* POST data to be sent via the {@link org.apache.commons.httpclient.methods.PostMethod}
*/
@SuppressWarnings("unchecked")
public static void handleMultipartPost(
EntityEnclosingMethod postMethodProxyRequest,
HttpServletRequest httpServletRequest,
DiskFileItemFactory diskFileItemFactory)
throws ServletException {
// TODO: this function doesn't set any history data
try {
// just pass back the binary data
InputStreamRequestEntity ire = new InputStreamRequestEntity(httpServletRequest.getInputStream());
postMethodProxyRequest.setRequestEntity(ire);
postMethodProxyRequest.setRequestHeader(STRING_CONTENT_TYPE_HEADER_NAME, httpServletRequest.getHeader(STRING_CONTENT_TYPE_HEADER_NAME));
} catch (Exception e) {
throw new ServletException(e);
}
}
示例2: _invoke
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
private static HTTPResponse _invoke(HttpMethod httpMethod, URL url, String username, String password, long timeout, int maxRedirect,
String charset, String useragent, ProxyData proxy, Header[] headers, Map<String,String> params, Object body) throws IOException {
HttpClient client = new HttpClient();
HostConfiguration config = client.getHostConfiguration();
HttpState state = client.getState();
setHeader(httpMethod,headers);
if(CollectionUtil.isEmpty(params))setContentType(httpMethod,charset);
setUserAgent(httpMethod,useragent);
setTimeout(client,timeout);
setParams(httpMethod,params);
setCredentials(client,httpMethod,username,password);
setProxy(config,state,proxy);
if(body!=null && httpMethod instanceof EntityEnclosingMethod)setBody((EntityEnclosingMethod)httpMethod,body);
return new HTTPResponse3Impl(execute(client,httpMethod,maxRedirect),url);
}
示例3: executeInternal
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
@Override
public ClientHttpResponse executeInternal(HttpHeaders headers, byte[] output) throws IOException {
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
String headerName = entry.getKey();
for (String headerValue : entry.getValue()) {
httpMethod.addRequestHeader(headerName, headerValue);
}
}
if (this.httpMethod instanceof EntityEnclosingMethod) {
EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) this.httpMethod;
RequestEntity requestEntity = new ByteArrayRequestEntity(output);
entityEnclosingMethod.setRequestEntity(requestEntity);
}
this.httpClient.executeMethod(this.httpMethod);
return new CommonsClientHttpResponse(this.httpMethod);
}
示例4: sendPostData
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
private String sendPostData(HttpMethod method) throws IOException {
String form;
if (useAuthHeader) {
form = nonOAuthParams.get(0).getValue();
} else {
form = OAuth.formEncode(message.getParameters());
}
method.addRequestHeader(HEADER_CONTENT_LENGTH, form.length() + ""); //$NON-NLS-1$
if (method instanceof PostMethod || method instanceof PutMethod) {
StringRequestEntity requestEntity = new StringRequestEntity(form);
((EntityEnclosingMethod)method).setRequestEntity(requestEntity);
} else {
log.error("Logic error, method must be POST or PUT to send body"); //$NON-NLS-1$
}
return form;
}
示例5: sendPostData
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
private String sendPostData(HttpMethod method) throws IOException {
String form;
if (useAuthHeader) {
form = OAuth.formEncode(nonOAuthParams);
} else {
form = OAuth.formEncode(message.getParameters());
}
method.addRequestHeader(HEADER_CONTENT_TYPE, OAuth.FORM_ENCODED);
method.addRequestHeader(HEADER_CONTENT_LENGTH, form.length() + ""); //$NON-NLS-1$
if (method instanceof PostMethod || method instanceof PutMethod) {
StringRequestEntity requestEntity = new StringRequestEntity(
form, OAuth.FORM_ENCODED, OAuth.ENCODING);
((EntityEnclosingMethod)method).setRequestEntity(requestEntity);
} else {
log.error("Logic error, method must be POST or PUT to send body"); //$NON-NLS-1$
}
return form;
}
示例6: clone
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
/**
* Clones a HttpMethod. <br>
* <b>Attention:</b> You have to clone a method before it has
* been executed, because the URI can change if followRedirects
* is set to true.
*
* @param m the HttpMethod to clone
*
* @return the cloned HttpMethod, null if the HttpMethod could
* not be instantiated
*
* @throws java.io.IOException if the request body couldn't be read
*/
public static HttpMethod clone(HttpMethod m) {
HttpMethod copy = null;
try {
copy = m.getClass().newInstance();
}
catch (InstantiationException iEx) {}
catch (IllegalAccessException iaEx) {}
if ( copy == null ) {
return null;
}
copy.setDoAuthentication(m.getDoAuthentication());
copy.setFollowRedirects(m.getFollowRedirects());
copy.setPath( m.getPath() );
copy.setQueryString(m.getQueryString());
Header[] h = m.getRequestHeaders();
int size = (h == null) ? 0 : h.length;
for (int i = 0; i < size; i++) {
copy.setRequestHeader(new Header(h[i].getName(), h[i].getValue()));
}
copy.setStrictMode(m.isStrictMode());
if (m instanceof HttpMethodBase) {
copyHttpMethodBase((HttpMethodBase)m,(HttpMethodBase)copy);
}
if (m instanceof EntityEnclosingMethod) {
copyEntityEnclosingMethod((EntityEnclosingMethod)m,(EntityEnclosingMethod)copy);
}
return copy;
}
示例7: HttpMethodAdapter
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
public HttpMethodAdapter(HttpMethod request, HostConfiguration hostConfiguration) {
this.request = request;
if (request instanceof EntityEnclosingMethod) {
entity = ((EntityEnclosingMethod) request).getRequestEntity();
}
hc = hostConfiguration;
}
示例8: populateRequestBody
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
/**
* Adds the JSON as request-body the the method and sets the correct
* content-type.
* @param method EntityEnclosingMethod
* @param object JSONObject
*/
private void populateRequestBody(EntityEnclosingMethod method, JSONObject object)
{
try
{
method.setRequestEntity(new StringRequestEntity(object.toJSONString(), MIME_TYPE_JSON, "UTF-8"));
}
catch (UnsupportedEncodingException error)
{
// This will never happen!
throw new RuntimeException("All hell broke loose, a JVM that doesn't have UTF-8 encoding...");
}
}
示例9: setRequestContent
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
/**
* This function sets the request content.
*
* @param httpRequest
* The HTTP request
* @param httpMethodClient
* The apache HTTP method
*/
protected void setRequestContent(HTTPRequest httpRequest,HttpMethodBase httpMethodClient)
{
//set content
if(httpMethodClient instanceof EntityEnclosingMethod)
{
EntityEnclosingMethod pushMethod=(EntityEnclosingMethod)httpMethodClient;
RequestEntity requestEntity=null;
ContentType contentType=httpRequest.getContentType();
switch(contentType)
{
case STRING:
requestEntity=this.createStringRequestContent(httpRequest);
break;
case BINARY:
requestEntity=this.createBinaryRequestContent(httpRequest);
break;
case MULTI_PART:
requestEntity=this.createMultiPartRequestContent(httpRequest,httpMethodClient);
break;
default:
throw new FaxException("Unsupported content type: "+contentType);
}
//set request data
if(requestEntity!=null)
{
pushMethod.setRequestEntity(requestEntity);
pushMethod.setContentChunked(false);
}
}
}
示例10: setBody
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
private static void setBody(EntityEnclosingMethod httpMethod, Object body) throws IOException {
if(body!=null)
try {
httpMethod.setRequestEntity(toRequestEntity(body));
} catch (PageException e) {
throw ExceptionUtil.toIOException(e);
}
}
示例11: recordEntity
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
private void recordEntity(HttpMethod httpMethod, Trace trace) {
if (httpMethod instanceof EntityEnclosingMethod) {
final EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod)httpMethod;
final RequestEntity entity = entityEnclosingMethod.getRequestEntity();
if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
if (entitySampler.isSampling()) {
try {
String entityValue;
String charSet = entityEnclosingMethod.getRequestCharSet();
if (charSet == null || charSet.isEmpty()) {
charSet = HttpConstants.DEFAULT_CONTENT_CHARSET;
}
if (entity instanceof ByteArrayRequestEntity) {
entityValue = readByteArray((ByteArrayRequestEntity)entity, charSet);
} else if (entity instanceof StringRequestEntity) {
entityValue = readString((StringRequestEntity)entity);
} else {
entityValue = entity.getClass() + " (ContentType:" + entity.getContentType() + ")";
}
trace.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, entityValue);
} catch (Exception e) {
logger.debug("HttpEntityEnclosingRequest entity record fail. Caused:{}", e.getMessage(), e);
}
}
}
}
}
示例12: handleStandard
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
/**
* Sets up the given {@link PostMethod} to send the same standard POST data as was sent in the given {@link HttpServletRequest}
*
* @param postMethodProxyRequest The {@link PostMethod} that we are configuring to send a standard POST request
* @param httpServletRequest The {@link HttpServletRequest} that contains the POST data to be sent via the {@link PostMethod}
* @throws IOException
*/
private void handleStandard(EntityEnclosingMethod methodProxyRequest,
HttpServletRequest httpServletRequest) throws IOException {
try {
methodProxyRequest.setRequestEntity(new InputStreamRequestEntity(httpServletRequest.getInputStream()));
//LOGGER.info("original request content length:" + httpServletRequest.getContentLength());
//LOGGER.info("proxied request content length:" +methodProxyRequest.getRequestEntity().getContentLength()+"");
} catch (IOException e) {
throw new IOException(e);
}
}
示例13: recordEntity
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
private void recordEntity(HttpMethod httpMethod, Trace trace) {
if (httpMethod instanceof EntityEnclosingMethod) {
final EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) httpMethod;
final RequestEntity entity = entityEnclosingMethod.getRequestEntity();
if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
if (entitySampler.isSampling()) {
try {
String entityValue;
String charSet = entityEnclosingMethod.getRequestCharSet();
if (StringUtils.isEmpty(charSet)) {
charSet = HttpConstants.DEFAULT_CONTENT_CHARSET;
}
if (entity instanceof ByteArrayRequestEntity || entity instanceof StringRequestEntity) {
entityValue = entityUtilsToString(entity, charSet);
} else {
entityValue = entity.getClass() + " (ContentType:" + entity.getContentType() + ")";
}
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, entityValue);
} catch (Exception e) {
logger.debug("HttpEntityEnclosingRequest entity record fail. Caused:{}", e.getMessage(), e);
}
}
}
}
}
示例14: getOutputStream
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
/**
* Gets the output stream.
*
* @return the output stream
* @throws EWSHttpException
* the eWS http exception
*/
@Override
public OutputStream getOutputStream() throws EWSHttpException {
OutputStream os = null;
throwIfConnIsNull();
os = new ByteArrayOutputStream();
((EntityEnclosingMethod) httpMethod).setRequestEntity(new ByteArrayOSRequestEntity(os));
return os;
}
示例15: update
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
/**
* Update entry by posting new representation of entry to server. Note that you should not
* attempt to update entries that you get from iterating over a collection they may be "partial"
* entries. If you want to update an entry, you must get it via one of the
* <code>getEntry()</code> methods in {@link com.rometools.rome.propono.atom.common.Collection}
* or {@link com.rometools.rome.propono.atom.common.AtomService}.
*
* @throws ProponoException If entry is a "partial" entry.
*/
public void update() throws ProponoException {
if (partial) {
throw new ProponoException("ERROR: attempt to update partial entry");
}
final EntityEnclosingMethod method = new PutMethod(getEditURI());
addAuthentication(method);
final StringWriter sw = new StringWriter();
final int code = -1;
try {
Atom10Generator.serializeEntry(this, sw);
method.setRequestEntity(new StringRequestEntity(sw.toString(), null, null));
method.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
getHttpClient().executeMethod(method);
final InputStream is = method.getResponseBodyAsStream();
if (method.getStatusCode() != 200 && method.getStatusCode() != 201) {
throw new ProponoException("ERROR HTTP status=" + method.getStatusCode() + " : " + Utilities.streamToString(is));
}
} catch (final Exception e) {
final String msg = "ERROR: updating entry, HTTP code: " + code;
LOG.debug(msg, e);
throw new ProponoException(msg, e);
} finally {
method.releaseConnection();
}
}