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:com.carrotsearch.util.httpclient.HttpUtils.java
/** * Opens a HTTP/1.1 connection to the given URL using the GET method, decompresses * compressed response streams, if supported by the server. * //from w ww. j av a 2 s .c om * @param url The URL to open. The URL must be properly escaped, this method will * <b>not</b> perform any escaping. * @param params Query string parameters to be attached to the url. * @param headers Any extra HTTP headers to add to the request. * @return The {@link HttpUtils.Response} object. Note that entire payload is read and * buffered so that the HTTP connection can be closed when leaving this * method. */ public static Response doGET(String url, Collection<NameValuePair> params, Collection<Header> headers) throws HttpException, IOException { final HttpClient client = HttpClientFactory.getTimeoutingClient(); client.getParams().setVersion(HttpVersion.HTTP_1_1); final GetMethod request = new GetMethod(); final Response response = new Response(); try { request.setURI(new URI(url, true)); if (params != null) { request.setQueryString(params.toArray(new NameValuePair[params.size()])); } request.setRequestHeader(HttpHeaders.URL_ENCODED); request.setRequestHeader(HttpHeaders.GZIP_ENCODING); if (headers != null) { for (Header header : headers) request.setRequestHeader(header); } Logger.getLogger(HttpUtils.class).debug("GET: " + request.getURI()); final int statusCode = client.executeMethod(request); response.status = statusCode; InputStream stream = request.getResponseBodyAsStream(); final Header encoded = request.getResponseHeader("Content-Encoding"); if (encoded != null && "gzip".equalsIgnoreCase(encoded.getValue())) { stream = new GZIPInputStream(stream); response.compression = COMPRESSION_GZIP; } else { response.compression = COMPRESSION_NONE; } final Header[] respHeaders = request.getResponseHeaders(); response.headers = new String[respHeaders.length][]; for (int i = 0; i < respHeaders.length; i++) { response.headers[i] = new String[] { respHeaders[i].getName(), respHeaders[i].getValue() }; } response.payload = StreamUtils.readFullyAndClose(stream); return response; } finally { request.releaseConnection(); } }
From source file:com.predic8.membrane.integration.Http11Test.java
/** * Note that "Read timed out" indicates incorrect server behavior. The * socket timeout is set on the client to avoid fallback mentioned in * RFC2616 section 8.2.3 ("indefinite period"). *///from ww w. ja va 2 s .c o m public static void initExpect100ContinueWithFastFail(HttpClient client) { client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, true); client.getParams().setParameter("http.method.retry-handler", new HttpMethodRetryHandler() { @Override public boolean retryMethod(HttpMethod arg0, IOException arg1, int arg2) { return false; } }); client.getParams().setParameter("http.socket.timeout", 7000); }
From source file:com.eviware.soapui.impl.wsdl.submit.filters.PostPackagingRequestFilter.java
@Override public void filterAbstractHttpRequest(SubmitContext context, AbstractHttpRequest<?> request) { ExtendedHttpMethod httpMethod = (ExtendedHttpMethod) context .getProperty(BaseHttpRequestTransport.HTTP_METHOD); Settings settings = request.getSettings(); // chunking?//from w w w . j a va 2s. c o m if (httpMethod.getParams().getVersion().equals(HttpVersion.HTTP_1_1) && httpMethod instanceof EntityEnclosingMethod) { EntityEnclosingMethod entityEnclosingMethod = ((EntityEnclosingMethod) httpMethod); long limit = settings.getLong(HttpSettings.CHUNKING_THRESHOLD, -1); RequestEntity requestEntity = entityEnclosingMethod.getRequestEntity(); entityEnclosingMethod.setContentChunked( limit >= 0 && requestEntity != null ? requestEntity.getContentLength() > limit : false); } }
From source file:com.greenbird.mule.http.log.RequestPropertiesRetainerTest.java
@Test public void transformMessage_normal_relevantPropertiesRetained() throws Exception { HttpRequest request = new HttpRequest(new RequestLine("GET", REQUEST, HttpVersion.HTTP_1_1), new Header[] { new Header("testHeader", "testValue") }, ENCODING); MuleMessage message = new HttpMuleMessageFactory(context()).create(request, "UTF-8"); retainer.retainRequestProperties(message); Map<String, Object> retainedProperties = message .getInvocationProperty(RequestPropertiesRetainer.INITIAL_REQUEST_PROPERTY); assertThat(retainedProperties.size(), is(7)); @SuppressWarnings("unchecked") Map<String, String> headers = (Map<String, String>) retainedProperties.get(HttpConnector.HTTP_HEADERS); assertThat(headers.get("testHeader"), is("testValue")); assertThat(retainedProperties.get(HttpConnector.HTTP_METHOD_PROPERTY).toString(), is("GET")); assertThat(retainedProperties.get(HttpConnector.HTTP_VERSION_PROPERTY).toString(), is("HTTP/1.1")); assertThat(retainedProperties.get(HttpConnector.HTTP_REQUEST_PROPERTY).toString(), is(REQUEST)); assertThat(retainedProperties.get(HttpConnector.HTTP_QUERY_STRING).toString(), is("query=value")); }
From source file:com.predic8.membrane.core.interceptor.rest.REST2SOAPInterceptorIntegrationTest.java
@Test public void testRest() throws Exception { HttpClient client = new HttpClient(); client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); GetMethod get = new GetMethod("http://localhost:3004/bank/37050198"); int status = client.executeMethod(get); //System.out.println(get.getResponseBodyAsString()); assertEquals(200, status);/* w w w. ja va 2 s . c om*/ }
From source file:com.predic8.membrane.core.interceptor.authentication.BasicAuthenticationInterceptorIntegrationTest.java
@Test public void testDeny() throws Exception { Rule rule = new ForwardingRule(new ForwardingRuleKey("localhost", "*", ".*", 8000), "thomas-bayer.com", 80); HttpRouter router = new HttpRouter(); router.getRuleManager().addRuleIfNew(rule); BasicAuthenticationInterceptor interceptor = new BasicAuthenticationInterceptor(); Map<String, String> mapping = new HashMap<String, String>(); mapping.put("admin", "admin"); interceptor.setUsers(mapping);//from w ww.j a v a2 s .c o m router.getTransport().getInterceptors().add(interceptor); HttpClient client = new HttpClient(); client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); int status = client.executeMethod(getGetMethod()); assertEquals(401, status); //TODO Basic Authentication test }
From source file:com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptorIntegrationTest.java
@Test public void testRewriting() throws Exception { HttpClient client = new HttpClient(); client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); int status = client.executeMethod(getPostMethod()); assertEquals(200, status);//from w w w.j ava2s . c om }
From source file:com.ironiacorp.http.impl.httpclient3.HttpJobRunnerHttpClient3.java
private void setupClient() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); // connectionManager.// maxConnectionsPerHost // maxTotalConnections httpClient = new HttpClient(connectionManager); // http://jakarta.apache.org/httpcomponents/httpclient-3.x/preference-api.html HttpClientParams params = httpClient.getParams(); params.setParameter("http.protocol.version", HttpVersion.HTTP_1_1); params.setParameter("http.socket.timeout", new Integer(60000)); params.setParameter("http.protocol.content-charset", "UTF-8"); params.setCookiePolicy(CookiePolicy.RFC_2109); }
From source file:com.greenbird.mule.http.log.converter.RequestPathConverterTest.java
@Test public void doConvert_pathAvailableInNotFoundReply_pathFromNotFoundReplyUsed() { HttpResponse response = new HttpResponse() { {/* w w w.j a v a 2 s .com*/ setStatusLine(HttpVersion.HTTP_1_1, HttpConstants.SC_NOT_FOUND); setBody("Cannot bind to address \"http://localhost:61000/path\" No component registered on that endpoint"); } }; String logOutput = logWithPayload(RequestPathConverter.CONVERSION_CHARACTER, response); assertThat(logOutput, is(PATH)); }
From source file:colt.nicity.performance.agent.LatentHttpPump.java
private org.apache.commons.httpclient.HttpClient createApacheClient(String host, int port, int maxConnections, int socketTimeoutInMillis) { HttpConnectionManager connectionManager = createConnectionManager(maxConnections); org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient( connectionManager);/* www . j a va2 s. co m*/ client.getParams().setParameter(HttpMethodParams.COOKIE_POLICY, CookiePolicy.RFC_2109); client.getParams().setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8"); client.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false); client.getParams().setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, true); client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, socketTimeoutInMillis > 0 ? socketTimeoutInMillis : 0); client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, socketTimeoutInMillis > 0 ? socketTimeoutInMillis : 0); HostConfiguration hostConfiguration = new HostConfiguration(); configureSsl(hostConfiguration, host, port); configureProxy(hostConfiguration); client.setHostConfiguration(hostConfiguration); return client; }