Package com.sun.jersey.client.apache4.config

Examples of com.sun.jersey.client.apache4.config.ApacheHttpClient4Config


    }

    private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration) {
        HttpClient httpClient = new HttpClientBuilder().using(configuration).build();
        ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
        ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
        config.getSingletons().add(new JacksonMessageBodyProvider(new ObjectMapper(), new Validator()));
        return new ApacheHttpClient4(handler, config);
    }
View Full Code Here


        return responseText;
    }

    private Client getClient(String endpoint) {
        // set up standard properties
        DefaultApacheHttpClient4Config clientConfig = new DefaultApacheHttpClient4Config();
        Map<String, Object> clientProperties = clientConfig.getProperties();
        clientProperties.put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
        clientConfig.getClasses().addAll(ConnUtilities.getJerseyProviders());

        // see if proxy needed
        URI uri;
        try {
            uri = new URI(endpoint);
View Full Code Here

        APPLICATION_XML_UTF8_TYPE
    );
  }

  protected ApacheHttpClient4 doCreateHttpClientFor(final ConnectionInfo connectionInfo, final XStream xstream) {
    final ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new XStreamXmlProvider(xstream, APPLICATION_XML_UTF8_TYPE));
    // set _real_ URL for baseUrl, and not a redirection (typically http instead of https)
    config.getProperties().put(PROPERTY_FOLLOW_REDIRECTS, Boolean.FALSE);

    applyAuthenticationIfAny(connectionInfo, config);
    applyProxyIfAny(connectionInfo, config);

    // obey JSSE defined system properties
    config.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER,
        new PoolingClientConnectionManager(SchemeRegistryFactory.createSystemDefault()));

    final ApacheHttpClient4 client = ApacheHttpClient4.create(config);

    // set UA
View Full Code Here

    }

    private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration) {
        HttpClient httpClient = new HttpClientBuilder().using(configuration).build();
        ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
        ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
        config.getSingletons().add(new JacksonMessageBodyProvider(new ObjectMapper(), new Validator()));
        return new ApacheHttpClient4(handler, config);
    }
View Full Code Here

    }

    private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration) {
        HttpClient httpClient = new HttpClientBuilder().using(configuration).build();
        ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
        ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
        config.getSingletons().add(new JacksonMessageBodyProvider(new ObjectMapperFactory().build(), new Validator()));
        return new ApacheHttpClient4(handler, config);
    }
