I have to call a WS that requires custom client authentication. This authentication is done by a program running on the client and listening on http://127.0.0.1:80. So I add a ProxySelector when starting up like this :
final ProxySelector ps = new ProxySelector() {
@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
ioe.printStackTrace();
}
@Override
public List<Proxy> select(URI uri) {
final List<Proxy> proxy = new ArrayList<Proxy>();
final SocketAddress adr = new InetSocketAddress("127.0.0.1", 80);
final Proxy p = new Proxy(Proxy.Type.HTTP, adr);
proxy.add(p);
return proxy;
};
ProxySelector.setDefault(ps);
This use to work fine, but after some refactoring (not related to WS calls), instead of having http://my.server.com as URI input, I have socket://my.server.com and it fails with a "Unknown proxy type : HTTP", what seems quite normal with SOCKET scheme...
The difference between my old application and the new one is the behavior during HttpUrlConnection.plainConnect开发者_如何学C() was not the same. Indeed, the working version calls my ProxySelector with the right URI (line 922 of http://www.docjar.com/html/api/sun/net/www/protocol/http/HttpURLConnection.java.html), whereas the new version jump to line 959 and start creating a new underlying connection, which ends up with a socket:// scheme.
So the difference lies in following lines :
ProxySelector sel =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<ProxySelector>() {
public ProxySelector run() {
return ProxySelector.getDefault();
}
});
This used to return my ProxySelector as "sel" but now returns null.
Can someone explain me what exactly means these lines, and why the result is not the same than in my old app ?
Eventually, I figured this out !
The jaxws-maven-plugin used to generate WS client was in version 1.10 in the working application, and changed to 1.12 in the new one, what introduced the changes in HttpUrlConnection as explained above.
Still don't know what happened, and which dependent library has changed between 1.10 and 1.12 but there is a quite BIG difference in the way of creating HttpConnections :)
Thanks anyway for those who read my weird question... ^^
精彩评论