Search in sources :

Example 6 with HttpProxyOptions

use of software.amazon.awssdk.crt.http.HttpProxyOptions in project aws-sdk-java-v2 by aws.

the class AwsCrtAsyncHttpClient method buildProxyOptions.

private HttpProxyOptions buildProxyOptions(ProxyConfiguration proxyConfiguration) {
    if (proxyConfiguration == null) {
        return null;
    }
    HttpProxyOptions clientProxyOptions = new HttpProxyOptions();
    clientProxyOptions.setHost(proxyConfiguration.host());
    clientProxyOptions.setPort(proxyConfiguration.port());
    if ("https".equalsIgnoreCase(proxyConfiguration.scheme())) {
        clientProxyOptions.setTlsContext(tlsContext);
    }
    if (proxyConfiguration.username() != null && proxyConfiguration.password() != null) {
        clientProxyOptions.setAuthorizationUsername(proxyConfiguration.username());
        clientProxyOptions.setAuthorizationPassword(proxyConfiguration.password());
        clientProxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.Basic);
    } else {
        clientProxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.None);
    }
    return clientProxyOptions;
}
Also used : HttpProxyOptions(software.amazon.awssdk.crt.http.HttpProxyOptions)

Example 7 with HttpProxyOptions

use of software.amazon.awssdk.crt.http.HttpProxyOptions in project aws-crt-java by awslabs.

the class ProxyTest method buildProxiedConnectionManager.

private HttpClientConnectionManager buildProxiedConnectionManager(ProxyTestType testType, ProxyAuthType authType) {
    try (EventLoopGroup eventLoopGroup = new EventLoopGroup(1);
        HostResolver resolver = new HostResolver(eventLoopGroup);
        ClientBootstrap bootstrap = new ClientBootstrap(eventLoopGroup, resolver);
        SocketOptions sockOpts = new SocketOptions();
        TlsContext tlsContext = createHttpClientTlsContext();
        TlsContext proxyTlsContext = createProxyTlsContext(testType)) {
        HttpProxyOptions proxyOptions = buildProxyOptions(testType, authType, proxyTlsContext);
        HttpClientConnectionManagerOptions options = new HttpClientConnectionManagerOptions();
        options.withClientBootstrap(bootstrap).withSocketOptions(sockOpts).withTlsContext(tlsContext).withUri(getUriForTest(testType)).withMaxConnections(1).withProxyOptions(proxyOptions);
        return HttpClientConnectionManager.create(options);
    }
}
Also used : HttpProxyOptions(software.amazon.awssdk.crt.http.HttpProxyOptions) EventLoopGroup(software.amazon.awssdk.crt.io.EventLoopGroup) ClientBootstrap(software.amazon.awssdk.crt.io.ClientBootstrap) HttpClientConnectionManagerOptions(software.amazon.awssdk.crt.http.HttpClientConnectionManagerOptions) SocketOptions(software.amazon.awssdk.crt.io.SocketOptions) ClientTlsContext(software.amazon.awssdk.crt.io.ClientTlsContext) TlsContext(software.amazon.awssdk.crt.io.TlsContext) HostResolver(software.amazon.awssdk.crt.io.HostResolver)

Example 8 with HttpProxyOptions

use of software.amazon.awssdk.crt.http.HttpProxyOptions in project aws-crt-java by awslabs.

the class ProxyTest method buildProxyOptions.

private HttpProxyOptions buildProxyOptions(ProxyTestType testType, ProxyAuthType authType, TlsContext proxyTlsContext) {
    HttpProxyOptions proxyOptions = new HttpProxyOptions();
    proxyOptions.setHost(getProxyHostForTest(testType, authType));
    proxyOptions.setPort(getProxyPortForTest(testType, authType));
    proxyOptions.setConnectionType(getProxyConnectionTypeForTest(testType));
    proxyOptions.setTlsContext(proxyTlsContext);
    if (authType == ProxyAuthType.Basic) {
        proxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.Basic);
        proxyOptions.setAuthorizationUsername(HTTP_PROXY_BASIC_AUTH_USERNAME);
        proxyOptions.setAuthorizationPassword(HTTP_PROXY_BASIC_AUTH_PASSWORD);
    }
    return proxyOptions;
}
Also used : HttpProxyOptions(software.amazon.awssdk.crt.http.HttpProxyOptions)

Example 9 with HttpProxyOptions

use of software.amazon.awssdk.crt.http.HttpProxyOptions in project aws-iot-device-sdk-java-v2 by aws.

the class CommandLineOption method buildWebsocketX509MQTTConnection.

