Jerome
Jerome

Reputation: 2278

Publish JAX-WS service with Spring and Embedded Jetty 8

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:

  1. 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>
    
  2. In my Spring web services context, configure the WSSpringServlet.

    webservicesContext.addServlet(new ServletHolder(new WSSpringServlet()), "/service/*");
    
  3. Created an implementation class for my service.

    @WebService(name = "GenerateUEIDService")
    public class GenerateUEIDService {
    
        @WebMethod(operationName = "generateUniqueIds")
        public String generateUniqueIds() {
            return "Hello World";
        }
    
    }
    
  4. 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.

Upvotes: 0

Views: 1594

Answers (2)

Jerome
Jerome

Reputation: 2278

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.

[exec:exec]
Jul 12, 2012 8:30:05 AM com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass
INFO: Dynamically creating request wrapper Class com.mycompany.mavenjaxwsjetty.jaxws.Greet
Jul 12, 2012 8:30:05 AM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass
INFO: Dynamically creating response wrapper bean Class com.mycompany.mavenjaxwsjetty.jaxws.GreetResponse

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.

Upvotes: 1

jddsantaella
jddsantaella

Reputation: 3687

You can generate jaxb classes using a Maven plugin. It should look like this:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.8.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <!--
        <generatePackage>if you wan to force the package</generatePackage>
        -->
        <generateDirectory>target/jaxb/generate/</generateDirectory>
        <schemaDirectory>src/main/webapp/WEB-INF/</schemaDirectory>
        <includeSchemas>
            <includeSchema>yourXSDfile.xsd</includeSchema>
        </includeSchemas>
    </configuration>
</plugin>

Upvotes: 0

Related Questions