Search in sources :

Example 1 with HttpClientParams

use of org.apache.commons.httpclient.params.HttpClientParams in project zm-mailbox by Zimbra.

the class ZimbraHttpConnectionManager method main.

public static void main(String[] args) {
    // dump httpclient package defaults
    System.out.println(dumpParams("httpclient package defaults", new HttpConnectionManagerParams(), new HttpClientParams()));
    System.out.println(dumpParams("Internal ZimbraHttpConnectionManager", ZimbraHttpConnectionManager.getInternalHttpConnMgr().getParams().getConnMgrParams(), ZimbraHttpConnectionManager.getInternalHttpConnMgr().getDefaultHttpClient().getParams()));
    System.out.println(dumpParams("External ZimbraHttpConnectionManager", ZimbraHttpConnectionManager.getExternalHttpConnMgr().getParams().getConnMgrParams(), ZimbraHttpConnectionManager.getExternalHttpConnMgr().getDefaultHttpClient().getParams()));
    HttpClient httpClient = ZimbraHttpConnectionManager.getInternalHttpConnMgr().getDefaultHttpClient();
    String connMgrName = httpClient.getHttpConnectionManager().getClass().getSimpleName();
    long connMgrTimeout = httpClient.getParams().getConnectionManagerTimeout();
    System.out.println("HttpConnectionManager for the HttpClient instance is: " + connMgrName);
    System.out.println("connection manager timeout for the HttpClient instance is: " + connMgrTimeout);
}
Also used : HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HttpClient(org.apache.commons.httpclient.HttpClient) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams)

Example 2 with HttpClientParams

use of org.apache.commons.httpclient.params.HttpClientParams in project camel by apache.

