List of usage examples for org.apache.commons.httpclient HttpVersion HTTP_1_1
HttpVersion HTTP_1_1
To view the source code for org.apache.commons.httpclient HttpVersion HTTP_1_1.
Click Source Link
From source file:org.opensaml.ws.soap.client.HTTPSOAPTransportFactory.java
/** * Initializes the {@link HttpClient} that will be used by the created {@link HTTPSOAPTransport} built by this * factory./*from w w w. ja v a2 s . c o m*/ */ protected void initializeHttpClient() { HttpConnectionManagerParams connectionParams = new HttpConnectionManagerParams(); connectionParams.setConnectionTimeout(connectionTimeout); MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(connectionParams); HttpClientParams clientParams = new HttpClientParams(); clientParams.setSoTimeout(socketTimeout); if (httpVersion == HTTP_VERSION.HTTP1_0) { clientParams.setVersion(HttpVersion.HTTP_1_0); } else { clientParams.setVersion(HttpVersion.HTTP_1_1); } httpClient = new HttpClient(clientParams, connectionManager); }
From source file:org.opensaml.ws.transport.http.HttpClientOutTransport.java
public void setVersion(HTTP_VERSION http_version) { HttpParams params = postMethod.getParams(); switch (http_version) { case HTTP1_0: params.setParameter("http.protocol.version", HttpVersion.HTTP_1_0); break;/*w w w. java 2 s. c o m*/ case HTTP1_1: params.setParameter("http.protocol.version", HttpVersion.HTTP_1_1); break; } }
From source file:org.opensaml.ws.transport.http.HttpClientOutTransport.java
public HTTP_VERSION getVersion() { HttpVersion httpVersion = (HttpVersion) postMethod.getParams().getParameter("http.protocol.version"); if (httpVersion == HttpVersion.HTTP_1_1) { return HTTP_VERSION.HTTP1_1; }/*from w ww. j a v a 2s. co m*/ return HTTP_VERSION.HTTP1_0; }
From source file:org.parosproxy.paros.network.HttpMethodHelper.java
public HttpMethod createRequestMethodNew(HttpRequestHeader header, HttpBody body) throws URIException { HttpMethod httpMethod = null;/*from ww w . j a v a 2 s. co m*/ String method = header.getMethod(); URI uri = header.getURI(); String version = header.getVersion(); httpMethod = new GenericMethod(method); httpMethod.setURI(uri); HttpMethodParams httpParams = httpMethod.getParams(); // default to use HTTP 1.0 httpParams.setVersion(HttpVersion.HTTP_1_0); if (version.equalsIgnoreCase(HttpHeader.HTTP11)) { httpParams.setVersion(HttpVersion.HTTP_1_1); } // set various headers int pos = 0; // ZAP: FindBugs fix - always initialise pattern Pattern pattern = patternCRLF; String delimiter = CRLF; String msg = header.getHeadersAsString(); if ((pos = msg.indexOf(CRLF)) < 0) { if ((pos = msg.indexOf(LF)) < 0) { delimiter = LF; pattern = patternLF; } } else { delimiter = CRLF; pattern = patternCRLF; } String[] split = pattern.split(msg); String token = null; String name = null; String value = null; //String host = null; for (int i = 0; i < split.length; i++) { token = split[i]; if (token.equals("")) { continue; } if ((pos = token.indexOf(":")) < 0) { return null; } name = token.substring(0, pos).trim(); value = token.substring(pos + 1).trim(); httpMethod.addRequestHeader(name, value); } // set body if post method or put method if (body != null && body.length() > 0) { EntityEnclosingMethod generic = (EntityEnclosingMethod) httpMethod; // generic.setRequestEntity(new StringRequestEntity(body.toString())); generic.setRequestEntity(new ByteArrayRequestEntity(body.getBytes())); } httpMethod.setFollowRedirects(false); return httpMethod; }
From source file:org.parosproxy.paros.network.HttpMethodHelper.java
public HttpMethod createRequestMethod(HttpRequestHeader header, HttpBody body) throws URIException { HttpMethod httpMethod = null;/*from ww w. j a va 2s. c o m*/ String method = header.getMethod(); URI uri = header.getURI(); String version = header.getVersion(); if (method == null || method.trim().length() < 3) { throw new URIException("Invalid HTTP method: " + method); } if (method.equalsIgnoreCase(GET)) { //httpMethod = new GetMethod(); // ZAP: avoid discarding HTTP status code 101 that is used for WebSocket upgrade httpMethod = new ZapGetMethod(); } else if (method.equalsIgnoreCase(POST)) { httpMethod = new ZapPostMethod(); } else if (method.equalsIgnoreCase(DELETE)) { httpMethod = new ZapDeleteMethod(); } else if (method.equalsIgnoreCase(PUT)) { httpMethod = new ZapPutMethod(); } else if (method.equalsIgnoreCase(HEAD)) { httpMethod = new ZapHeadMethod(); } else if (method.equalsIgnoreCase(OPTIONS)) { httpMethod = new ZapOptionsMethod(); } else if (method.equalsIgnoreCase(TRACE)) { httpMethod = new ZapTraceMethod(uri.toString()); } else { httpMethod = new GenericMethod(method); } try { httpMethod.setURI(uri); } catch (Exception e1) { logger.error(e1.getMessage(), e1); } HttpMethodParams httpParams = httpMethod.getParams(); // default to use HTTP 1.0 httpParams.setVersion(HttpVersion.HTTP_1_0); if (version.equalsIgnoreCase(HttpHeader.HTTP11)) { httpParams.setVersion(HttpVersion.HTTP_1_1); } // set various headers int pos = 0; // ZAP: changed to always use CRLF, like the HttpHeader Pattern pattern = patternCRLF; String delimiter = header.getLineDelimiter(); // ZAP: Shouldn't happen as the HttpHeader always uses CRLF if (delimiter.equals(LF)) { delimiter = LF; pattern = patternLF; } String msg = header.getHeadersAsString(); String[] split = pattern.split(msg); String token = null; String name = null; String value = null; for (int i = 0; i < split.length; i++) { token = split[i]; if (token.equals("")) { continue; } if ((pos = token.indexOf(":")) < 0) { return null; } name = token.substring(0, pos).trim(); value = token.substring(pos + 1).trim(); httpMethod.addRequestHeader(name, value); } // set body if post method or put method if (body != null && body.length() > 0 && (httpMethod instanceof EntityEnclosingMethod)) { EntityEnclosingMethod post = (EntityEnclosingMethod) httpMethod; // post.setRequestEntity(new StringRequestEntity(body.toString())); post.setRequestEntity(new ByteArrayRequestEntity(body.getBytes())); } httpMethod.setFollowRedirects(false); return httpMethod; }
From source file:org.red5.server.net.rtmpt.RTMPTClientConnector.java
public RTMPTClientConnector(String server, int port, RTMPTClient client) { httpClient.getHostConfiguration().setHost(server, port); httpClient.getHttpConnectionManager().closeIdleConnections(0); HttpClientParams params = new HttpClientParams(); params.setVersion(HttpVersion.HTTP_1_1); httpClient.setParams(params);// www . jav a 2s. com // establish a connection within x seconds - this will prevent hung // sockets httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout); this.client = client; this.connManager = client.getConnManager(); }
From source file:org.wso2.carbon.esb.proxyservice.test.proxyservices.ESBJAVA4846HttpProtocolVersionTestCase.java
@Test(groups = "wso2.esb", description = "Sending HTTP1.1 message") public void sendingHTTP11Message() throws Exception { PostMethod post = new PostMethod(getProxyServiceURLHttp("StockQuoteProxyTestHTTPVersion")); RequestEntity entity = new StringRequestEntity(getPayload(), "text/xml", "UTF-8"); post.setRequestEntity(entity);/* w w w .j a v a 2s .c o m*/ post.setRequestHeader("SOAPAction", "urn:getQuote"); HttpMethodParams params = new HttpMethodParams(); params.setVersion(HttpVersion.HTTP_1_1); post.setParams(params); HttpClient httpClient = new HttpClient(); String httpVersion = ""; try { httpClient.executeMethod(post); post.getResponseBodyAsString(); httpVersion = post.getStatusLine().getHttpVersion(); } finally { post.releaseConnection(); } Assert.assertEquals(httpVersion, HttpVersion.HTTP_1_1.toString(), "Http version mismatched"); }
From source file:org.zaproxy.zap.extension.ascanrulesAlpha.CloudMetadataScanner.java
private static HttpMethod createRequestMethod(HttpRequestHeader header, HttpBody body, HttpMethodParams params) throws URIException { HttpMethod httpMethod = new ZapGetMethod(); httpMethod.setURI(header.getURI());/*w ww .j a v a2s. c o m*/ httpMethod.setParams(params); params.setVersion(HttpVersion.HTTP_1_1); String msg = header.getHeadersAsString(); String[] split = Pattern.compile("\\r\\n", Pattern.MULTILINE).split(msg); String token = null; String name = null; String value = null; int pos = 0; for (int i = 0; i < split.length; i++) { token = split[i]; if (token.equals("")) { continue; } if ((pos = token.indexOf(":")) < 0) { return null; } name = token.substring(0, pos).trim(); value = token.substring(pos + 1).trim(); httpMethod.addRequestHeader(name, value); } if (body != null && body.length() > 0 && (httpMethod instanceof EntityEnclosingMethod)) { EntityEnclosingMethod post = (EntityEnclosingMethod) httpMethod; post.setRequestEntity(new ByteArrayRequestEntity(body.getBytes())); } httpMethod.setFollowRedirects(false); return httpMethod; }
From source file:voldemort.client.HttpStoreClientFactory.java
public HttpStoreClientFactory(ClientConfig config) { super(config); HostConfiguration hostConfig = new HostConfiguration(); hostConfig.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1); MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); this.httpClient = new HttpClient(connectionManager); this.httpClient.setHostConfiguration(hostConfig); HttpClientParams clientParams = this.httpClient.getParams(); clientParams.setConnectionManagerTimeout(config.getConnectionTimeout(TimeUnit.MILLISECONDS)); clientParams.setSoTimeout(config.getSocketTimeout(TimeUnit.MILLISECONDS)); clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES); clientParams.setParameter("http.useragent", VOLDEMORT_USER_AGENT); HttpConnectionManagerParams managerParams = this.httpClient.getHttpConnectionManager().getParams(); managerParams.setConnectionTimeout(config.getConnectionTimeout(TimeUnit.MILLISECONDS)); managerParams.setMaxTotalConnections(config.getMaxTotalConnections()); managerParams.setStaleCheckingEnabled(false); managerParams.setMaxConnectionsPerHost(httpClient.getHostConfiguration(), config.getMaxConnectionsPerNode()); this.reroute = config.getRoutingTier().equals(RoutingTier.SERVER); this.requestFormatFactory = new RequestFormatFactory(); }
From source file:voldemort.performance.HttpClientBench.java
private static HttpClient createClient() { HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpClient httpClient = new HttpClient(connectionManager); HttpClientParams clientParams = httpClient.getParams(); clientParams.setConnectionManagerTimeout(DEFAULT_CONNECTION_MANAGER_TIMEOUT); clientParams.setSoTimeout(500);/*w w w. j av a2 s .co m*/ clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES); clientParams.setBooleanParameter("http.tcp.nodelay", false); clientParams.setIntParameter("http.socket.receivebuffer", 60000); clientParams.setParameter("http.useragent", VOLDEMORT_USER_AGENT); HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost("localhost"); hostConfig.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1); httpClient.setHostConfiguration(hostConfig); HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager().getParams(); managerParams.setConnectionTimeout(DEFAULT_CONNECTION_MANAGER_TIMEOUT); managerParams.setMaxTotalConnections(DEFAULT_MAX_CONNECTIONS); managerParams.setMaxConnectionsPerHost(httpClient.getHostConfiguration(), DEFAULT_MAX_HOST_CONNECTIONS); managerParams.setStaleCheckingEnabled(false); return httpClient; }