Search in sources :

Example 1 with WebProxyData

use of code.satyagraha.gfm.support.api.WebProxyConfig.WebProxyData in project gfm_viewer by satyagraha.

the class WebProxyConfigTest method shouldHandleNoMatchingProxy.

@Test
public void shouldHandleNoMatchingProxy() throws Exception {
    // given
    URI uri = new URI("http://www.test");
    given(proxyService.select(uri)).willReturn(proxyDataListEmpty);
    // when
    WebProxyData webProxyData = webProxyConfig.getWebProxyData(uri);
    // then
    assertThat(webProxyData, nullValue());
}
Also used : WebProxyData(code.satyagraha.gfm.support.api.WebProxyConfig.WebProxyData) URI(java.net.URI) Test(org.junit.Test)

Example 2 with WebProxyData

use of code.satyagraha.gfm.support.api.WebProxyConfig.WebProxyData in project gfm_viewer by satyagraha.

the class WebServiceClientDefault method getClient.

private Client getClient(String endpoint) {
    // set up standard properties
    DefaultApacheHttpClient4Config clientConfig = new DefaultApacheHttpClient4Config();
    Map<String, Object> clientProperties = clientConfig.getProperties();
    clientProperties.put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
    clientConfig.getClasses().addAll(ConnUtilities.getJerseyProviders());
    // see if proxy needed
    URI uri;
    try {
        uri = new URI(endpoint);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    WebProxyData webProxyData = webProxyConfig.getWebProxyData(uri);
    if (webProxyData != null) {
        if (webProxyData.getProxyUri() != null) {
            clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_PROXY_URI, webProxyData.getProxyUri());
            if (webProxyData.getUserId() != null) {
                clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_PROXY_USERNAME, webProxyData.getUserId());
                if (webProxyData.getPassword() != null) {
                    clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD, webProxyData.getPassword());
                }
            }
        }
    }
    // set up client properties
    clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, connectionManager);
    LOGGER.fine("clientProperties(): " + clientProperties);
    // build client
    Client client = ApacheHttpClient4.create(clientConfig);
    return client;
}
Also used : DefaultApacheHttpClient4Config(com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config) WebProxyData(code.satyagraha.gfm.support.api.WebProxyConfig.WebProxyData) URISyntaxException(java.net.URISyntaxException) Client(com.sun.jersey.api.client.Client) WebServiceClient(code.satyagraha.gfm.support.api.WebServiceClient) URI(java.net.URI)

Example 3 with WebProxyData

use of code.satyagraha.gfm.support.api.WebProxyConfig.WebProxyData in project gfm_viewer by satyagraha.

the class WebProxyConfigTest method shouldHandleMatchingProxy.

@Test
public void shouldHandleMatchingProxy() throws Exception {
    // given
    given(proxyData.getType()).willReturn(HTTP_PROXY_TYPE);
    String proxyHost = "proxyHost";
    given(proxyData.getHost()).willReturn(proxyHost);
    int proxyPort = 1234;
    given(proxyData.getPort()).willReturn(proxyPort);
    String userid = "userid";
    given(proxyData.getUserId()).willReturn(userid);
    String password = "password";
    given(proxyData.getPassword()).willReturn(password);
    URI uri = new URI("http://www.test");
    given(proxyService.select(uri)).willReturn(proxyDataListOne);
    // when
    WebProxyData webProxyData = webProxyConfig.getWebProxyData(uri);
    // then
    assertThat(webProxyData, notNullValue());
    URI proxyUri = new URI(webProxyData.getProxyUri());
    assertThat(proxyUri.getHost(), is(proxyHost));
    assertThat(proxyUri.getPort(), is(proxyPort));
    assertThat(webProxyData.getUserId(), is(userid));
    assertThat(webProxyData.getPassword(), is(password));
}
Also used : WebProxyData(code.satyagraha.gfm.support.api.WebProxyConfig.WebProxyData) URI(java.net.URI) Test(org.junit.Test)

Aggregations

WebProxyData (code.satyagraha.gfm.support.api.WebProxyConfig.WebProxyData)3 URI (java.net.URI)3 Test (org.junit.Test)2 WebServiceClient (code.satyagraha.gfm.support.api.WebServiceClient)1 Client (com.sun.jersey.api.client.Client)1 DefaultApacheHttpClient4Config (com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config)1 URISyntaxException (java.net.URISyntaxException)1