the class HttpComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    String addressUri = "http://" + remaining;
    if (uri.startsWith("https:")) {
        addressUri = "https://" + remaining;
    }
    Map<String, Object> httpClientParameters = new HashMap<String, Object>(parameters);
    // must extract well known parameters before we create the endpoint
    HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, "httpBinding", HttpBinding.class);
    HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
    UrlRewrite urlRewrite = resolveAndRemoveReferenceParameter(parameters, "urlRewrite", UrlRewrite.class);
    // http client can be configured from URI options
    HttpClientParams clientParams = new HttpClientParams();
    Map<String, Object> httpClientOptions = IntrospectionSupport.extractProperties(parameters, "httpClient.");
    IntrospectionSupport.setProperties(clientParams, httpClientOptions);
    // validate that we could resolve all httpClient. parameters as this component is lenient
    validateParameters(uri, httpClientOptions, null);
    // http client can be configured from URI options
    HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams();
    // setup the httpConnectionManagerParams
    Map<String, Object> httpConnectionManagerOptions = IntrospectionSupport.extractProperties(parameters, "httpConnectionManager.");
    IntrospectionSupport.setProperties(connectionManagerParams, httpConnectionManagerOptions);
    // validate that we could resolve all httpConnectionManager. parameters as this component is lenient
    validateParameters(uri, httpConnectionManagerOptions, null);
    // make sure the component httpConnectionManager is take effect
    HttpConnectionManager thisHttpConnectionManager = httpConnectionManager;
    if (thisHttpConnectionManager == null) {
        // only set the params on the new created http connection manager
        thisHttpConnectionManager = new MultiThreadedHttpConnectionManager();
        thisHttpConnectionManager.setParams(connectionManagerParams);
    }
    // create the configurer to use for this endpoint (authMethods contains the used methods created by the configurer)
    final Set<AuthMethod> authMethods = new LinkedHashSet<AuthMethod>();
    HttpClientConfigurer configurer = createHttpClientConfigurer(parameters, authMethods);
    addressUri = UnsafeUriCharactersEncoder.encodeHttpURI(addressUri);
    URI endpointUri = URISupport.createRemainingURI(new URI(addressUri), httpClientParameters);
    // create the endpoint and connectionManagerParams already be set
    HttpEndpoint endpoint = createHttpEndpoint(endpointUri.toString(), this, clientParams, thisHttpConnectionManager, configurer);
    // configure the endpoint with the common configuration from the component
    if (getHttpConfiguration() != null) {
        Map<String, Object> properties = new HashMap<>();
        IntrospectionSupport.getProperties(getHttpConfiguration(), properties, null);
        setProperties(endpoint, properties);
    }
    if (headerFilterStrategy != null) {
        endpoint.setHeaderFilterStrategy(headerFilterStrategy);
    } else {
        setEndpointHeaderFilterStrategy(endpoint);
    }
    if (urlRewrite != null) {
        // let CamelContext deal with the lifecycle of the url rewrite
        // this ensures its being shutdown when Camel shutdown etc.
        getCamelContext().addService(urlRewrite);
        endpoint.setUrlRewrite(urlRewrite);
    }
    // prefer to use endpoint configured over component configured
    if (binding == null) {
        // fallback to component configured
        binding = getHttpBinding();
    }
    if (binding != null) {
        endpoint.setBinding(binding);
    }
    setProperties(endpoint, parameters);
    // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
    URI httpUri = URISupport.createRemainingURI(new URI(addressUri), parameters);
    // validate http uri that end-user did not duplicate the http part that can be a common error
    String part = httpUri.getSchemeSpecificPart();
    if (part != null) {
        part = part.toLowerCase();
        if (part.startsWith("//http//") || part.startsWith("//https//") || part.startsWith("//http://") || part.startsWith("//https://")) {
            throw new ResolveEndpointFailedException(uri, "The uri part is not configured correctly. You have duplicated the http(s) protocol.");
        }
    }
    endpoint.setHttpUri(httpUri);
    endpoint.setHttpClientOptions(httpClientOptions);
    return endpoint;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) UrlRewrite(org.apache.camel.http.common.UrlRewrite) HeaderFilterStrategy(org.apache.camel.spi.HeaderFilterStrategy) HttpRestHeaderFilterStrategy(org.apache.camel.http.common.HttpRestHeaderFilterStrategy) URI(java.net.URI) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) HttpBinding(org.apache.camel.http.common.HttpBinding) HttpConnectionManager(org.apache.commons.httpclient.HttpConnectionManager) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)

Example 3 with HttpClientParams

use of org.apache.commons.httpclient.params.HttpClientParams in project camel by apache.

the class HttpComponentVerifier method createHttpClient.

private HttpClient createHttpClient(ResultBuilder builder, Map<String, Object> parameters) throws Exception {
    HttpClientParams clientParams = setProperties(new HttpClientParams(), "httpClient.", parameters);
    HttpClient client = new HttpClient(clientParams);
    CompositeHttpConfigurer configurer = new CompositeHttpConfigurer();
    configureProxy(builder, parameters).ifPresent(configurer::addConfigurer);
    configureAuthentication(builder, parameters).ifPresent(configurer::addConfigurer);
    configurer.configureHttpClient(client);
    return client;
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams)

Example 4 with HttpClientParams

use of org.apache.commons.httpclient.params.HttpClientParams in project lobcder by skoulouzis.

