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


Java EntityEnclosingMethod類代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:groupon,項目名稱:odo,代碼行數:26,代碼來源:HttpUtilities.java

示例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);
}
 
開發者ID:lucee,項目名稱:Lucee4,代碼行數:18,代碼來源:HTTPEngine3Impl.java

示例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);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:17,代碼來源:CommonsClientHttpRequest.java

示例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;     
}
 
開發者ID:groovenauts,項目名稱:jmeter_oauth_plugin,代碼行數:24,代碼來源:OAuthSampler.java

示例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;     
}
 
開發者ID:aoprisan,項目名稱:net.oauth,代碼行數:26,代碼來源:OAuthSampler.java

示例6: clone

import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入依賴的package包/類
/**
* Clones a HttpMethod. &ltbr>
* &ltb&gtAttention:</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;
}
 
開發者ID:lucee,項目名稱:Lucee4,代碼行數:44,代碼來源:HttpMethodCloner.java

示例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;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:8,代碼來源:HttpMethodAdapter.java

示例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...");
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:19,代碼來源:AuthenticatedHttp.java

示例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);
        }
    }
}
 
開發者ID:sagiegurari,項目名稱:fax4j,代碼行數:41,代碼來源:ApacheHTTPClient.java

示例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);
		}
}
 
開發者ID:lucee,項目名稱:Lucee4,代碼行數:9,代碼來源:HTTPEngine3Impl.java

示例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);
                }
            }
        }
    }
    
}
 
開發者ID:masonmei,項目名稱:apm-agent,代碼行數:32,代碼來源:ExecuteInterceptor.java

示例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);
}
}
 
開發者ID:geosolutions-it,項目名稱:OpenSDI-Manager2,代碼行數:22,代碼來源:ProxyServiceImpl.java

示例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);
                }
            }
        }
    }
}
 
開發者ID:naver,項目名稱:pinpoint,代碼行數:31,代碼來源:HttpMethodBaseExecuteMethodInterceptor.java

示例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;
}
 
開發者ID:sheymans,項目名稱:todopl,代碼行數:17,代碼來源:HttpClientWebRequest.java

示例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();
    }
}
 
開發者ID:rometools,項目名稱:rome,代碼行數:36,代碼來源:ClientEntry.java


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