List of usage examples for org.apache.commons.httpclient HttpMethod setPath
public abstract void setPath(String paramString);
From source file:lucee.commons.net.http.httpclient3.HttpMethodCloner.java
/** * Clones a HttpMethod. <br>/*from www.j a v a 2s . c o m*/ * <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; }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
/** * FUNKTIONIERT NICHT, HOST WIRD NICHT UEBERNOMMEN * Clones a http method and sets a new url * @param src//from w w w . j a v a 2 s. co m * @param url * @return */ private static HttpMethod clone(HttpMethod src, URL url) { HttpMethod trg = HttpMethodCloner.clone(src); HostConfiguration trgConfig = trg.getHostConfiguration(); trgConfig.setHost(url.getHost(), url.getPort(), url.getProtocol()); trg.setPath(url.getPath()); trg.setQueryString(url.getQuery()); return trg; }
From source file:gov.loc.ndmso.proxyfilter.RequestProxy.java
private static HttpMethod setupProxyRequest(final HttpServletRequest hsRequest, final URL targetUrl) throws IOException { final String methodName = hsRequest.getMethod(); final HttpMethod method; if ("POST".equalsIgnoreCase(methodName)) { PostMethod postMethod = new PostMethod(); InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity( hsRequest.getInputStream()); postMethod.setRequestEntity(inputStreamRequestEntity); method = postMethod;// w w w .ja v a2 s . com } else if ("GET".equalsIgnoreCase(methodName)) { method = new GetMethod(); } else { // log.warn("Unsupported HTTP method requested: " + hsRequest.getMethod()); return null; } method.setFollowRedirects(false); method.setPath(targetUrl.getPath()); method.setQueryString(targetUrl.getQuery()); @SuppressWarnings("unchecked") Enumeration<String> e = hsRequest.getHeaderNames(); if (e != null) { while (e.hasMoreElements()) { String headerName = e.nextElement(); if ("host".equalsIgnoreCase(headerName)) { //the host value is set by the http client continue; } else if ("content-length".equalsIgnoreCase(headerName)) { //the content-length is managed by the http client continue; } else if ("accept-encoding".equalsIgnoreCase(headerName)) { //the accepted encoding should only be those accepted by the http client. //The response stream should (afaik) be deflated. If our http client does not support //gzip then the response can not be unzipped and is delivered wrong. continue; } else if (headerName.toLowerCase().startsWith("cookie")) { //fixme : don't set any cookies in the proxied request, this needs a cleaner solution continue; } @SuppressWarnings("unchecked") Enumeration<String> values = hsRequest.getHeaders(headerName); while (values.hasMoreElements()) { String headerValue = values.nextElement(); // log.info("setting proxy request parameter:" + headerName + ", value: " + headerValue); method.addRequestHeader(headerName, headerValue); } } } // add rs5/tomcat5 request header for ML method.addRequestHeader("X-Via", "tomcat5"); // log.info("proxy query string " + method.getQueryString()); return method; }
From source file:net.sourceforge.jwbf.actions.HttpActionClient.java
/** * //from w ww.j a v a2 s.c o m * @param a * a * @return message, never null * @throws ActionException * on problems with http, cookies and io * @throws ProcessException on inner problems */ public String performAction(ContentProcessable a) throws ActionException, ProcessException { List<HttpMethod> msgs = a.getMessages(); String out = ""; Iterator<HttpMethod> it = msgs.iterator(); while (it.hasNext()) { HttpMethod e = it.next(); if (path.length() > 1) { e.setPath(path + e.getPath()); LOG.debug("path is: " + e.getPath()); } try { if (e instanceof GetMethod) { out = get(e, a); } else { out = post(e, a); } } catch (IOException e1) { throw new ActionException(e1); } } return out; }
From source file:com.datos.vfs.provider.http.HttpFileObject.java
/** * Prepares a HttpMethod object.//from www . j av a 2s .c o m * * @param method The object which gets prepared to access the file object. * @throws FileSystemException if an error occurs. * @throws URIException if path cannot be represented. * @since 2.0 (was package) */ protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException { final String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(this.getUrlCharset()); method.setPath(pathEncoded); method.setFollowRedirects(this.getFollowRedirect()); method.setRequestHeader("User-Agent", this.getUserAgent()); }
From source file:com.datos.vfs.provider.webdav.WebdavFileObject.java
/** * Prepares a Method object.//w w w . j a v a 2 s . c om * * @param method the HttpMethod. * @throws FileSystemException if an error occurs encoding the uri. * @throws URIException if the URI is in error. */ @Override protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException { final String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(this.getUrlCharset()); method.setPath(pathEncoded); method.setFollowRedirects(this.getFollowRedirect()); method.setRequestHeader("User-Agent", "Jakarta-Commons-VFS"); method.addRequestHeader("Cache-control", "no-cache"); method.addRequestHeader("Cache-store", "no-store"); method.addRequestHeader("Pragma", "no-cache"); method.addRequestHeader("Expires", "0"); }
From source file:fr.cls.atoll.motu.library.cas.HttpClientCAS.java
/** * Adds the cas ticket.//from ww w. j a v a2 s. co m * * @param method * the method * @throws IOException * Signals that an I/O exception has occurred. * @throws MotuCasException */ public static void addCASTicket(HttpMethod method) throws IOException, MotuCasException { if (LOG.isDebugEnabled()) { LOG.debug("addCASTicket(HttpMethod) - entering : debugHttpMethod BEFORE " + HttpClientCAS.debugHttpMethod(method)); } if (HttpClientCAS.addCASTicketFromTGT(method)) { return; } if (!AuthenticationHolder.isCASAuthentication()) { if (LOG.isDebugEnabled()) { LOG.debug("addCASTicket(HttpMethod) - exiting - NO CAS AUTHENTICATION : debugHttpMethod AFTER " + HttpClientCAS.debugHttpMethod(method)); } return; } String newURIAsString = AssertionUtils.addCASTicket(method.getURI().getEscapedURI()); if (!AssertionUtils.hasCASTicket(newURIAsString)) { newURIAsString = AssertionUtils.addCASTicket(method.getURI().getEscapedURI(), AuthenticationHolder.getUser()); if (!AssertionUtils.hasCASTicket(newURIAsString)) { String login = AuthenticationHolder.getUserLogin(); throw new MotuCasException(String.format( "Unable to access resource '%s'. This resource has been declared as CASified, but the Motu application/API can't retrieve any ticket from CAS via REST. \nFor information, current user login is:'%s'", method.getURI().getEscapedURI(), login)); } } URI newURI = new URI(newURIAsString, true); // method.setURI(newURI); method.setPath(newURI.getPath()); method.setQueryString(newURI.getQuery()); // System.out.println(newURI.getPathQuery()); if (LOG.isDebugEnabled()) { LOG.debug("addCASTicket(HttpMethod) - exiting : debugHttpMethod AFTER " + HttpClientCAS.debugHttpMethod(method)); } }
From source file:fr.cls.atoll.motu.library.cas.HttpClientCAS.java
/** * Adds the cas ticket from tgt.//from ww w . j ava2 s.c o m * * @param method the method * @return true, if successful * @throws MotuCasException the motu cas exception * @throws URIException the uRI exception * @throws IOException Signals that an I/O exception has occurred. */ public static boolean addCASTicketFromTGT(HttpMethod method) throws MotuCasException, URIException, IOException { if (LOG.isDebugEnabled()) { LOG.debug("addCASTicketFromTGT(HttpMethod) - entering : debugHttpMethod BEFORE " + HttpClientCAS.debugHttpMethod(method)); } Header headerTgt = method.getRequestHeader(HttpClientCAS.TGT_PARAM); Header headerCasRestUrl = method.getRequestHeader(HttpClientCAS.CAS_REST_URL_PARAM); if ((headerTgt == null) || (headerCasRestUrl == null)) { return false; } String ticketGrantingTicket = headerTgt.getValue(); String casRestUrl = headerCasRestUrl.getValue(); if ((RestUtil.isNullOrEmpty(ticketGrantingTicket)) || (RestUtil.isNullOrEmpty(casRestUrl))) { return false; } String ticket = RestUtil.loginToCASWithTGT(casRestUrl, ticketGrantingTicket, method.getURI().getEscapedURI()); String newURIAsString = AssertionUtils.addCASTicket(ticket, method.getURI().getEscapedURI()); if (!AssertionUtils.hasCASTicket(newURIAsString)) { throw new MotuCasException(String.format( "Unable to access resource '%s'. This resource has been declared as CASified, but the Motu application/API can't retrieve any ticket from CAS via REST. \nFor information, current TGT is:'%s', CAS REST url is:'%s'", method.getURI().getEscapedURI(), ticketGrantingTicket, casRestUrl)); } URI newURI = new URI(newURIAsString, true); // method.setURI(newURI); method.setPath(newURI.getPath()); method.setQueryString(newURI.getQuery()); // System.out.println(newURI.getPathQuery()); if (LOG.isDebugEnabled()) { LOG.debug("addCASTicketFromTGT(HttpMethod) - exiting : debugHttpMethod AFTER " + HttpClientCAS.debugHttpMethod(method)); } return true; }
From source file:org.alfresco.repo.transfer.HttpClientTransmitterImpl.java
public void verifyTarget(TransferTarget target) throws TransferException { HttpMethod verifyRequest = getPostMethod(); try {/*ww w . j a v a2 s . c om*/ HostConfiguration hostConfig = getHostConfig(target); HttpState httpState = getHttpState(target); verifyRequest.setPath(target.getEndpointPath() + "/test"); try { int response = httpClient.executeMethod(hostConfig, verifyRequest, httpState); checkResponseStatus("verifyTarget", response, verifyRequest); } catch (RuntimeException e) { throw e; } catch (Exception e) { String error = "Failed to execute HTTP request to target"; log.debug(error, e); throw new TransferException(MSG_HTTP_REQUEST_FAILED, new Object[] { "verifyTraget", target.toString(), e.toString() }, e); } } finally { verifyRequest.releaseConnection(); } }
From source file:org.alfresco.repo.transfer.HttpClientTransmitterImpl.java
public void abort(Transfer transfer) throws TransferException { TransferTarget target = transfer.getTransferTarget(); HttpMethod abortRequest = getPostMethod(); try {/*from ww w . j a v a2 s.c o m*/ HostConfiguration hostConfig = getHostConfig(target); HttpState httpState = getHttpState(target); abortRequest.setPath(target.getEndpointPath() + "/abort"); //Put the transferId on the query string abortRequest.setQueryString( new NameValuePair[] { new NameValuePair("transferId", transfer.getTransferId()) }); try { int responseStatus = httpClient.executeMethod(hostConfig, abortRequest, httpState); checkResponseStatus("abort", responseStatus, abortRequest); //If we get here then we've received a 200 response //We're expecting the transfer id encoded in a JSON object... } catch (RuntimeException e) { throw e; } catch (Exception e) { String error = "Failed to execute HTTP request to target"; log.debug(error, e); throw new TransferException(MSG_HTTP_REQUEST_FAILED, new Object[] { "abort", target.toString(), e.toString() }, e); } } finally { abortRequest.releaseConnection(); } }