Search in sources :

Example 6 with HttpProxy

use of org.eclipse.jetty.client.HttpProxy in project jetty.project by eclipse.

the class ForwardProxyTLSServerTest method testProxyDown.

@Test
public void testProxyDown() throws Exception {
    startTLSServer(new ServerHandler());
    startProxy();
    int proxyPort = proxyConnector.getLocalPort();
    stopProxy();
    HttpClient httpClient = new HttpClient(newSslContextFactory());
    httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(new Origin.Address("localhost", proxyPort), proxySslContextFactory != null));
    httpClient.start();
    try {
        String body = "BODY";
        httpClient.newRequest("localhost", serverConnector.getLocalPort()).scheme(HttpScheme.HTTPS.asString()).method(HttpMethod.GET).path("/echo?body=" + URLEncoder.encode(body, "UTF-8")).timeout(5, TimeUnit.SECONDS).send();
        Assert.fail();
    } catch (ExecutionException x) {
        Assert.assertThat(x.getCause(), Matchers.instanceOf(ConnectException.class));
    } finally {
        httpClient.stop();
    }
}
Also used : HttpProxy(org.eclipse.jetty.client.HttpProxy) HttpClient(org.eclipse.jetty.client.HttpClient) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 7 with HttpProxy

use of org.eclipse.jetty.client.HttpProxy in project camel by apache.

the class SalesforceComponentVerifier method configureHttpProxy.

private void configureHttpProxy(SalesforceHttpClient httpClient, Map<String, Object> parameters) throws NoSuchOptionException, URISyntaxException {
    Optional<String> httpProxyHost = getOption(parameters, "httpProxyHost", String.class);
    Optional<Integer> httpProxyPort = getOption(parameters, "httpProxyPort", Integer.class);
    Optional<String> httpProxyUsername = getOption(parameters, "httpProxyUsername", String.class);
    Optional<String> httpProxyPassword = getOption(parameters, "httpProxyPassword", String.class);
    if (httpProxyHost.isPresent() && httpProxyPort.isPresent()) {
        Origin.Address address = new Origin.Address(httpProxyHost.get(), httpProxyPort.get());
        Boolean isHttpProxySocks4 = getOption(parameters, "isHttpProxySocks4", Boolean.class, () -> false);
        Boolean isHttpProxySecure = getOption(parameters, "isHttpProxySecure", Boolean.class, () -> true);
        if (isHttpProxySocks4) {
            httpClient.getProxyConfiguration().getProxies().add(new Socks4Proxy(address, isHttpProxySecure));
        } else {
            httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(address, isHttpProxySecure));
        }
    }
    if (httpProxyUsername.isPresent() && httpProxyPassword.isPresent()) {
        Boolean httpProxyUseDigestAuth = getOption(parameters, "httpProxyUseDigestAuth", Boolean.class, () -> false);
        String httpProxyAuthUri = getMandatoryOption(parameters, "httpProxyAuthUri", String.class);
        String httpProxyRealm = getMandatoryOption(parameters, "httpProxyRealm", String.class);
        if (httpProxyUseDigestAuth) {
            httpClient.getAuthenticationStore().addAuthentication(new DigestAuthentication(new URI(httpProxyAuthUri), httpProxyRealm, httpProxyUsername.get(), httpProxyPassword.get()));
        } else {
            httpClient.getAuthenticationStore().addAuthentication(new BasicAuthentication(new URI(httpProxyAuthUri), httpProxyRealm, httpProxyUsername.get(), httpProxyPassword.get()));
        }
    }
}
Also used : Origin(org.eclipse.jetty.client.Origin) DigestAuthentication(org.eclipse.jetty.client.util.DigestAuthentication) URI(java.net.URI) HttpProxy(org.eclipse.jetty.client.HttpProxy) Socks4Proxy(org.eclipse.jetty.client.Socks4Proxy) BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication)

Example 8 with HttpProxy

use of org.eclipse.jetty.client.HttpProxy in project jetty.project by eclipse.

the class AsyncMiddleManServletTest method startClient.

private void startClient() throws Exception {
    QueuedThreadPool clientPool = new QueuedThreadPool();
    clientPool.setName("client");
    client = new HttpClient();
    client.setExecutor(clientPool);
    client.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort()));
    client.start();
}
Also used : HttpProxy(org.eclipse.jetty.client.HttpProxy) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpClient(org.eclipse.jetty.client.HttpClient)

Example 9 with HttpProxy

use of org.eclipse.jetty.client.HttpProxy in project jetty.project by eclipse.

the class ProxyServletLoadTest method startClient.

private void startClient() throws Exception {
    QueuedThreadPool clientPool = new QueuedThreadPool();
    clientPool.setName("client");
    HttpClient result = new HttpClient();
    result.setExecutor(clientPool);
    result.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort()));
    result.start();
    client = result;
}
Also used : HttpProxy(org.eclipse.jetty.client.HttpProxy) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpClient(org.eclipse.jetty.client.HttpClient)

Example 10 with HttpProxy

use of org.eclipse.jetty.client.HttpProxy in project camel by apache.

the class SalesforceComponent method doStart.

