How do I specify the url in the JAX-WS call and avoid the initial network connection?
I am using standard JAX-WS s wsimport http://localhost/Order.wsdl
to create client stub classes.
The live web service is on a different host, so I need to specify the url when calling the service. My approach so far has been this (the classes below are generated from wsimport):
1. OrderService s = new OrderService (
new URL("https://live/WS/Order"),
new QName(...));
2. OrderServicePort port = s.getOrderServicePort();
3. configureHttpCertificatesStuff(port) // Set up ssl stuff with the port
4. port.placeOrder(args); // The actual ws call
First: Is this the correct way to specify the URL?
Second: it seems that the constructor on line 1 is actually making the network call to the new url! This throws an exception (due to the fact that https is not configured), so I never go to the next line.
Reference Information. I am implementing two way ssl auth as described in this question . This means that before calling the service, I need to set up the ssl file in port
. I can't seem to get the constructor to connect before I set up the ssl layer correctly for obvious reasons ...
Update:
Apparently a WSDL url and not an endpoint when using the jax-ws standard. This confused me. Loading the WSDL directly from the file solved this problem.
Configuring the endpoint URL is done as follows:
BindingProvider b = (BindingProvider) port;
b.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
source to share
One solution would be to organize the build process for the WSDL file, processed wsimport
to become a classpath resource for your application. There are several ways to do this, but let's assume you are using a JAR-per-service approach. So, you run Order.wsdl
through wsimport
and take the resulting classes, for example OrderService
and OrderServicePort
, and fill them in order-service.jar
. Another thing you could do is stuff a copy Order.wsdl
into the same JAR into META-INF/wsdl/Order.wsdl
. Assuming the JAR file is part of your application path, you can get the WSDL URL by doing the following:
URL wsdlLocation = Thread.currentThread().getContextClassLoader().getResource("META-INF/wsdl/Order.wsdl");
source to share