List of usage examples for org.apache.commons.httpclient HttpMethod getURI
public abstract URI getURI() throws URIException;
From source file:com.comcast.cats.service.util.HttpClientUtil.java
public static synchronized Object deleteForObject(String uri, Map<String, String> paramMap) { Object responseObject = new Object(); HttpMethod httpMethod = new DeleteMethod(uri); if ((null != paramMap) && (!paramMap.isEmpty())) { httpMethod.setQueryString(getNameValuePair(paramMap)); }//from ww w . j a va2s . c o m Yaml yaml = new Yaml(); HttpClient client = new HttpClient(); InputStream responseStream = null; Reader inputStreamReader = null; try { int responseCode = client.executeMethod(httpMethod); if (HttpStatus.SC_OK != responseCode) { logger.error("[ REQUEST ] " + httpMethod.getURI().toString()); logger.error("[ METHOD ] " + httpMethod.getName()); logger.error("[ STATUS ] " + responseCode); } else { logger.trace("[ REQUEST ] " + httpMethod.getURI().toString()); logger.trace("[ METHOD ] " + httpMethod.getName()); logger.trace("[ STATUS ] " + responseCode); } responseStream = httpMethod.getResponseBodyAsStream(); inputStreamReader = new InputStreamReader(responseStream, VideoRecorderServiceConstants.UTF); responseObject = yaml.load(inputStreamReader); } catch (IOException ioException) { ioException.printStackTrace(); } finally { cleanUp(inputStreamReader, responseStream, httpMethod); } return responseObject; }
From source file:davmail.http.DavGatewayHttpClientFacade.java
/** * Execute method with httpClient, follow 30x redirects. * * @param httpClient Http client instance * @param method Http method// w ww .ja v a 2 s . c o m * @return last http method after redirects * @throws IOException on error */ public static HttpMethod executeFollowRedirects(HttpClient httpClient, HttpMethod method) throws IOException { HttpMethod currentMethod = method; try { DavGatewayTray.debug(new BundleMessage("LOG_EXECUTE_FOLLOW_REDIRECTS", currentMethod.getURI())); httpClient.executeMethod(currentMethod); checkNTLM(httpClient, currentMethod); String locationValue = getLocationValue(currentMethod); // check javascript redirect (multiple authentication pages) if (locationValue == null) { locationValue = getJavascriptRedirectUrl(currentMethod); } int redirectCount = 0; while (redirectCount++ < 10 && locationValue != null) { currentMethod.releaseConnection(); currentMethod = new GetMethod(locationValue); currentMethod.setFollowRedirects(false); DavGatewayTray.debug(new BundleMessage("LOG_EXECUTE_FOLLOW_REDIRECTS_COUNT", currentMethod.getURI(), redirectCount)); httpClient.executeMethod(currentMethod); checkNTLM(httpClient, currentMethod); locationValue = getLocationValue(currentMethod); } if (locationValue != null) { currentMethod.releaseConnection(); throw new HttpException("Maximum redirections reached"); } } catch (IOException e) { currentMethod.releaseConnection(); throw e; } // caller will need to release connection return currentMethod; }
From source file:fr.cls.atoll.motu.library.cas.HttpClientCAS.java
public static String debugHttpMethod(HttpMethod method) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("\nName:"); stringBuffer.append(method.getName()); stringBuffer.append("\n"); stringBuffer.append("\nPath:"); stringBuffer.append(method.getPath()); stringBuffer.append("\n"); stringBuffer.append("\nQueryString:"); stringBuffer.append(method.getQueryString()); stringBuffer.append("\n"); stringBuffer.append("\nUri:"); try {/*from w w w.ja v a 2s . com*/ stringBuffer.append(method.getURI().toString()); } catch (URIException e) { // Do nothing } stringBuffer.append("\n"); HttpMethodParams httpMethodParams = method.getParams(); stringBuffer.append("\nHttpMethodParams:"); stringBuffer.append(httpMethodParams.toString()); return stringBuffer.toString(); }
From source file:davmail.http.DavGatewayHttpClientFacade.java
/** * Build Http Exception from methode status * * @param method Http Method/*from w w w . jav a2 s . co m*/ * @return Http Exception */ public static HttpException buildHttpException(HttpMethod method) { int status = method.getStatusCode(); StringBuilder message = new StringBuilder(); message.append(status).append(' ').append(method.getStatusText()); try { message.append(" at ").append(method.getURI().getURI()); if (method instanceof CopyMethod || method instanceof MoveMethod) { message.append(" to ").append(method.getRequestHeader("Destination")); } } catch (URIException e) { message.append(method.getPath()); } // 440 means forbidden on Exchange if (status == 440) { return new LoginTimeoutException(message.toString()); } else if (status == HttpStatus.SC_FORBIDDEN) { return new HttpForbiddenException(message.toString()); } else if (status == HttpStatus.SC_NOT_FOUND) { return new HttpNotFoundException(message.toString()); } else if (status == HttpStatus.SC_PRECONDITION_FAILED) { return new HttpPreconditionFailedException(message.toString()); } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) { return new HttpServerErrorException(message.toString()); } else { return new HttpException(message.toString()); } }
From source file:edu.umd.cs.buildServer.BuildServer.java
/** * Write a URI of an HttpMethod to the Log. * * @param log/* ww w .j av a 2s.co m*/ * the Log * @param method * the HttpMethod */ public static void printURI(Logger log, HttpMethod method) { try { log.trace("URI=" + method.getURI()); } catch (URIException e) { log.error("Could not print URI for HttpMethod", e); } }
From source file:net.oauth.client.HttpMethodResponse.java
/** * Construct an OAuthMessage from the HTTP response, including parameters * from OAuth WWW-Authenticate headers and the body. The header parameters * come first, followed by the ones from the response body. *///from w w w . ja va2s . com public HttpMethodResponse(HttpMethod method) throws IOException { super(method.getName(), method.getURI().toString(), NO_PARAMETERS); this.method = method; try { addParameters(getResponseParameters()); } catch (Exception ignored) { } }
From source file:davmail.http.DavGatewayHttpClientFacade.java
private static int checkNTLM(HttpClient httpClient, HttpMethod currentMethod) throws IOException { int status = currentMethod.getStatusCode(); if ((status == HttpStatus.SC_UNAUTHORIZED || status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) && acceptsNTLMOnly(currentMethod) && !hasNTLM(httpClient)) { LOGGER.debug(/*from www . j a v a2s. c o m*/ "Received " + status + " unauthorized at " + currentMethod.getURI() + ", retrying with NTLM"); resetMethod(currentMethod); addNTLM(httpClient); status = httpClient.executeMethod(currentMethod); } return status; }
From source file:fr.cls.atoll.motu.library.cas.HttpClientCAS.java
/** * Adds the cas ticket.//w w w. j a v a2 s . com * * @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:com.google.jstestdriver.server.gateway.GatewayMethodTest.java
public void testGetNameAndGetUri() throws Exception { HttpMethod method = new GatewayMethod("GET", "http://www.google.com/search"); assertEquals("GET", method.getName()); assertEquals("http://www.google.com/search", method.getURI().toString()); }
From source file:davmail.http.DavGatewayHttpClientFacade.java
/** * Execute method with httpClient, do not follow 30x redirects. * * @param httpClient Http client instance * @param method Http method//ww w . j a v a 2s . c o m * @return status * @throws IOException on error */ public static int executeNoRedirect(HttpClient httpClient, HttpMethod method) throws IOException { int status; try { status = httpClient.executeMethod(method); // check NTLM if ((status == HttpStatus.SC_UNAUTHORIZED || status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) && acceptsNTLMOnly(method) && !hasNTLM(httpClient)) { LOGGER.debug("Received " + status + " unauthorized at " + method.getURI() + ", retrying with NTLM"); resetMethod(method); addNTLM(httpClient); status = httpClient.executeMethod(method); } } finally { method.releaseConnection(); } // caller will need to release connection return status; }