I am trying to fetch a resource using the camel-http component and I am
running my application behind a proxy server who uses NTLM for
authentication.
Each time I try to connect it gives an I/O Exception, see error below:
17:18:29,747 | INFO | Service-thread-2 | HttpMethodDirector
|
ns.httpclient.HttpMethodDirector 439 | I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
17:18:29,747 | INFO | Service-thread-2 | HttpMethodDirector
|
ns.httpclient.HttpMethodDirector 445 | Retrying request
17:18:30,779 | INFO | Service-thread-2 | HttpMethodDirector
|
ns.httpclient.HttpMethodDirector 439 | I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
17:18:30,779 | INFO | Service-thread-2 | HttpMethodDirector
|
ns.httpclient.HttpMethodDirector 445 | Retrying request
17:18:31,795 | INFO | Service-thread-2 | HttpMethodDirector
|
ns.httpclient.HttpMethodDirector 439 | I/O exception
(java.net.ConnectException) caught when processing request: Connection
refused: connect
17:18:31,795 | INFO | Service-thread-2 | HttpMethodDirector
|
ns.httpclient.HttpMethodDirector 445 | Retrying request
17:18:32,843 | ERROR | Service-thread-2 | DefaultErrorHandler
|
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
See snippet:
<bean id="http" class="org.apache.camel.component.http.HttpComponent">
<property name="camelContext" ref="camel"/>
<property name="httpClientConfigurer" ref="myHTTPClientConfigurer"/>
</bean>
<bean id="myHTTPClientConfigurer"
class="com.interswitchng.techquest.nmr_aero_http_provider_bundle.MyHttpClientConfigurer">
<property name="sslPort" value="443"/>
<property name="keystore" value="${keystore-file}"/>
<property name="keystorePassword" value="${keystore-password}"/>
<property name="truststore" value="${keystore-file}"/>
<property name="truststorePassword" value="${keystore-password}"/>
<property name="keyPassword" value="${key-password}"/>
<property name="proxyHost" value="${proxy-ip}"/>
<property name="proxyPort" value="${proxy-port}"/>
<property name="proxyUsername" value="${proxy-username}"/>
<property name="proxyPassword" value="${proxy-password}"/>
<property name="domain" value="${proxy-domain}"/>
</bean>
<osgi:camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring"
trace="true">
<endpoint id="httpEndpoint"
uri="${aero-webservice-url}?username=${auth-username}&password=${auth-password}&httpClient.authenticationPreemptive=true"/>
<route>
<from uri="nmr:aeroHTTPService"/>
<setHeader
headerName="CamelHttpMethod"><constant>POST</constant></setHeader>
<transform><simple>XML=${in.body}</simple></transform>
<setHeader
headerName="CamelHttpQuery"><simple>${in.body}</simple></setHeader>
<to ref="httpEndpoint"/>
</route>
</osgi:camelContext>
Below is MyHttpClientConfigurer:
public void configureHttpClient(HttpClient httpClient)
{
ProtocolSocketFactory protocolSocketFactory = null;
try
{
protocolSocketFactory = new SSLProtocolSocketFactory();
System.setProperty("javax.net.ssl.keyStore", keystore);
System.setProperty("javax.net.ssl.keyStorePassword",
keystorePassword);
System.setProperty("javax.net.ssl.trustStore", truststore);
System.setProperty("javax.net.ssl.trustStorePassword",
truststorePassword);
System.setProperty("javax.net.ssl.keyPassword",
keyPassword);
HostConfiguration hostConfiguration =
httpClient.getHostConfiguration();
hostConfiguration.setProxy(proxyHost, proxyPort);
HttpState httpState = httpClient.getState();
AuthScope authscope = new AuthScope(null, proxyPort, null);
Credentials credentials = new NTCredentials(proxyUsername,
proxyPassword, "", domain);
httpState.setProxyCredentials(authscope, credentials);
List authPrefs = new ArrayList();
authPrefs.add(AuthPolicy.NTLM);
// Credentials credentials = new
UsernamePasswordCredentials(proxyUsername, proxyPassword);
// httpState.setProxyCredentials(authscope, credentials);
HttpClientParams httpClientParams = httpClient.getParams();
httpClientParams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
authPrefs);
}
catch (Exception e)
{
e.printStackTrace();
}
Protocol protocol = new Protocol("https", protocolSocketFactory,
sslPort);
Protocol.registerProtocol("https", protocol);
}
WHat am I doing wrong/