The scenario is trying to access wsdl file from remote service provider using URL as "http://localhost:9083/TestWeb/HelloService?wsdl". The remote service redirect the request to URL "http://localhost:9083/TestWeb/HelloService/HelloService.wsdl".
I turned on AutoRedirect by calling method "HTTPClientPolicy.setAutoRedirect(true)" in CXF. The auto redirection works and WSDL file is loaded successfully.
However, inside of the WSDL file it imports another XSD schema file which is in the same folder as WSDL file on remote server.
<xsd:import namespace="http://hello.jaxws.sample.com/" schemaLocation="HelloService_schema1.xsd"/>
CXF tries to load this XSD file, but it use the original URL "http://localhost:9083/TestWeb/HelloService?wsdl" as base URI, and got the wrong target address as "http://localhost:9083/TestWeb/HelloService_schema1.xsd". Obviously it failed since the XSD file is not there.
Actually if CXF use the new URL after auto redirect as base URI, it will get the correct URL for XSD file, in this case it should be "http://localhost:9083/TestWeb/HelloService/HelloService_schema1.xsd".
In method TransportURIResolver.resolve(String curUri, String baseUri):
InputStream ins = exch.get(InputStream.class);
InputSource src = new InputSource(ins);
lastestImportUri = base.toString();
The actual redirect happens in method HTTPConduit.redirectRetransmit(...) when "c.close(message)" above is invoked. However TransportURIResolver has no idea if redirect happens or not. So it still save the original URI (the variable base) to publicId and systemId and lastestImportUri. Later when it tries to get XSD file these info will be used as base URI.
To resolve this problem I suggest we get the new URL after redirect, and save it as publicId, systemId, or lastestImportUri. And use it as future base URI.
Per my investigation the new URL after redirect can be retrieved from message object:
java.net.HttpURLConnection conn = (java.net.HttpURLConnection)message.get("http.connection");
String newURL = conn.getURL().toURI().toString();
The problem is at this place it does not know if redirect happened or not. If it does not happen, the returned URL should be the same as original base URI.
Could somebody help to review this logic please? Is there any object for this proposed change? Any suggestion are welcome. Thank you!