the class TestWebWAVFS method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    String propBasePath = "etc" + File.separator + "test.properties";
    prop = TestSettings.getTestProperties(propBasePath);
    String testURL = prop.getProperty("webdav.test.url");
    // Some problem with the pom.xml. The properties are set but System.getProperty gets null
    if (testURL == null) {
        testURL = "http://localhost:8080/lobcder-1.0-SNAPSHOT/";
    }
    assertTrue(testURL != null);
    if (!testURL.endsWith("/")) {
        testURL = testURL + "/";
    }
    uri = URI.create(testURL);
    root = uri.toASCIIString();
    if (!root.endsWith("/")) {
        root += "/";
    }
    username1 = prop.getProperty(("webdav.test.username1"), "");
    if (username1 == null) {
        username1 = "user1";
    }
    assertTrue(username1 != null);
    password1 = prop.getProperty(("webdav.test.password1"), "");
    if (password1 == null) {
        password1 = "passwd1";
    }
    assertTrue(password1 != null);
    username2 = prop.getProperty(("webdav.test.username2"), "user2");
    assertTrue(username2 != null);
    password2 = prop.getProperty(("webdav.test.password2"), "passwd2");
    assertTrue(password2 != null);
    quckTest = Boolean.valueOf(prop.getProperty(("test.quick"), "true"));
    client1 = new HttpClient();
    HttpClientParams params = new HttpClientParams();
    params.setParameter("http.protocol.handle-redirects", false);
    client1.setParams(params);
    assertNotNull(uri.getHost());
    assertNotNull(uri.getPort());
    assertNotNull(client1);
    int port = uri.getPort();
    if (port == -1) {
        port = 443;
    }
    ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
    Protocol https = new Protocol("https", socketFactory, port);
    Protocol.registerProtocol("https", https);
    client1.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username1, password1));
    httpclient = new DefaultHttpClient();
    org.apache.http.auth.Credentials defaultcreds = new org.apache.http.auth.UsernamePasswordCredentials(username1, password1);
    httpclient.getCredentialsProvider().setCredentials(org.apache.http.auth.AuthScope.ANY, (org.apache.http.auth.Credentials) defaultcreds);
    // httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    client2 = new HttpClient();
    assertNotNull(uri.getHost());
    assertNotNull(uri.getPort());
    assertNotNull(client2);
    client2.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username2, password2));
    ClientConfig clientConfig = new DefaultClientConfig();
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    restClient = Client.create(clientConfig);
    restClient.addFilter(new com.sun.jersey.api.client.filter.HTTPBasicAuthFilter(username1, password1));
    restURL = prop.getProperty(("rest.test.url"), "http://localhost:8080/lobcder-2.0-SNAPSHOT/rest/");
    utils = new Utils(client1);
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) EasySSLProtocolSocketFactory(org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) EasySSLProtocolSocketFactory(org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory) ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams) AuthScope(org.apache.commons.httpclient.auth.AuthScope) Protocol(org.apache.commons.httpclient.protocol.Protocol) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) BeforeClass(org.junit.BeforeClass)

Example 5 with HttpClientParams

use of org.apache.commons.httpclient.params.HttpClientParams in project cloudstack by apache.

the class BigSwitchApiTest method setUp.

@Before
public void setUp() {
    HttpClientParams hmp = mock(HttpClientParams.class);
    when(_client.getParams()).thenReturn(hmp);
    _api = new BigSwitchBcfApi() {

        @Override
        protected HttpClient createHttpClient() {
            return _client;
        }

        @Override
        protected HttpMethod createMethod(String type, String uri, int port) {
            return _method;
        }
    };
    _api.setControllerAddress("10.10.0.10");
    _api.setControllerUsername("myname");
    _api.setControllerPassword("mypassword");
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams) HttpMethod(org.apache.commons.httpclient.HttpMethod) Before(org.junit.Before)

Aggregations

HttpClientParams (org.apache.commons.httpclient.params.HttpClientParams)20 HttpClient (org.apache.commons.httpclient.HttpClient)18 IOException (java.io.IOException)7 HttpMethod (org.apache.commons.httpclient.HttpMethod)6 BufferedReader (java.io.BufferedReader)5 InputStreamReader (java.io.InputStreamReader)5 MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)5 GetMethod (org.apache.commons.httpclient.methods.GetMethod)5 HttpConnectionManagerParams (org.apache.commons.httpclient.params.HttpConnectionManagerParams)5 Map (java.util.Map)3 URIException (org.apache.commons.httpclient.URIException)3 PostMethod (org.apache.commons.httpclient.methods.PostMethod)3 HashMap (java.util.HashMap)2 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)2 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)1 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)1