List of usage examples for org.apache.commons.httpclient HttpHost HttpHost
public HttpHost(URI paramURI) throws URIException
From source file:com.orange.mmp.net.http.HttpConnection.java
/** * Inner method used to execute request//from www. j a va 2 s. co m * * @param dataStream The data stream to send in request (null for GET only) * @throws MMPNetException */ @SuppressWarnings("unchecked") protected void doExecute(InputStream dataStream) throws MMPNetException { try { this.currentHttpClient = HttpConnectionManager.httpClientPool.take(); } catch (InterruptedException ie) { throw new MMPNetException("Corrupted HTTP client pool", ie); } if (this.httpConnectionProperties.containsKey(HttpConnectionParameters.PARAM_IN_CREDENTIALS_USER)) { this.currentHttpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials( (String) this.httpConnectionProperties.get(HttpConnectionParameters.PARAM_IN_CREDENTIALS_USER), (String) this.httpConnectionProperties .get(HttpConnectionParameters.PARAM_IN_CREDENTIALS_PASSWORD))); this.currentHttpClient.getParams().setAuthenticationPreemptive(true); } // Config HostConfiguration config = new HostConfiguration(); if (this.timeout > 0) this.currentHttpClient.getParams().setParameter(HttpConnectionParameters.PARAM_IN_HTTP_SOCKET_TIMEOUT, this.timeout); if (HttpConnectionManager.proxyHost != null && (this.httpConnectionProperties.get(HttpConnectionParameters.PARAM_IN_HTTP_USE_PROXY) != null && this.httpConnectionProperties.get(HttpConnectionParameters.PARAM_IN_HTTP_USE_PROXY) .toString().equals("true")) || (this.httpConnectionProperties.get(HttpConnectionParameters.PARAM_IN_HTTP_USE_PROXY) == null && this.useProxy)) { config.setProxy(HttpConnectionManager.proxyHost, HttpConnectionManager.proxyPort); } else { config.setProxyHost(null); } this.currentHttpClient.setHostConfiguration(config); this.currentHttpClient.getHostConfiguration().setHost(new HttpHost(this.endPointUrl.getHost())); String methodStr = (String) this.httpConnectionProperties .get(HttpConnectionParameters.PARAM_IN_HTTP_METHOD); if (methodStr == null || methodStr.equals(HttpConnectionParameters.HTTP_METHOD_GET)) { this.method = new GetMethod(endPointUrl.toString().replace(" ", "+")); } else if (methodStr.equals(HttpConnectionParameters.HTTP_METHOD_POST)) { this.method = new PostMethod((this.endPointUrl.getQuery() == null) ? this.endPointUrl.getPath() : this.endPointUrl.getPath() + "?" + endPointUrl.getQuery()); if (dataStream != null) { InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity(dataStream); ((PostMethod) this.method).setRequestEntity(inputStreamRequestEntity); } } else if (methodStr.equals(HttpConnectionParameters.HTTP_METHOD_PUT)) { this.method = new PutMethod((this.endPointUrl.getQuery() == null) ? this.endPointUrl.getPath() : this.endPointUrl.getPath() + "?" + endPointUrl.getQuery()); if (dataStream != null) { InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity(dataStream); ((PutMethod) this.method).setRequestEntity(inputStreamRequestEntity); } } else if (methodStr.equals(HttpConnectionParameters.HTTP_METHOD_DEL)) { this.method = new DeleteMethod((this.endPointUrl.getQuery() == null) ? this.endPointUrl.getPath() : this.endPointUrl.getPath() + "?" + endPointUrl.getQuery()); } else throw new MMPNetException("HTTP method not supported"); //Add headers if (this.httpConnectionProperties != null) { for (Object headerName : this.httpConnectionProperties.keySet()) { if (!((String) headerName).startsWith("http.")) { this.method.addRequestHeader((String) headerName, this.httpConnectionProperties.get(headerName).toString()); } } } // Set Connection/Proxy-Connection close to avoid TIME_WAIT sockets this.method.addRequestHeader("Connection", "close"); this.method.addRequestHeader("Proxy-Connection", "close"); try { int httpCode = this.currentHttpClient.executeMethod(config, method); this.currentStatusCode = httpCode; for (org.apache.commons.httpclient.Header responseHeader : method.getResponseHeaders()) { this.httpConnectionProperties.put(responseHeader.getName(), responseHeader.getValue()); } if (this.currentStatusCode >= 400) { throw new MMPNetException("HTTP " + this.currentStatusCode + " on '" + endPointUrl + "'"); } else { this.inDataStream = this.method.getResponseBodyAsStream(); } } catch (IOException ioe) { throw new MMPNetException("I/O error on " + this.endPointUrl + " : " + ioe.getMessage()); } catch (Exception e) { e.printStackTrace(); } }
From source file:pt.webdetails.browserid.spring.BrowserIdProcessingFilter.java
@Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); //request parameters Assert.hasLength(getAssertionParameterName(), "assertionParameterName cannot be empty."); // Assert.hasLength(getAudienceParameterName(), "audienceParameterName cannot be empty."); //check URL//from w w w .ja va2s. c o m Assert.hasLength(getVerificationServiceUrl()); try { HttpHost host = new HttpHost(new URI(getVerificationServiceUrl(), false)); Assert.isTrue(host.getProtocol().isSecure(), "verificationServiceUrl does not use a secure protocol"); } catch (URIException e) { throw new IllegalArgumentException("verificationServiceUrl is not a valid URI", e); } }
From source file:smartrics.rest.fitnesse.fixture.support.http.URIBuilder.java
@SuppressWarnings("deprecation") public void setURI(org.apache.commons.httpclient.HttpMethodBase m, URI uri) throws URIException { HostConfiguration conf = m.getHostConfiguration(); if (uri.isAbsoluteURI()) { conf.setHost(new HttpHost(uri)); m.setHostConfiguration(conf);//from w ww .ja v a 2 s. co m } m.setPath(uri.getPath() != null ? uri.getEscapedPath() : "/"); m.setQueryString(uri.getQuery()); }