@Override
protected void doStart() throws Exception {
    if (loginConfig == null) {
        if (ObjectHelper.isNotEmpty(password)) {
            loginConfig = new SalesforceLoginConfig(loginUrl, clientId, clientSecret, userName, password, lazyLogin);
        } else if (ObjectHelper.isNotEmpty(refreshToken)) {
            loginConfig = new SalesforceLoginConfig(loginUrl, clientId, clientSecret, refreshToken, lazyLogin);
        } else if (ObjectHelper.isNotEmpty(keystore)) {
            loginConfig = new SalesforceLoginConfig(loginUrl, clientId, userName, keystore, lazyLogin);
        } else {
            throw new IllegalArgumentException("Cannot define a login configuration, the component configuration" + " does not contain `password`, `refreshToken` or `keystore` parameters. Specifying one of those" + " determines the type of authentication performed.");
        }
        LOG.debug("Created login configuration: {}", loginConfig);
    } else {
        LOG.debug("Using shared login configuration: {}", loginConfig);
    }
    // create a Jetty HttpClient if not already set
    if (null == httpClient) {
        if (config != null && config.getHttpClient() != null) {
            httpClient = config.getHttpClient();
        } else {
            // set ssl context parameters if set
            final SSLContextParameters contextParameters = sslContextParameters != null ? sslContextParameters : new SSLContextParameters();
            final SslContextFactory sslContextFactory = new SslContextFactory();
            sslContextFactory.setSslContext(contextParameters.createSSLContext(getCamelContext()));
            httpClient = new SalesforceHttpClient(sslContextFactory);
            // default settings, use httpClientProperties to set other properties
            httpClient.setConnectTimeout(CONNECTION_TIMEOUT);
        }
    }
    // set HTTP client parameters
    if (httpClientProperties != null && !httpClientProperties.isEmpty()) {
        IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), httpClient, new HashMap<String, Object>(httpClientProperties));
    }
    // set HTTP proxy settings
    if (this.httpProxyHost != null && httpProxyPort != null) {
        Origin.Address proxyAddress = new Origin.Address(this.httpProxyHost, this.httpProxyPort);
        ProxyConfiguration.Proxy proxy;
        if (isHttpProxySocks4) {
            proxy = new Socks4Proxy(proxyAddress, isHttpProxySecure);
        } else {
            proxy = new HttpProxy(proxyAddress, isHttpProxySecure);
        }
        if (httpProxyIncludedAddresses != null && !httpProxyIncludedAddresses.isEmpty()) {
            proxy.getIncludedAddresses().addAll(httpProxyIncludedAddresses);
        }
        if (httpProxyExcludedAddresses != null && !httpProxyExcludedAddresses.isEmpty()) {
            proxy.getExcludedAddresses().addAll(httpProxyExcludedAddresses);
        }
        httpClient.getProxyConfiguration().getProxies().add(proxy);
    }
    if (this.httpProxyUsername != null && httpProxyPassword != null) {
        ObjectHelper.notEmpty(httpProxyAuthUri, "httpProxyAuthUri");
        ObjectHelper.notEmpty(httpProxyRealm, "httpProxyRealm");
        final Authentication authentication;
        if (httpProxyUseDigestAuth) {
            authentication = new DigestAuthentication(new URI(httpProxyAuthUri), httpProxyRealm, httpProxyUsername, httpProxyPassword);
        } else {
            authentication = new BasicAuthentication(new URI(httpProxyAuthUri), httpProxyRealm, httpProxyUsername, httpProxyPassword);
        }
        httpClient.getAuthenticationStore().addAuthentication(authentication);
    }
    // support restarts
    if (this.session == null) {
        this.session = new SalesforceSession(getCamelContext(), httpClient, httpClient.getTimeout(), loginConfig);
    }
    // set session before calling start()
    httpClient.setSession(this.session);
    // start the Jetty client to initialize thread pool, etc.
    httpClient.start();
    // login at startup if lazyLogin is disabled
    if (!loginConfig.isLazyLogin()) {
        ServiceHelper.startService(session);
    }
    if (packages != null && packages.length > 0) {
        // parse the packages to create SObject name to class map
        classMap = parsePackages();
        LOG.info("Found {} generated classes in packages: {}", classMap.size(), Arrays.asList(packages));
    } else {
        // use an empty map to avoid NPEs later
        LOG.warn("Missing property packages, getSObject* operations will NOT work");
        classMap = new HashMap<String, Class<?>>(0);
    }
    if (subscriptionHelper != null) {
        ServiceHelper.startService(subscriptionHelper);
    }
}
Also used : Origin(org.eclipse.jetty.client.Origin) DigestAuthentication(org.eclipse.jetty.client.util.DigestAuthentication) URI(java.net.URI) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters) HttpProxy(org.eclipse.jetty.client.HttpProxy) Socks4Proxy(org.eclipse.jetty.client.Socks4Proxy) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) ProxyConfiguration(org.eclipse.jetty.client.ProxyConfiguration) Authentication(org.eclipse.jetty.client.api.Authentication) DigestAuthentication(org.eclipse.jetty.client.util.DigestAuthentication) BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication) SalesforceSession(org.apache.camel.component.salesforce.internal.SalesforceSession) BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication)

Aggregations

HttpProxy (org.eclipse.jetty.client.HttpProxy)11 HttpClient (org.eclipse.jetty.client.HttpClient)7 BasicAuthentication (org.eclipse.jetty.client.util.BasicAuthentication)4 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)4 URI (java.net.URI)3 Origin (org.eclipse.jetty.client.Origin)3 Socks4Proxy (org.eclipse.jetty.client.Socks4Proxy)3 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)3 DigestAuthentication (org.eclipse.jetty.client.util.DigestAuthentication)3 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 SalesforceSession (org.apache.camel.component.salesforce.internal.SalesforceSession)2 SSLContextParameters (org.apache.camel.util.jsse.SSLContextParameters)2 ProxyConfiguration (org.eclipse.jetty.client.ProxyConfiguration)2 Authentication (org.eclipse.jetty.client.api.Authentication)2 Socket (java.net.Socket)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ServletException (javax.servlet.ServletException)1