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


Java EntityEnclosingMethod.setRequestEntity方法代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.methods.EntityEnclosingMethod.setRequestEntity方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityEnclosingMethod.setRequestEntity方法的具體用法?Java EntityEnclosingMethod.setRequestEntity怎麽用?Java EntityEnclosingMethod.setRequestEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.httpclient.methods.EntityEnclosingMethod的用法示例。


在下文中一共展示了EntityEnclosingMethod.setRequestEntity方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: addToCollection

import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入方法依賴的package包/類
void addToCollection(final ClientCollection col) throws ProponoException {
    setCollection(col);
    final EntityEnclosingMethod method = new PostMethod(getCollection().getHrefResolved());
    addAuthentication(method);
    final StringWriter sw = new StringWriter();
    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();
        code = method.getStatusCode();
        if (code != 200 && code != 201) {
            throw new ProponoException("ERROR HTTP status=" + code + " : " + Utilities.streamToString(is));
        }
        final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(is), getCollection().getHrefResolved(), Locale.US);
        BeanUtils.copyProperties(this, romeEntry);

    } catch (final Exception e) {
        final String msg = "ERROR: saving entry, HTTP code: " + code;
        LOG.debug(msg, e);
        throw new ProponoException(msg, e);
    } finally {
        method.releaseConnection();
    }
    final Header locationHeader = method.getResponseHeader("Location");
    if (locationHeader == null) {
        LOG.warn("WARNING added entry, but no location header returned");
    } else if (getEditURI() == null) {
        final List<Link> links = getOtherLinks();
        final Link link = new Link();
        link.setHref(locationHeader.getValue());
        link.setRel("edit");
        links.add(link);
        setOtherLinks(links);
    }
}
 
開發者ID:rometools,項目名稱:rome,代碼行數:39,代碼來源:ClientEntry.java

示例9: copyEntityEnclosingMethod

import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入方法依賴的package包/類
private static void copyEntityEnclosingMethod(
 EntityEnclosingMethod m, EntityEnclosingMethod copy )
   throws java.io.IOException
{
    copy.setRequestEntity(m.getRequestEntity());
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:7,代碼來源:HttpMethodCloner.java

示例10: copyEntityEnclosingMethod

import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入方法依賴的package包/類
private static void copyEntityEnclosingMethod(EntityEnclosingMethod m, EntityEnclosingMethod copy ) {
 copy.setRequestEntity(m.getRequestEntity());
}
 
開發者ID:lucee,項目名稱:Lucee4,代碼行數:4,代碼來源:HttpMethodCloner.java

示例11: addToCollection

import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入方法依賴的package包/類
/** Package access, to be called by DefaultClientCollection */
@Override
void addToCollection(final ClientCollection col) throws ProponoException {
    setCollection(col);
    final EntityEnclosingMethod method = new PostMethod(col.getHrefResolved());
    getCollection().addAuthentication(method);
    try {
        final Content c = getContents().get(0);
        if (inputStream != null) {
            method.setRequestEntity(new InputStreamRequestEntity(inputStream));
        } else {
            method.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(getBytes())));
        }
        method.setRequestHeader("Content-type", c.getType());
        method.setRequestHeader("Title", getTitle());
        method.setRequestHeader("Slug", getSlug());
        getCollection().getHttpClient().executeMethod(method);
        if (inputStream != null) {
            inputStream.close();
        }
        final InputStream is = method.getResponseBodyAsStream();
        if (method.getStatusCode() == 200 || method.getStatusCode() == 201) {
            final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(is), col.getHrefResolved(), Locale.US);
            BeanUtils.copyProperties(this, romeEntry);

        } else {
            throw new ProponoException("ERROR HTTP status-code=" + method.getStatusCode() + " status-line: " + method.getStatusLine());
        }
    } catch (final IOException ie) {
        throw new ProponoException("ERROR: saving media entry", ie);
    } catch (final JDOMException je) {
        throw new ProponoException("ERROR: saving media entry", je);
    } catch (final FeedException fe) {
        throw new ProponoException("ERROR: saving media entry", fe);
    } catch (final IllegalAccessException ae) {
        throw new ProponoException("ERROR: saving media entry", ae);
    } catch (final InvocationTargetException te) {
        throw new ProponoException("ERROR: saving media entry", te);
    }
    final Header locationHeader = method.getResponseHeader("Location");
    if (locationHeader == null) {
        LOG.warn("WARNING added entry, but no location header returned");
    } else if (getEditURI() == null) {
        final List<Link> links = getOtherLinks();
        final Link link = new Link();
        link.setHref(locationHeader.getValue());
        link.setRel("edit");
        links.add(link);
        setOtherLinks(links);
    }
}
 
開發者ID:rometools,項目名稱:rome,代碼行數:52,代碼來源:ClientMediaEntry.java


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