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());
}
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;
}
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));
}
Aggregations