CXF generates java code with annotations like this:

@WebServiceClient(name = "XyzService",
                   wsdlLocation = "file:///path/to/XyzService.wsdl",
                   targetNamespace = "http://xyz.com/";)
public class XyzService extends Service {

   public final static URL WSDL_LOCATION;
public final static QName SERVICE = new QName("http://xyz.com/";, "XyzService"); public final static QName EmergencyProvisioningPort = new QName("http://xyz.com/";, "XyzPort");
   static {
       URL url = null;
       try {
           url = new URL("file:///path/to/XyzService.wsdl");
       } catch (MalformedURLException e) {
System.err.println("Can not initialize the default wsdl from file:///path/to/XyzService.wsdl");
           // e.printStackTrace();
       }
       WSDL_LOCATION = url;
   }
...
}

Note that the file URL file:///path/to/XyzService.wsdl is repeated three times by the generator in different contexts and its reference comes from the machine where the generator was run.

But suppose I want to write a JUnit test, say, that tests the client I am building, and let's further suppose that I want to run that test on different machines, perhaps even on Linux and Windows machines. I will have to modify the generated code, but I am not aware of any file:// URL that could be correctly interpreted on both linux and windows unless I do something ugly like create a /C: directory in linux. If I wanted to make a requirement that no machine could run this code that did not have working web server on it, then I could use an http://localhost URL instead, but that is also not optimal.


Is there some way to have the generator create more portable code than this? And if not, and I am forced to modify generated code, is there any possible file:// URL that will work cross-platform?


Reply via email to