Hi, one additional help. I tried to use the HttpAsyncClient to do upload via
SSL&Proxy. Everything works great, except I have to use host name. If I use IP
address, I got exception. Could you please help to see anything I did wrong?
How to get around it? THX.
Code snip:
HttpAsyncClient httpclient = new DefaultHttpAsyncClient();
HttpHost proxy = new HttpHost("10.97.196.145", 3128, "http");
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new X509TrustManager[]{new X509TrustManager(){
public void
checkClientTrusted(X509Certificate[] chain, String authType){;}
public void
checkServerTrusted(X509Certificate[] chain, String authType){;}
public X509Certificate[] getAcceptedIssuers()
{ return new X509Certificate[0];}
}},
null);
//the allow all host name seems have no effect here
SSLLayeringStrategy sslLS = new SSLLayeringStrategy(ctx, new
AllowAllHostnameVerifier());
AsyncScheme sch = new AsyncScheme("https", 8443, sslLS);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
httpclient.start();
try {
//will work if changed to host name
String url = "https://10.97.196.123:8443/cfcc/t.jsp";
HttpUriRequest hp = new HttpPost(url);
StringEntity se = new StringEntity("my
dataddddddddddddddddddddddddddd");
((HttpPost)hp).setEntity(se);
Future<Boolean> future = httpclient.execute(
HttpAsyncMethods.create(hp), new MyResponseConsumer(), null);
Boolean result = future.get();
if (result != null && result.booleanValue()) {
System.out.println("Request successfully executed");
} else {
System.out.println("Request failed");
}
System.out.println("Shutting down");
} finally {
httpclient.shutdown();
}
Exception if using IP address:
Exception in thread "main" java.util.concurrent.ExecutionException:
org.apache.http.ProtocolException: Invalid request U
RI: 10.97.196.123:8443
at org.apache.http.concurrent.BasicFuture.getResult(BasicFuture.java:61)
at org.apache.http.concurrent.BasicFuture.get(BasicFuture.java:70)
at
AsyncClientHttpExchangeStreaming.main(AsyncClientHttpExchangeStreaming.java:124)
Caused by: org.apache.http.ProtocolException: Invalid request URI:
10.97.196.123:8443
at
org.apache.http.impl.client.RequestWrapper.<init>(RequestWrapper.java:83)
at
org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.wrapRequest(DefaultAsyncRequestDirector.java:560)
at
org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.generateRequest(DefaultAsyncRequestDirector.java:
206)
at
org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.requestReady(HttpAsyncClientProtocolHandler.java:
113)
at
org.apache.http.impl.nio.client.LoggingClientProtocolHandler.requestReady(LoggingClientProtocolHandler.java:9
0)
at
org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.connected(HttpAsyncClientProtocolHandler.java:65)
at
org.apache.http.impl.nio.client.LoggingClientProtocolHandler.connected(LoggingClientProtocolHandler.java:58)
at
org.apache.http.impl.nio.DefaultClientIODispatch.onConnected(DefaultClientIODispatch.java:103)
at
org.apache.http.impl.nio.DefaultClientIODispatch.onConnected(DefaultClientIODispatch.java:49)
at
org.apache.http.impl.nio.AbstractIODispatch.connected(AbstractIODispatch.java:76)
at
org.apache.http.impl.nio.reactor.BaseIOReactor.sessionCreated(BaseIOReactor.java:252)
at
org.apache.http.impl.nio.reactor.AbstractIOReactor.processNewChannels(AbstractIOReactor.java:427)
at
org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:291)
at
org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:106)
at
org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:59
9)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.URISyntaxException: Illegal character in scheme name at
index 0: 10.97.196.123:8443
at java.net.URI$Parser.fail(URI.java:2809)
at java.net.URI$Parser.checkChars(URI.java:2982)
at java.net.URI$Parser.checkChar(URI.java:2992)
at java.net.URI$Parser.parse(URI.java:3008)
at java.net.URI.<init>(URI.java:578)
at
org.apache.http.impl.client.RequestWrapper.<init>(RequestWrapper.java:81)
... 15 more
-----Original Message-----
From: Oleg Kalnichevski [mailto:[email protected]]
Sent: Wednesday, January 04, 2012 12:43 PM
To: HttpComponents Project
Subject: Re: httpcore nio SSL/proxy support
On Wed, Jan 04, 2012 at 04:59:34PM +0000, Yongjian Li wrote:
> Hi, thank you very much for your message. I didn't see GA version of
> HttpAsyncClient, I only see alpha3 build on download page. Is this the GA
> build? Or it is in HttpClient? THX.
>
There has been no GA release yes, as HttpAsyncClient is still considered API
unstable. It does not mean it is not usable, though.
Oleg
> -----Original Message-----
> From: Oleg Kalnichevski [mailto:[email protected]]
> Sent: Wednesday, January 04, 2012 11:47 AM
> To: [email protected]
> Subject: Re: httpcore nio SSL/proxy support
>
> On Wed, 2012-01-04 at 15:59 +0000, Yongjian Li wrote:
> > I read an old post that httpcore nio does not support SSL over proxy. Is
> > this addressed with the latest release? If not, could anyone help to give
> > me some hints what I need to overwrite so that I can get it working? THX.
> >
>
> If you want an asynchronous HTTP client based on HttpCore that supports SSL
> via proxy among other things, you should be using HttpAsyncClient.
>
> http://hc.apache.org/httpcomponents-asyncclient-dev/index.html
>
> Oleg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected] For additional
> commands, e-mail: [email protected]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected] For additional
> commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands,
e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]