3

I'm using JAX-WS standard stuff with wsimport http://localhost/Order.wsdl to generate client stub classes.

The live web service is on a different host, so I need to supply a url when I make the service call. My approach so far has been like this (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 of specifying the url?

Second: It seems the constructor in line 1 actually makes a network call to the new URL! This results in an exception (due to https not being configured), so I never get to the next line.

Background: I am implementing two-way ssl auth as outlined in this question. This means I need to configure ssl stuff in the port before the service call. I can't have the constructor make any connection before I've configured the ssl layer correctly for obvious reasons...

Update:

Apparenty the url is to the WSDL, not the endpoint when using jax-ws standard. This tripped me up. Loading the WSDL directly from file solved that problem.

Setting the endpoint url is done like this:

BindingProvider b = (BindingProvider) port;        
b.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
4

1 に答える 1

1

One solution would be to have your build process arrange for the WSDL file processed by wsimport to become a class path resource for your app. There are any number of ways to do this, but lets assume you take a JAR-per-service approach. So, you'd run Order.wsdl through wsimport and take the resulting classes, like OrderService and OrderServicePort, and stuff them into order-service.jar. The other thing you could do would be to stuff a copy of Order.wsdl into that same JAR at META-INF/wsdl/Order.wsdl. Assuming that JAR file is then part of the class path for your app, you can get the WSDL's URL by doing:

URL wsdlLocation = Thread.currentThread().getContextClassLoader().getResource("META-INF/wsdl/Order.wsdl");
于 2013-02-15T04:39:59.837 に答える