|
Replies:
12
-
Last Post:
Apr 29, 2008 3:16 PM
by: scottrobey
|
|
|
|
|
|
|
how to get rid of absolute paths to WSDL in generated classes?
Posted:
Jun 29, 2007 2:41 AM
|
|
|
Hello,
I noticed that wsimport puts the location of the WSDL into the generated service class (...Service.java) as an *absolute* file URL (...SERVICE_WSDL_LOCATION).
This is of course a bad habit, since it will prevent these classes from running properly after the service has been deployed in a totally different environment where the WSDL is not present at this location or not present at all. For my application, this results in error messages like "Failed to access the WSDL at: file:/C:/..." whenever a SOAP fault is generated.
Can wsimport be prevented from doing this, and forced into using a web application context-relative reference (like /WEB-INF/wsdl/foobar.wsdl) instead?
|
|
|
|
|
|
|
Re: how to get rid of absolute paths to WSDL in generated classes?
Posted:
Jun 29, 2007 9:09 AM
in response to: teecee
|
|
|
You can use -wsdllocation option on wsimport to specify the location you want.
|
|
|
|
|
|
|
|
|
|
Re: how to get rid of absolute paths to WSDL in generated classes?
Posted:
Jun 30, 2007 5:01 PM
in response to: teecee
|
|
|
I use this method to use a specific URL instead of the hardcoded one.
public static <T extends javax.xml.ws.Service> T createService(Class<T> serviceClass, URL wsdlLocation) {
if (serviceClass == null) {
throw new IllegalArgumentException("Null service class");
}
if (wsdlLocation == null) {
throw new IllegalArgumentException("No location specified for: " + serviceClass);
}
WebServiceClient wsc = serviceClass.getAnnotation(WebServiceClient.class);
if (wsc == null) {
throw new RuntimeException("Class: " + serviceClass + " is not annotated with javax.xml.ws.WebServiceClient. " +
"Is it really a JAX-WS created class?");
}
QName qname = new QName(wsc.targetNamespace(), wsc.name());
try {
Constructor<T> constr = serviceClass.getConstructor(URL.class, QName.class);
return constr.newInstance(wsdlLocation, qname);
} catch (Exception e) {
throw new RuntimeException("Could not invoke constructor with URL: '" + wsdlLocation + "'", e);
}
}
I call it like this:
MyPort myPort = createService(MyService.class, myServiceURL).getMyPort();
Does that fit?
|
|
|
|
|
|
|
|
Re: how to get rid of absolute paths to WSDL in generated classes?
Posted:
Jul 1, 2007 7:59 AM
in response to: andreou
|
|
|
It might fit, however I must admit I wouldn't even know where to call this method explicitly (isn't that done behind the scenes for pure SEI use)?
I managed to solve my problem by using 2 catalog files, one used at build time (in order to have wsimport generate an abstract URL into the service class instead of an actual path), and one used at runtime (to enable JAX-WS to resolve that abstract URL to a path to the WSDL that's relative to /WEB-INF).
Anyway, thanks for your answers.
|
|
|
|
|
|
|
|
Re: how to get rid of absolute paths to WSDL in generated classes?
Posted:
Jul 1, 2007 8:31 AM
in response to: teecee
|
|
|
> isn't that done behind the scenes for pure SEI use? To get the interface of the services, using the default URL (that wsimport used), you would say:
new MyService().getMyPort();
The no-args constructor of the generated Service class uses the hardcoded constructor (that was given to wsimport). But there is a second constructor that takes a URL argument (and a QName). I just call that instead, to override the hardcoded URL, and build the QName by peeking the WebServiceClient annotation of the service class.
I wansn't even aware of this way: > I managed to solve my problem by using 2 catalog > files, one used at build time (in order to have > wsimport generate an abstract URL into the service > class instead of an actual path), and one used at > runtime (to enable JAX-WS to resolve that abstract > URL to a path to the WSDL that's relative to > /WEB-INF). > Do you have a pointer handy to this approach? Thanks
|
|
|
|
|
|
|
|
Re: how to get rid of absolute paths to WSDL in generated classes?
Posted:
Jul 1, 2007 8:55 AM
in response to: andreou
|
|
|
> To get the interface of the services, using the > default URL (that wsimport used), you would say: > new MyService().getMyPort();
Well on the server side (within the implementation class of the port), I'm not instantiating MyService explicitly at all, This is done by the framework, hence my question about where to call it. > I wansn't even aware of this way: > > I managed to solve my problem by using 2 catalog > > files, one used at build time (in order to have > > wsimport generate an abstract URL into the service > > class instead of an actual path), and one used at > > runtime (to enable JAX-WS to resolve that abstract > > URL to a path to the WSDL that's relative to > > /WEB-INF). > > > Do you have a pointer handy to this approach? Thanks
There's some terse but useful information here: https://jax-ws.dev.java.net/nonav/2.1.1/docs/catalog-support.html
In my case, what I did was setup a file jax-ws-catalog-build.xml that contains something like
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system"> <system systemId="http://my.namespace.url" uri="../../../relative/build/time/path/to/Service.wsdl"/> </catalog>
and pass the path to that file to the wsimport ant task:
<wsimport .... wsdl="http://my.namespace.url" catalog="jax-ws-catalog-build.xml" ... </w
The ant file also makes sure that Service.wsdl is copied to /WEB-INF during the build process.
The other catalog must be called jax-ws-catalog.xml and put into /WEB-INF. It looks like this:
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system"> <system systemId="http://my.namespace.url" uri="Service.wsdl"/> </catalog>
It will cause JAX-WS to pick up the wsdl from /WEB-INF if needed.
That's it.
|
|
|
|
|
|
|
|
Re: how to get rid of absolute paths to WSDL in generated classes?
Posted:
Jul 1, 2007 9:25 AM
in response to: teecee
|
|
|
Oh, thanks for the info.
Previously, I was actually referring to client-side code, and may have been totally irrelevant. It was just meant to use the generated stubs with an arbitrary location of the wsdl file apart the hardcoded one; but not for the server-side framework. I probably didn't read the initial question too carefully
|
|
|
|
|
|
|
|
|
|
Re: how to get rid of absolute paths to WSDL in generated classes?
Posted:
Apr 29, 2008 3:16 PM
in response to: teecee
|
|
|
I had the same problem, on the server side and used your approach of using 2 catalog files (one for build-time resolution of the wsdl, the other for runtime resolution of the wsdl). It worked great as long as I had only 1 application deployed to the container (Tomcat 6.0 in this case) that used the systemId.
If I deployed 2 applications that use http://my.namespace.url with the same relative path to the wsdl, the first application that gets loaded resolves the WSDL location fine, but the 2nd application gets the following error: com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
java.net.UnknownHostException: my.namespace.url java.net.UnknownHostException: my.namespace.url
In my case, both applications have a jax-ws -catalog.xml with the same contents. I'm confused as to why the 2 applications are interfering with each other if the catalog file is put into the application's WEB-INF directory.
I've worked around the problem for now by putting all of the JAX-WS jars into the applications' war file instead of Tomcat's server/lib directory, but I'd rather solve the problem long term in a different way.
Any help is appreciated.
|
|
|
|
|
|
|
|
Re: how to get rid of absolute paths to WSDL in generated classes?
Posted:
Dec 17, 2007 6:49 AM
in response to: andreou
|
|
|
Hi, just a note to say that your method for getting a QName helped me out. I think it should be a method (static or not) of the generated service class.
Note that there's a builder with no parameters, and a builder with two parameters (url & qname). Where's the builder with each of the parameters? Sometimes would be useful...
JRobinss
|
|
|
|
|
|
|
|
Re: how to get rid of absolute paths to WSDL in generated classes?
Posted:
Jul 1, 2007 1:09 PM
in response to: teecee
|
|
|
Hi all I am looking for an almost same thing. we have some wsdl which thier address changes frequenty and we want to avoid hard coding the address into the generated class.
we want our compiled application to work fine after we provide the correct ip address to it.
does any one know how we can call the web service without using netbeans generated classes?
thanks
|
|
|
|
|