Package org.sonatype.nexus.httpclient.HttpClientFactory

Examples of org.sonatype.nexus.httpclient.HttpClientFactory.Builder


  @Override
  public HttpClient create(final ProxyRepository proxyRepository, final RemoteStorageContext ctx) {
    checkNotNull(proxyRepository);
    checkNotNull(ctx);
    final Builder builder = httpClientFactory.prepare(new RemoteStorageContextCustomizer(ctx));
    configure(builder);
    return builder.build();
  }
View Full Code Here


    checkNotNull(context);
    checkNotNull(host);

    log.info("Retrieving certificate from https://{}:{}", host, port);

    Builder httpClientBuilder = null;
    HttpClientConnectionManager connectionManager = null;
    try {
      final AtomicReference<Certificate[]> chain = new AtomicReference<Certificate[]>();
      final SSLContext sc = SSLContext.getInstance("TLS");
      sc.init(null, new TrustManager[]{ACCEPT_ALL_TRUST_MANAGER}, null);

      final SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sc, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
      final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
          .register("http", PlainConnectionSocketFactory.getSocketFactory())
          .register("https", sslSocketFactory).build();

      httpClientBuilder = httpClientFactory.prepare(new RemoteStorageContextCustomizer(context));
      connectionManager = new BasicHttpClientConnectionManager(registry);
      httpClientBuilder.getHttpClientBuilder().setConnectionManager(connectionManager);
      httpClientBuilder.getHttpClientBuilder().addInterceptorFirst(
          new HttpResponseInterceptor()
          {
            @Override
            public void process(final HttpResponse response, final HttpContext context)
                throws HttpException, IOException
            {
              final ManagedHttpClientConnection connection = HttpCoreContext.adapt(context).getConnection(ManagedHttpClientConnection.class);
              if (connection != null) {
                SSLSession session = connection.getSSLSession();
                if (session != null) {
                  chain.set(session.getPeerCertificates());
                }
              }
            }
          });
      httpClientBuilder.build().execute(new HttpGet("https://" + host + ":" + port));
      return chain.get();
    }
    finally {
      if (connectionManager != null) {
        connectionManager.shutdown();
View Full Code Here

          eventBus,
          jmxInstaller,
          null);

      // just to grab UA
      final Builder builder = testSubject.prepare(new RemoteStorageContextCustomizer(globalRemoteStorageContext));
      final String userAgent = builder.getUserAgent();
      final HttpClient client = builder.build();

      activity.perform(client);

      assertThat(userAgentChecker.getUserAgents(), hasSize(1)); // same UA should be used even if multiple reqs
      assertThat(userAgentChecker.getUserAgents().iterator().next(), equalTo(userAgent)); // the one we set must be used
View Full Code Here

        eventBus,
        jmxInstaller,
        null);

    RemoteStorageContextCustomizer customizer = new RemoteStorageContextCustomizer(globalRemoteStorageContext);
    final Builder builder = testSubject.prepare(customizer);

    final RemoteAuthenticationSettings remoteAuthenticationSettings =
        new UsernamePasswordRemoteAuthenticationSettings("user", "pass");
    customizer.applyAuthenticationConfig(builder, remoteAuthenticationSettings, null);

    final DefaultRemoteHttpProxySettings httpProxy = new DefaultRemoteHttpProxySettings();
    httpProxy.setHostname("http-proxy");
    httpProxy.setPort(8080);
    httpProxy.setProxyAuthentication(new UsernamePasswordRemoteAuthenticationSettings("http-proxy", "http-pass"));

    final DefaultRemoteHttpProxySettings httpsProxy = new DefaultRemoteHttpProxySettings();
    httpsProxy.setHostname("https-proxy");
    httpsProxy.setPort(9090);
    httpsProxy.setProxyAuthentication(new UsernamePasswordRemoteAuthenticationSettings("https-proxy", "https-pass"));

    final DefaultRemoteProxySettings remoteProxySettings = new DefaultRemoteProxySettings();
    remoteProxySettings.setHttpProxySettings(httpProxy);
    remoteProxySettings.setHttpsProxySettings(httpsProxy);

    customizer.applyProxyConfig(builder, remoteProxySettings);

    final CredentialsProvider credentialsProvider = builder.getCredentialsProvider();

    assertThat(credentialsProvider.getCredentials(AuthScope.ANY), notNullValue(Credentials.class));
    assertThat(credentialsProvider.getCredentials(AuthScope.ANY).getUserPrincipal().getName(), equalTo("user"));
    assertThat(credentialsProvider.getCredentials(AuthScope.ANY).getPassword(), equalTo("pass"));
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.httpclient.HttpClientFactory.Builder

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.