I am trying to add a JAX-WS web service to my Embedded Jetty application. The web service client will be a .NET application.
My project was created as a Maven application in Netbeans 7.1.1. It uses Spring 3.0.
I took the following steps to add the JAX-WS to my application:
-
Added jaxws-spring to the pom.xml.
<dependency> <groupId>org.jvnet.jax-ws-commons.spring</groupId> <artifactId>jaxws-spring</artifactId> <version>1.8</version> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </exclusion> </exclusions> </dependency> -
In my Spring web services context, configure the WSSpringServlet.
webservicesContext.addServlet(new ServletHolder(new WSSpringServlet()), "/service/*"); -
Created an implementation class for my service.
@WebService(name = "GenerateUEIDService") public class GenerateUEIDService { @WebMethod(operationName = "generateUniqueIds") public String generateUniqueIds() { return "Hello World"; } } -
Configure my service in the Spring applicationContext.xml file.
<bean id="generateUEIDService" class="com.mycompany.GenerateUEIDService"/> <wss:binding url="/service/GenerateUEID.svc"> <wss:service> <ws:service bean="#generateUEIDService" /> </wss:service> </wss:binding>
I didn’t use any Web Service creation wizard in Netbeans for Step 3 above. Instead I created GenerateUEIDService as a normal Java class, but adding the annotations. Even though I didn’t Netbeans did somehow detect this was a Web Service because it created a “Web Services” node in the project view with “GenerateUEIDServiceService” beneath it. If I expand GenerateUEIDServiceService I see “generateUniqueIds: String”.
It seems to build fine. But when I run the application I get:
com.sun.xml.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class
com.mycompany.jaxws.GenerateUniqueIds is not found. Have you run APT to generate them?
Well no, I haven’t run APT to generate anything. Given my configuration how should I do that? Do I need to add a plug-in to my pom.xml? Or was Netbeans magically supposed to generate the wrapper for me?
Please note that my web service client will be .NET. So I assume I should use the default SOAPBinding of document/literal wrapped.
I decided to create a simple Netbeans Maven java application to see if the wrapper classes for the service would be generated automatically. Turns out they are created dynamically at run-time by the JAX-WS runtime.
So back to my original application (from the original posting above). I removed the jaxws-spring stuff for unrelated reasons. I may have made some other changes I can’t recall. And now when I run that application I can see in the logs that the wrapper classes are being created.
So I guess the answer to my question is that Netbeans does not magically create the wrapper classes for me, but rather the jax-ws runtime does.
Still I wonder under what circumstances the wrapper classes wouldn’t be generated automatically for me. Or when I would want to generate my own using wsgen or maven-jaxb2-plugin. As usual, I guess there are more than one ways to “skin the cat” and each has its pros and cons.