Search in sources :

Example 1 with Communicator

use of com.ingenico.connect.gateway.sdk.java.Communicator in project connect-sdk-java by Ingenico-ePayments.

the class SDKProxyTest method assertProxySet.

@SuppressWarnings("resource")
private void assertProxySet(ApiResource resource, ProxyConfiguration proxyConfiguration) {
    Communicator communicator = getField(resource, "communicator", Communicator.class);
    Session session = getField(communicator, "session", Session.class);
    DefaultConnection connection = getField(session, "connection", DefaultConnection.class);
    CloseableHttpClient httpClient = getField(connection, "httpClient", CloseableHttpClient.class);
    DefaultProxyRoutePlanner routePlanner = getField(httpClient, "routePlanner", DefaultProxyRoutePlanner.class);
    HttpHost proxy = getField(routePlanner, "proxy", HttpHost.class);
    Assert.assertEquals(proxyConfiguration.getScheme(), proxy.getSchemeName());
    Assert.assertEquals(proxyConfiguration.getPort(), proxy.getPort());
    BasicCredentialsProvider credentialsProvider = getField(httpClient, "credentialsProvider", BasicCredentialsProvider.class);
    AuthScope authScope = new AuthScope(proxy);
    Credentials credentials = credentialsProvider.getCredentials(authScope);
    Assert.assertTrue(credentials instanceof UsernamePasswordCredentials);
    UsernamePasswordCredentials usernamePasswordCredentials = (UsernamePasswordCredentials) credentials;
    Assert.assertEquals(proxyConfiguration.getUsername(), usernamePasswordCredentials.getUserName());
    Assert.assertEquals(proxyConfiguration.getPassword(), usernamePasswordCredentials.getPassword());
}
Also used : Communicator(com.ingenico.connect.gateway.sdk.java.Communicator) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) DefaultConnection(com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultConnection) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) DefaultProxyRoutePlanner(org.apache.http.impl.conn.DefaultProxyRoutePlanner) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Credentials(org.apache.http.auth.Credentials) Session(com.ingenico.connect.gateway.sdk.java.Session) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with Communicator

use of com.ingenico.connect.gateway.sdk.java.Communicator in project connect-sdk-java by Ingenico-ePayments.

the class ConnectionPoolingTest method testConnectionPooling.

private void testConnectionPooling(int requestCount, int maxConnections) throws Exception {
    ExecutorService executorService = Executors.newFixedThreadPool(requestCount);
    try {
        CommunicatorConfiguration configuration = getCommunicatorConfiguration().withMaxConnections(maxConnections);
        Communicator communicator = Factory.createCommunicator(configuration);
        try {
            testConnectionPooling(executorService, communicator, requestCount);
        } finally {
            communicator.close();
        }
    } finally {
        executorService.shutdown();
    }
}
Also used : Communicator(com.ingenico.connect.gateway.sdk.java.Communicator) ExecutorService(java.util.concurrent.ExecutorService) CommunicatorConfiguration(com.ingenico.connect.gateway.sdk.java.CommunicatorConfiguration)

Example 3 with Communicator

use of com.ingenico.connect.gateway.sdk.java.Communicator in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnectionLoggerTest method createClient.

@SuppressWarnings("resource")
private Client createClient(HttpHost host, int connectTimeout, int socketTimeout) throws URISyntaxException {
    URI uri = new URI(host.getSchemeName(), null, host.getHostName(), host.getPort(), null, null, null);
    Connection connection = new DefaultConnection(connectTimeout, socketTimeout);
    Authenticator authenticator = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKey", "secret");
    MetaDataProvider metaDataProvider = new MetaDataProvider("Ingenico");
    Session session = new Session(uri, connection, authenticator, metaDataProvider);
    Communicator communicator = Factory.createCommunicator(session);
    Client client = Factory.createClient(communicator);
    return client;
}
Also used : MetaDataProvider(com.ingenico.connect.gateway.sdk.java.MetaDataProvider) Communicator(com.ingenico.connect.gateway.sdk.java.Communicator) Connection(com.ingenico.connect.gateway.sdk.java.Connection) TestConnection(com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection) Client(com.ingenico.connect.gateway.sdk.java.Client) URI(java.net.URI) Authenticator(com.ingenico.connect.gateway.sdk.java.Authenticator) Session(com.ingenico.connect.gateway.sdk.java.Session)

Example 4 with Communicator

use of com.ingenico.connect.gateway.sdk.java.Communicator in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnectionIdempotenceTest method createClient.

@SuppressWarnings("resource")
private Client createClient(HttpHost host) {
    Connection connection = new DefaultConnection(500, 500);
    Authenticator authenticator = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKey", "secret");
    MetaDataProvider metaDataProvider = new MetaDataProvider("Ingenico");
    Session session = new Session(URI.create(host.toURI()), connection, authenticator, metaDataProvider);
    Communicator communicator = Factory.createCommunicator(session);
    Client client = Factory.createClient(communicator);
    return client;
}
Also used : MetaDataProvider(com.ingenico.connect.gateway.sdk.java.MetaDataProvider) Communicator(com.ingenico.connect.gateway.sdk.java.Communicator) Connection(com.ingenico.connect.gateway.sdk.java.Connection) Client(com.ingenico.connect.gateway.sdk.java.Client) Authenticator(com.ingenico.connect.gateway.sdk.java.Authenticator) Session(com.ingenico.connect.gateway.sdk.java.Session)

Aggregations

Communicator (com.ingenico.connect.gateway.sdk.java.Communicator)4 Session (com.ingenico.connect.gateway.sdk.java.Session)3 Authenticator (com.ingenico.connect.gateway.sdk.java.Authenticator)2 Client (com.ingenico.connect.gateway.sdk.java.Client)2 Connection (com.ingenico.connect.gateway.sdk.java.Connection)2 MetaDataProvider (com.ingenico.connect.gateway.sdk.java.MetaDataProvider)2 CommunicatorConfiguration (com.ingenico.connect.gateway.sdk.java.CommunicatorConfiguration)1 DefaultConnection (com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultConnection)1 TestConnection (com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection)1 URI (java.net.URI)1 ExecutorService (java.util.concurrent.ExecutorService)1 HttpHost (org.apache.http.HttpHost)1 AuthScope (org.apache.http.auth.AuthScope)1 Credentials (org.apache.http.auth.Credentials)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 DefaultProxyRoutePlanner (org.apache.http.impl.conn.DefaultProxyRoutePlanner)1