Eric Vernier created CXF-8248:
---------------------------------
Summary: Root cause eaten when hostname rejected by the parser of
URI.
Key: CXF-8248
URL: https://issues.apache.org/jira/browse/CXF-8248
Project: CXF
Issue Type: Bug
Components: Transports
Affects Versions: 3.2.8
Reporter: Eric Vernier
I'm using CXF (3.2.8 a bit old but the involved code seems always the same on
master) to access the SOAP WebService WinRM on Windows Servers with the lib
[WinRM4J|https://github.com/cloudsoft/winrm4j] which use the
org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit.
I saw that the underscore character is not allowed in hostname (as describe in
[RFC 2396|http://www.ietf.org/rfc/rfc2396.txt]) but in the Active Directory DNS
you can use underscore, so here in our private Cloud AzurePack it's possible to
create a VM with an underscore in its hostname.
When the WebService on a such VM is accessed the following exception is thrown :
{code}
java.lang.IllegalStateException: Buffer already closed for writing
at
org.apache.cxf.transport.http.asyncclient.SharedOutputBuffer.write(SharedOutputBuffer.java:229)
at
org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit$AsyncWrappedOutputStream$1.write(AsyncHTTPConduit.java:436)
at
org.apache.cxf.io.CacheAndWriteOutputStream.write(CacheAndWriteOutputStream.java:80)
at java.io.ByteArrayOutputStream.writeTo(ByteArrayOutputStream.java:167)
at
org.apache.cxf.io.CachedOutputStream.writeCacheTo(CachedOutputStream.java:314)
at
org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit$AsyncWrappedOutputStream.close(AsyncHTTPConduit.java:415)
at
org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:673)
at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:63)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:531)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:440)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:355)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:140)
at com.sun.proxy.$Proxy212.create(Unknown Source)
at sun.reflect.GeneratedMethodAccessor447.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at
io.cloudsoft.winrm4j.client.RetryingProxyHandler.invokeWithRetry(RetryingProxyHandler.java:46)
at
io.cloudsoft.winrm4j.client.RetryingProxyHandler.invoke(RetryingProxyHandler.java:34)
at com.sun.proxy.$Proxy213.create(Unknown Source)
at
io.cloudsoft.winrm4j.client.WinRmClient.createShell(WinRmClient.java:485)
at
io.cloudsoft.winrm4j.winrm.WinRmTool.executeCommand(WinRmTool.java:335)
at
com.carl.remote.winrm.WinrmConnection.execute(WinrmConnection.java:88)
{code}
It's not the root cause, so it's a bit difficult to find out the problem.
The root cause is in fact an {{IllegalArgumentException: Host name may not be
null}} thrown by the
[HttpHost|https://github.com/apache/httpcomponents-core/blob/rel/v4.4.4/httpcore/src/main/java/org/apache/http/HttpHost.java#L80]
when it's instanciated by
[​CXFHttpAsyncRequestProducer#getTarget()|https://github.com/apache/cxf/blob/cxf-3.2.8/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncRequestProducer.java#L62].
The hostname is null because the parsing do by the java.net.URI reject the
underscore (but doesn't thrown an URISyntaxException).
I have managed a workaround (you can see it on this branch
https://github.com/zerikv/cxf/commits/fix-lost-exception-hostname-with-underscore)
at the end of the {{connect()}} method in the inner class
{{AsyncWrappedOutputStream}} of
[AsyncHTTPConduit|https://github.com/apache/cxf/blob/cxf-3.2.8/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java#L584]
so that {{IllegalArgumentException}} now goes back to the user.
It's not even the real root cause but I think it's a little better than the
{{Buffer already closed for writing}} message, at least it indicates that
something is wrong with the hostname.
For my initial problem (accept the hostnames with underscore because they exist
I have meet them) the only solution I can find would be to replace the URI with
the URL, but I guess it's not really an option.
If someone see another way thank for advices.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)