List of usage examples for org.apache.commons.httpclient.methods PutMethod setFollowRedirects
public void setFollowRedirects(boolean paramBoolean)
From source file:com.sun.faban.driver.transport.hc3.ApacheHC3Transport.java
/** * Makes a PUT request to the URL. Reads data back and returns the data * read. Note that this method only works with text data as it does the * byte-to-char conversion. This method will return null for responses * with binary MIME types. The addTextType(String) method is used to * register additional MIME types as text types. Use getContentSize() to * obtain the bytes of binary data read. * * @param url The URL to read from/*from www .j a va 2 s . c om*/ * @param buffer containing the PUT data * @param contentType the content type, or null * @param headers The request headers, or null * @return The StringBuilder buffer containing the resulting document * @throws java.io.IOException */ public StringBuilder putURL(String url, byte[] buffer, String contentType, Map<String, String> headers) throws IOException { PutMethod method = new PutMethod(url); method.setFollowRedirects(followRedirects); setHeaders(method, headers); method.setRequestEntity(new ByteArrayRequestEntity(buffer, contentType)); try { responseCode = hc.executeMethod(method); buildResponseHeaders(method); return fetchResponse(method); } finally { method.releaseConnection(); } }
From source file:dk.clarin.tools.create.java
private Document putToPDP(String request) { //logger.debug("PDP request: " + request); // for downloading... org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient(); org.apache.commons.httpclient.methods.PutMethod method; httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(500000); method = new org.apache.commons.httpclient.methods.PutMethod(ToolsProperties.coreServer + "/aa/pdp"); try {/*from w w w. ja v a2s .c o m*/ method.setRequestEntity(new org.apache.commons.httpclient.methods.StringRequestEntity(request, "application/xml", "UTF-8")); //if (userHandle != null && userHandle.trim().length() > 0) method.setRequestHeader("Cookie", "escidocCookie=" + ToolsProperties.adminUserHandle /*userHandle*/); method.setFollowRedirects(false); // Download the item httpClient.executeMethod(method); if (method.getStatusCode() != 200) { if (method.getStatusCode() == 302) { logger.error("The userhandle has expired!"); return null; } else { logger.warn("Unknown error while trying to use the PDP! Request: " + request + "\nResponse: " + method.getResponseBodyAsString()); return null; } } //logger.debug("PDP responce: " + method.getResponseBodyAsString() ); InputStream in = method.getResponseBodyAsStream(); Document ret = streamToXml(in); return ret; } catch (UnsupportedEncodingException e) { logger.error("An error occured while using the PDP! " + e.getMessage()); return null; } catch (Exception e) { logger.error("An error occured while using the PDP!"); return null; } finally { method.releaseConnection(); } }
From source file:org.apache.maven.wagon.providers.webdav.CorrectedWebdavResource.java
/** * Execute the PUT method for the given path. * * @param path the server relative path to put the data * @param inputStream The input stream./*from w w w . j a va2 s.c om*/ * * @return true if the method is succeeded. */ public boolean putMethod(String path, InputStream inputStream, int contentLength) throws IOException { setClient(); PutMethod method = new PutMethod(URIUtil.encodePathQuery(path)); method.setFollowRedirects(super.followRedirects); generateIfHeader(method); if (getGetContentType() != null && !getGetContentType().equals("")) { method.setRequestHeader("Content-Type", getGetContentType()); } method.setRequestContentLength(contentLength); method.setRequestBody(inputStream); generateTransactionHeader(method); generateAdditionalHeaders(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return isHttpSuccess(statusCode); }
From source file:org.apache.webdav.ant.Utils.java
public static void putFile(HttpClient client, HttpURL url, InputStream is, String contentType, String lockToken) throws IOException, HttpException { PutMethod put = new PutMethod(url.getEscapedURI()); generateIfHeader(put, lockToken);//from w w w . j a v a2 s . c o m put.setRequestHeader("Content-Type", contentType); put.setRequestBody(is); put.setFollowRedirects(true); int status = client.executeMethod(put); switch (status) { case WebdavStatus.SC_OK: case WebdavStatus.SC_CREATED: case WebdavStatus.SC_NO_CONTENT: return; default: HttpException ex = new HttpException(); ex.setReason(put.getStatusText()); ex.setReasonCode(status); throw ex; } }
From source file:org.bibsonomy.rest.client.worker.impl.PutWorker.java
@Override protected PutMethod getMethod(String url, String requestBody) { final PutMethod put = new PutMethod(url); put.setFollowRedirects(false); // TODO: remove deprecated method put.setRequestEntity(new StringRequestEntity(requestBody)); return put;//from w w w . j av a 2s . c om }
From source file:org.eclipse.mylyn.internal.oslc.core.client.AbstractOslcClient.java
protected PutMethod createPutMethod(String requestPath) { PutMethod method = new PutMethod(getRequestPath(requestPath)); method.setFollowRedirects(false); method.setDoAuthentication(true);/*from w w w . j a v a 2s .com*/ return method; }