View Full Code Here

    public static Client createApacheClient(AtmosConfig config,
                                            boolean useExpect100Continue,
                                            List<Class<MessageBodyReader<?>>> readers,
                                            List<Class<MessageBodyWriter<?>>> writers) {
        try {
            ClientConfig clientConfig = new DefaultApacheHttpClient4Config();

            // make sure the apache client is thread-safe
            PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
            // Increase max total connection to 200
            connectionManager.setMaxTotal(200);
            // Increase default max connection per route to 200
            connectionManager.setDefaultMaxPerRoute(200);
            clientConfig.getProperties().put(DefaultApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER,
                    connectionManager);

            // register an open trust manager to allow SSL connections to servers with self-signed certificates
            if (config.isDisableSslValidation()) {
                connectionManager.getSchemeRegistry().register(
                        new Scheme("https", 443,
                                new SSLSocketFactory(SslUtil.createGullibleSslContext(),
                                        SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)));
            }

            // set proxy configuration
            // first look in config
            URI proxyUri = config.getProxyUri();
            // then check system props
            if (proxyUri == null) {
                String host = System.getProperty("http.proxyHost");
                String portStr = System.getProperty("http.proxyPort");
                int port = (portStr != null) ? Integer.parseInt(portStr) : -1;
                if (host != null && host.length() > 0)
                    proxyUri = new URI("http", null, host, port, null, null, null);
            }
            if (proxyUri != null)
                clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_PROXY_URI, proxyUri);

            // set proxy auth
            // first config
            String proxyUser = config.getProxyUser(), proxyPassword = config.getProxyPassword();
            // then system props
            if (proxyUser == null) {
                proxyUser = System.getProperty("http.proxyUser");
                proxyPassword = System.getProperty("http.proxyPassword");
            }
            if (proxyUser != null && proxyUser.length() > 0) {
                clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_PROXY_USERNAME, proxyUser);
                clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD, proxyPassword);
            }

            // specify whether to use Expect: 100-continue
            HttpParams httpParams = new SyncBasicHttpParams();
            DefaultHttpClient.setDefaultHttpParams(httpParams);
            httpParams.setBooleanParameter(AllClientPNames.USE_EXPECT_CONTINUE, useExpect100Continue);
            clientConfig.getProperties().put(DefaultApacheHttpClient4Config.PROPERTY_HTTP_PARAMS, httpParams);

            // pick up other configuration from system props
            for (String prop : System.getProperties().stringPropertyNames()) {
                if (prop.startsWith("http.")) {
                    // because AbstractHttpParams uses casts instead of parsing string values, we must know the
View Full Code Here

  private final CouchDocSerializer couchDocSerializer = new CouchDocSerializer();

  @Nonnull
  public static CouchDatabase create( @Nonnull URI uri, @Nullable ClientFilter... filters ) {
    ClientConnectionManager connectionManager = new ThreadSafeClientConnManager();
    DefaultApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getProperties().put( ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, connectionManager );

    Client client = ApacheHttpClient4.create( config );

    if ( filters != null ) {
      for ( ClientFilter filter : filters ) {
View Full Code Here

*/
public class CouchDatabase extends AbstractCouchDatabase {
  @Nonnull
  public static CouchDatabase create( @Nonnull URI uri, @Nullable ClientFilter... filters ) {
    ClientConnectionManager connectionManager = new ThreadSafeClientConnManager();
    DefaultApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getProperties().put( ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, connectionManager );

    Client client = ApacheHttpClient4.create( config );

    if ( filters != null ) {
      for ( ClientFilter filter : filters ) {
View Full Code Here

    public static Client createApacheClient(AtmosConfig config,
                                            boolean useExpect100Continue,
                                            List<Class<MessageBodyReader<?>>> readers,
                                            List<Class<MessageBodyWriter<?>>> writers) {
        try {
            ClientConfig clientConfig = new DefaultApacheHttpClient4Config();

            // make sure the apache client is thread-safe
            PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
            // Increase max total connection to 200
            connectionManager.setMaxTotal(200);
            // Increase default max connection per route to 200
            connectionManager.setDefaultMaxPerRoute(200);
            clientConfig.getProperties().put(DefaultApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER,
                    connectionManager);

            // register an open trust manager to allow SSL connections to servers with self-signed certificates
            if (config.isDisableSslValidation()) {
                connectionManager.getSchemeRegistry().register(
                        new Scheme("https", 443,
                                new SSLSocketFactory(SslUtil.createGullibleSslContext(),
                                        SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)));
            }

            // set proxy uri
            ProxySelector proxySelector;
            // first look in config
            URI proxyUri = config.getProxyUri();
            if (proxyUri != null) {
                proxySelector = new ConfigProxySelector(config);
            } else {
                // if no proxy in config, use system property sniffing selector
                proxySelector = new DefaultProxySelector();

                // and see if a proxy is set
                String host = System.getProperty("http.proxyHost");
                String portStr = System.getProperty("http.proxyPort");
                int port = (portStr != null) ? Integer.parseInt(portStr) : -1;
                if (host != null && host.length() > 0)
                    proxyUri = new URI("http", null, host, port, null, null, null);
            }

            // make sure any proxy credentials (below) are associated with the proxy
            if (proxyUri != null)
                clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_PROXY_URI, proxyUri);

            // set proxy auth
            // first config
            String proxyUser = config.getProxyUser(), proxyPassword = config.getProxyPassword();
            // then system props
            if (proxyUser == null) {
                proxyUser = System.getProperty("http.proxyUser");
                proxyPassword = System.getProperty("http.proxyPassword");
            }
            if (proxyUser != null && proxyUser.length() > 0) {
                clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_PROXY_USERNAME, proxyUser);
                clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD, proxyPassword);
            }

            // specify whether to use Expect: 100-continue
            HttpParams httpParams = new SyncBasicHttpParams();
            DefaultHttpClient.setDefaultHttpParams(httpParams);
            httpParams.setBooleanParameter(AllClientPNames.USE_EXPECT_CONTINUE, useExpect100Continue);
            clientConfig.getProperties().put(DefaultApacheHttpClient4Config.PROPERTY_HTTP_PARAMS, httpParams);

            // pick up other configuration from system props
            for (String prop : System.getProperties().stringPropertyNames()) {
                if (prop.startsWith("http.")) {
                    // because AbstractHttpParams uses casts instead of parsing string values, we must know the
View Full Code Here

  public ConnectionManager(ConfigHelper config) {
    this.config = config;
  }

  public Client getConnection() throws MalformedURLException {
    ClientConfig clientConfig = new DefaultApacheHttpClient4Config();
     // make sure the apache client is thread-safe
    ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager();
        clientConfig.getProperties().put( DefaultApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER,
                                          connectionManager );

    if (config.getProxyUrl() != null) {
      clientConfig.getProperties().put(
          DefaultApacheHttpClient4Config.PROPERTY_PROXY_URI,
          config.getProxyUrl() + ":" + config.getProxyPort());
      if (config.getProxyUser() != null
          && config.getProxyPassword() != null) {
        clientConfig.getProperties().put(
            ApacheHttpClient4Config.PROPERTY_PROXY_USERNAME,
            config.getProxyUser());
        clientConfig.getProperties().put(
            ApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD,
            config.getProxyPassword());
      }
    }
    clientConfig.getClasses().add(MultiPartWriter.class);

    if (config.isDevel()) {
      try {
        connectionManager.getSchemeRegistry().register(
            new Scheme("https", 443, new SSLSocketFactory(createGullibleSslContext(),
View Full Code Here

TOP

Related Classes of com.sun.jersey.client.apache4.config.ApacheHttpClient4Config

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.