本文整理匯總了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);
}
}
示例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);
}
示例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...");
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
示例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);
}
}
示例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());
}
示例10: copyEntityEnclosingMethod
import org.apache.commons.httpclient.methods.EntityEnclosingMethod; //導入方法依賴的package包/類
private static void copyEntityEnclosingMethod(EntityEnclosingMethod m, EntityEnclosingMethod copy ) {
copy.setRequestEntity(m.getRequestEntity());
}
示例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);
}
}