Search in sources :

Example 1 with Session

use of com.ingenico.connect.gateway.sdk.java.Session 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 Session

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

the class MultiLineHeaderTest method test.

/**
 * Smoke test for products service.
 */
@Test
public void test() throws URISyntaxException, IOException {
    CommunicatorConfiguration configuration = getCommunicatorConfiguration();
    String multiLineHeader = " some value  \r\n \n with  some \r\n  spaces ";
    MetaDataProvider metaDataProvider = new MetaDataProviderBuilder("Ingenico").withAdditionalRequestHeader(new RequestHeader("X-GCS-MultiLineHeader", multiLineHeader)).build();
    DirectoryParams params = new DirectoryParams();
    params.setCountryCode("NL");
    params.setCurrencyCode("EUR");
    Session session = Factory.createSessionBuilder(configuration).withMetaDataProvider(metaDataProvider).build();
    Client client = Factory.createClient(session);
    try {
        Directory response = client.merchant("8500").products().directory(809, params);
        Assert.assertTrue(response.getEntries().size() > 0);
    } finally {
        client.close();
    }
}
Also used : MetaDataProvider(com.ingenico.connect.gateway.sdk.java.MetaDataProvider) MetaDataProviderBuilder(com.ingenico.connect.gateway.sdk.java.MetaDataProviderBuilder) DirectoryParams(com.ingenico.connect.gateway.sdk.java.merchant.products.DirectoryParams) RequestHeader(com.ingenico.connect.gateway.sdk.java.RequestHeader) CommunicatorConfiguration(com.ingenico.connect.gateway.sdk.java.CommunicatorConfiguration) Client(com.ingenico.connect.gateway.sdk.java.Client) Session(com.ingenico.connect.gateway.sdk.java.Session) Directory(com.ingenico.connect.gateway.sdk.java.domain.product.Directory) Test(org.junit.Test)

Example 3 with Session

use of com.ingenico.connect.gateway.sdk.java.Session 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 Session

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

the class PaymentsClientTest method initializeSession.

@Before
public void initializeSession() {
    URI apiEndpoint = URI.create("http://localhost");
    session = new Session(apiEndpoint, connection, new DefaultAuthenticator(AuthorizationType.V1HMAC, "test", "test"), new MetaDataProvider("Ingenico"));
}
Also used : MetaDataProvider(com.ingenico.connect.gateway.sdk.java.MetaDataProvider) DefaultAuthenticator(com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultAuthenticator) URI(java.net.URI) Session(com.ingenico.connect.gateway.sdk.java.Session) Before(org.junit.Before)

Example 5 with Session

use of com.ingenico.connect.gateway.sdk.java.Session 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

Session (com.ingenico.connect.gateway.sdk.java.Session)5 MetaDataProvider (com.ingenico.connect.gateway.sdk.java.MetaDataProvider)4 Client (com.ingenico.connect.gateway.sdk.java.Client)3 Communicator (com.ingenico.connect.gateway.sdk.java.Communicator)3 Authenticator (com.ingenico.connect.gateway.sdk.java.Authenticator)2 Connection (com.ingenico.connect.gateway.sdk.java.Connection)2 URI (java.net.URI)2 CommunicatorConfiguration (com.ingenico.connect.gateway.sdk.java.CommunicatorConfiguration)1 MetaDataProviderBuilder (com.ingenico.connect.gateway.sdk.java.MetaDataProviderBuilder)1 RequestHeader (com.ingenico.connect.gateway.sdk.java.RequestHeader)1 DefaultAuthenticator (com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultAuthenticator)1 DefaultConnection (com.ingenico.connect.gateway.sdk.java.defaultimpl.DefaultConnection)1 Directory (com.ingenico.connect.gateway.sdk.java.domain.product.Directory)1 TestConnection (com.ingenico.connect.gateway.sdk.java.domain.services.TestConnection)1 DirectoryParams (com.ingenico.connect.gateway.sdk.java.merchant.products.DirectoryParams)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