public MqttClientConnection buildWebsocketX509MQTTConnection(MqttClientConnectionEvents callbacks) {
    try {
        AwsIotMqttConnectionBuilder builder = AwsIotMqttConnectionBuilder.newMtlsBuilderFromPath(null, null);
        buildConnectionSetupCAFileDefaults(builder);
        buildConnectionSetupConnectionDefaults(builder, callbacks);
        HttpProxyOptions proxyOptions = null;
        int proxyPort = Integer.parseInt(getCommandOrDefault(m_cmd_proxy_port, "0"));
        if (hasCommand(m_cmd_proxy_host) && proxyPort > 0) {
            proxyOptions = new HttpProxyOptions();
            proxyOptions.setHost(getCommand(m_cmd_proxy_host));
            proxyOptions.setPort(proxyPort);
            builder.withHttpProxyOptions(proxyOptions);
        }
        builder.withWebsockets(true);
        builder.withWebsocketSigningRegion(getCommandRequired(m_cmd_signing_region, ""));
        TlsContextOptions x509TlsOptions = TlsContextOptions.createWithMtlsFromPath(getCommandRequired(m_cmd_x509_cert_file, ""), getCommandRequired(m_cmd_x509_key_file, ""));
        if (hasCommand(m_cmd_x509_ca_file)) {
            x509TlsOptions.withCertificateAuthorityFromPath(null, getCommand(m_cmd_x509_ca_file));
        }
        ClientTlsContext x509TlsContext = new ClientTlsContext(x509TlsOptions);
        X509CredentialsProvider.X509CredentialsProviderBuilder x509builder = new X509CredentialsProvider.X509CredentialsProviderBuilder().withTlsContext(x509TlsContext).withEndpoint(getCommandRequired(m_cmd_x509_endpoint, "")).withRoleAlias(getCommandRequired(m_cmd_x509_role, "")).withThingName(getCommandRequired(m_cmd_x509_thing_name, "")).withProxyOptions(proxyOptions);
        X509CredentialsProvider provider = x509builder.build();
        builder.withWebsocketCredentialsProvider(provider);
        return builder.build();
    } catch (CrtRuntimeException ex) {
        return null;
    }
}
Also used : HttpProxyOptions(software.amazon.awssdk.crt.http.HttpProxyOptions) AwsIotMqttConnectionBuilder(software.amazon.awssdk.iot.AwsIotMqttConnectionBuilder) X509CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.X509CredentialsProvider)

Example 10 with HttpProxyOptions

use of software.amazon.awssdk.crt.http.HttpProxyOptions in project aws-iot-device-sdk-java-v2 by aws.

the class CommandLineOption method buildConnectionSetupProxyDefaults.

private void buildConnectionSetupProxyDefaults(AwsIotMqttConnectionBuilder builder) {
    int proxyPort = Integer.parseInt(getCommandOrDefault(m_cmd_proxy_port, "0"));
    if (hasCommand(m_cmd_proxy_host) && proxyPort > 0) {
        HttpProxyOptions proxyOptions = new HttpProxyOptions();
        proxyOptions.setHost(getCommand(m_cmd_proxy_host));
        proxyOptions.setPort(proxyPort);
        builder.withHttpProxyOptions(proxyOptions);
    }
}
Also used : HttpProxyOptions(software.amazon.awssdk.crt.http.HttpProxyOptions)

Aggregations

HttpProxyOptions (software.amazon.awssdk.crt.http.HttpProxyOptions)10 ClientTlsContext (software.amazon.awssdk.crt.io.ClientTlsContext)4 ClientBootstrap (software.amazon.awssdk.crt.io.ClientBootstrap)3 EventLoopGroup (software.amazon.awssdk.crt.io.EventLoopGroup)3 HostResolver (software.amazon.awssdk.crt.io.HostResolver)3 TlsContext (software.amazon.awssdk.crt.io.TlsContext)3 X509CredentialsProvider (software.amazon.awssdk.crt.auth.credentials.X509CredentialsProvider)2 File (java.io.File)1 ExecutionException (java.util.concurrent.ExecutionException)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.jupiter.api.Test)1 CrtRuntimeException (software.amazon.awssdk.crt.CrtRuntimeException)1 HttpClientConnectionManagerOptions (software.amazon.awssdk.crt.http.HttpClientConnectionManagerOptions)1 SocketOptions (software.amazon.awssdk.crt.io.SocketOptions)1 MqttClient (software.amazon.awssdk.crt.mqtt.MqttClient)1 MqttClientConnection (software.amazon.awssdk.crt.mqtt.MqttClientConnection)1 MqttConnectionConfig (software.amazon.awssdk.crt.mqtt.MqttConnectionConfig)1 AwsIotMqttConnectionBuilder (software.amazon.awssdk.iot.AwsIotMqttConnectionBuilder)1 DiscoveryClient (software.amazon.awssdk.iot.discovery.DiscoveryClient)1 DiscoveryClientConfig (software.amazon.awssdk.iot.discovery.DiscoveryClientConfig)1