A Technology Blog About Code Development, Architecture, Operating System, Hardware, Tips and Tutorials for Developers.

Thursday, November 29, 2012

JAX-WS Web Integration (Apache Axis2)

5:08:00 PM Posted by Satish , , , , , , No comments
Here I will demonstrate web integration of web services. I have created document style, RPC style and MTOM web services in the tutorials Web Service using JAX-WS (RPC Style)Web Service using JAX-WS (Document Style) and Web Service using JAX-WS (MTOM) respectively. Here in this tutorial, I am going to demonstrate the document style web service. I will be using the Apache Axis2 which is one of the implementation of JAX-WS. Unlike Glassfish Metro, using Apache Axis2, it is bit different and complicated. 

For this tutorial I will be using the following tools

1. JDK 7
2. Eclipse Juno
3. Maven2
4. Apache Axis2
5. Tomcat 7

Most of the time web services are part of web applications, so let's deploy a web service in application server. I will not be explaining much about web services here, as I have already explained in my previous posts. In JAX-WS Web Integration (Glassfish Metro), I have discussed some of the concept about RPC and Document style web services.

This tutorial shows you how to do the following tasks:

1. Create a web service Apache Axis2.
2. Deployment in Tomcat 7.

As I told before Creating a web service using Apache Axis2 is a bit complected process, so let me provide the steps, what we are going to do exactly.

1. End Point Class Creation
2. From End point Class to WSDL generation using maven plugin
3. From WSDL to Artifact Class Generation
4. Mapping of End Point in services.xml
5. Front Controller Configuration in web.xml

Before start coding let's create a java project using the following maven command.

1
mvn archetype:generate -DgroupId=com.techiekernel -DartifactId=webservice-JAX-WS-Web-Axis2 -Dpackagename=com.techiekernel -DarchetypeArtifactId=maven-archetype-webapp

After you execute, the project will be get created with pom.xml file. As I am using JDK 7 and annotations, I have to specify the updated maven plugin. So the final pom.xml is shown bellow.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.techiekernel</groupId>
 <artifactId>webservice-JAX-WS-Web-Axis2</artifactId>
 <packaging>war</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>webservice-JAX-WS-Web-Axis2 Maven Webapp</name>
 <url>http://maven.apache.org</url>
 <dependencies>
  <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
     <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.0.2</version>
   </plugin>
   <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.5.1</version>
    <configuration>
     <source>1.6</source>
     <target>1.6</target>
    </configuration>
   </plugin>
  </plugins>
  <finalName>webservice-JAX-WS-Web-Axis2</finalName>
 </build>
</project>

End Point Class Creation:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.techiekernel.ws.jaxws.document;

import javax.jws.WebMethod;
import javax.jws.WebService;

public class FooBarImpl{

 public String callFooBar(String name) {
  // TODO Auto-generated method stub
  return "FooBar called by " + name;
 }

 public Server getServerDetail(String client) {
  // TODO Auto-generated method stub
  Server server = new Server();
  server.setName("Techie Kernel");
  server.setIp("192.168.1.0");
  server.setMac("12-75-61-09-12-22");
  server.setOs("Ubuntu");
  return server;
 }
}

From End point Class to WSDL generation using maven plugin:

Here  we are going to use the following maven plugin to create the WSDL. Once you add the plugin to your pom.xml, you can run mvn clean install to generate the WSDL.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<plugin>
    <groupId>org.apache.axis2</groupId>
    <artifactId>axis2-java2wsdl-maven-plugin</artifactId>
    <version>1.5.4</version>
    <executions>
     <execution>
      <phase>process-classes</phase>
      <goals>
       <goal>java2wsdl</goal>
      </goals>
     </execution>
    </executions>
    <configuration>
     <className>com.techiekernel.ws.jaxws.document.FooBarImpl</className>
     <outputFileName>src/main/webapp/FooBarImpl.wsdl</outputFileName>
    </configuration>
   </plugin>

From WSDL to Artifact Class Generation:

Even for generating the artifact classes, we are going to use the maven plugin.  To generate the artifact classes we have to run the same mvn clean install command. But not now.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<plugin>
 <groupId>org.apache.axis2</groupId>
 <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
 <version>1.5.4</version>
 <executions>
  <execution>
   <phase>generate-sources</phase>
   <goals>
    <goal>wsdl2code</goal>
   </goals>
  </execution>
 </executions>
 <configuration>
  <classpathElements>${project.build.outputDirectory}</classpathElements>
  <wsdlFile>src/main/webapp/FooBarImpl.wsdl</wsdlFile>
  <databindingName>xmlbeans</databindingName>
  <packageName>com.techiekernel.ws.jaxws.document</packageName>
 </configuration>
</plugin>
 <plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <executions>
   <execution>
    <phase>generate-sources</phase>
    <goals>
     <goal>add-source</goal>
    </goals>
    <configuration>
     <sources>
      <source>${project.build.directory}/webservice-JAX-WS-Web-Axis2/wsdl2code/src</source>
     </sources>
    </configuration>
   </execution>
  </executions>
 </plugin>

Mapping of End Point in services.xml:

Once you map the end point, you have to place the services.xml to /webapp/WEB-INF/services/FooBarImpl/. The services.xml looks as bellow.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<serviceGroup>
 <service name="FooBarImpl" targetNamespace="http://document.jaxws.ws.techiekernel.com/">>
  <description>FooBarWsDocument</description>
  <schema schemaNamespace="http://document.jaxws.ws.techiekernel.com/" />
  <parameter name="ServiceClass" locked="false">com.techiekernel.ws.jaxws.document.FooBarImpl
  </parameter>
  <operation name="callFooBar">
   <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
  </operation>
  <operation name="getServerDetail">
   <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
  </operation>
 </service>
</serviceGroup>

Front Controller Configuration in web.xml:

We have to declare a servlet from Axis2 in web.xml, which will be acting as front controller for all the web services. 


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>webservice-JAX-WS-Web-Axis2</display-name>
  <servlet>
        <servlet-name>AxisServlet</servlet-name>
        <display-name>Apache-Axis Servlet</display-name>
        <servlet-class>
            org.apache.axis2.transport.http.AxisServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
</web-app>

Now every thing is ready, so we can run the mvn clean install command to generate the war file. Let's deploy the generated war in to tomcat container. By hitting the following url, we can see the WSDL.

1
http://localhost:8080/webservice-JAX-WS-Web-Axis2/services/FooBarImpl?wsdl

Code Base:

You can download the source code from GitHub.


Wednesday, November 28, 2012

Web Service Client

9:01:00 PM Posted by Satish , , 1 comment
We have done with Document Style Web Service, RPC Style Web Service, MTOM Web Service and integrated with web application in JAX-WS Web Integration (Glassfish Metro). Now it is time to write the client for them, yes we are going to consume the web services. I am going to demonsrate both jdk wsimport and maven plugin to import the web services from wsdl. In my last post JAX-WS Web Integration (Glassfish Metro), I have focused how the document and RPC style differ from each other while building web service. Here I am going to demonstrate the difference between RPC and Document style web services, while writing the client.

For this tutorial I will be using the following tools

1. JDK 7
2. Eclipse Juno
3. Maven2

We are going to use the same web services that we have demonstrated in JAX-WS Web Integration (Glassfish Metro). So before stating the tutorial let me deploy the war to the tomcat. So we will be doing the following things here:

1. Import web service and stub creation (using wsimport and maven wsimport plugin)
2. Client for Document style web service
3. Client for RPC style web service

Before start coding let's create a java project using the following maven command. 

1
mvn archetype:generate -DgroupId=com.techiekernel -DartifactId=webservice-client -Dpackagename=com.techiekernel

After executing, the project will be get created with pom.xml file. Bellow is the final pom.xml file with wsimport plugin.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

 <groupId>com.techiekernel</groupId>
 <artifactId>webservice-client</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>jar</packaging>

 <name>webservice-client</name>
 <url>http://maven.apache.org</url>

 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 </properties>

 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
   </plugin>
   <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
     <source>1.5</source>
     <target>1.5</target>
    </configuration>
   </plugin>
   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>1.12</version>
    <executions>
     <execution>
      <goals>
       <goal>wsimport</goal>
      </goals>
     </execution>
    </executions>
    <configuration>
     <wsdlUrls>
      <wsdlUrl>http://localhost:8080/webservice-JAX-WS-Web-Metro/foobar?wsdl</wsdlUrl>
      <wsdlUrl>http://localhost:8080/webservice-JAX-WS-Web-Metro/foobarRPC?wsdl</wsdlUrl>
      <wsdlUrl>http://localhost:8080/webservice-JAX-WS-Web-Metro/fileImageServer?wsdl</wsdlUrl>
     </wsdlUrls>

     <sourceDestDir>src/main/java</sourceDestDir>
     <verbose>true</verbose>
    </configuration>
   </plugin>
  </plugins>
  <finalName>webservice-client</finalName>
 </build>
</project>

Import web service and stub creation (using wsimport and maven wsimport plugin):


We can import the web service using wsimport in the following way. Once you import the web services, you will notice the stub for document and RPC style web services are totally different. Same way the SOAP engine will take the responsibility of marshaling and demarshaling the SOAP request in case of RPC style.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
satish@sertao:~/code-base/code-playground/webservice-client$ wsimport -keep -verbose http://localhost:8080/webservice-JAX-WS-Web-Metro/foobar?wsdl -d src/main/java/
parsing WSDL...



Generating code...

com/techiekernel/ws/jaxws/document/CallFooBar.java
com/techiekernel/ws/jaxws/document/CallFooBarResponse.java
com/techiekernel/ws/jaxws/document/FooBarImpl.java
com/techiekernel/ws/jaxws/document/FooBarImplService.java
com/techiekernel/ws/jaxws/document/GetServerDetail.java
com/techiekernel/ws/jaxws/document/GetServerDetailResponse.java
com/techiekernel/ws/jaxws/document/ObjectFactory.java
com/techiekernel/ws/jaxws/document/Server.java
com/techiekernel/ws/jaxws/document/package-info.java

Compiling code...

javac -d /home/satish/code-base/code-playground/webservice-client/src/main/java -classpath /usr/lib/jvm/java-7-oracle/lib/tools.jar:/usr/lib/jvm/java-7-oracle/classes -Xbootclasspath/p:/usr/lib/jvm/java-7-oracle/jre/lib/rt.jar:/usr/lib/jvm/java-7-oracle/jre/lib/rt.jar /home/satish/code-base/code-playground/webservice-client/src/main/java/com/techiekernel/ws/jaxws/document/CallFooBar.java /home/satish/code-base/code-playground/webservice-client/src/main/java/com/techiekernel/ws/jaxws/document/CallFooBarResponse.java /home/satish/code-base/code-playground/webservice-client/src/main/java/com/techiekernel/ws/jaxws/document/FooBarImpl.java /home/satish/code-base/code-playground/webservice-client/src/main/java/com/techiekernel/ws/jaxws/document/FooBarImplService.java /home/satish/code-base/code-playground/webservice-client/src/main/java/com/techiekernel/ws/jaxws/document/GetServerDetail.java /home/satish/code-base/code-playground/webservice-client/src/main/java/com/techiekernel/ws/jaxws/document/GetServerDetailResponse.java /home/satish/code-base/code-playground/webservice-client/src/main/java/com/techiekernel/ws/jaxws/document/ObjectFactory.java /home/satish/code-base/code-playground/webservice-client/src/main/java/com/techiekernel/ws/jaxws/document/Server.java /home/satish/code-base/code-playground/webservice-client/src/main/java/com/techiekernel/ws/jaxws/document/package-info.java 

We can also use the bellow maven plugin to import the web service.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>1.12</version>
    <executions>
     <execution>
      <goals>
       <goal>wsimport</goal>
      </goals>
     </execution>
    </executions>
    <configuration>
     <wsdlUrls>
      <wsdlUrl>http://localhost:8080/webservice-JAX-WS-Web-Metro/foobar?wsdl</wsdlUrl>
      <wsdlUrl>http://localhost:8080/webservice-JAX-WS-Web-Metro/foobarRPC?wsdl</wsdlUrl>
      <wsdlUrl>http://localhost:8080/webservice-JAX-WS-Web-Metro/fileImageServer?wsdl</wsdlUrl>
     </wsdlUrls>

     <sourceDestDir>src/main/java</sourceDestDir>
     <verbose>true</verbose>
    </configuration>
   </plugin>

Client for Document style web service:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
package com.techiekernel.ws.jaxws.client;

import com.techiekernel.ws.jaxws.document.FooBarImpl;
import com.techiekernel.ws.jaxws.document.FooBarImplService;

public class DocumentStyleWsClient {
 public static void main(String[] args) {
  FooBarImplService fooBarImplService = new FooBarImplService();
  FooBarImpl fooBarImpl = fooBarImplService.getFooBarImplPort();
  System.out.println(fooBarImpl.callFooBar("Satish"));
 }
}

Client for RPC style web service:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
package com.techiekernel.ws.jaxws.client;

import com.techiekernel.ws.jaxws.rpc.FooBarImpl;
import com.techiekernel.ws.jaxws.rpc.FooBarImplService;

public class RPCStyleWsClient {
 public static void main(String[] args) {
  FooBarImplService fooBarImplService = new FooBarImplService();
  FooBarImpl fooBarImpl = fooBarImplService.getFooBarImplPort();
  System.out.println(fooBarImpl.callFooBar1("Satish"));
 }
}


Source Code:

You can pull the source code from GitHub.

Sunday, November 25, 2012

JAX-WS Web Integration (Glassfish Metro)

9:35:00 PM Posted by Satish , , , , No comments
Here I will demonstrate web integration of web services. I have created document style, RPC style and MTOM web services in the tutorials Web Service using JAX-WS (RPC Style), Web Service using JAX-WS (Document Style) and Web Service using JAX-WS (MTOM) respectively. The code which I will be sharing will have the implementation for all those three web services. But here in this tutorial, I am going to demonstrate the document style web service. I will be using the Glassfish Metro which is one of the implementation of JAX-WS. 

For this tutorial I will be using the following tools

1. JDK 7
2. Eclipse Juno
3. Maven2
4. GlassFish Metro

Most of the time web services are part of web applications, so let's deploy a web service in application server. Along with integration I am going to show you how the RPC and Document style web services are different from each other.

This tutorial shows you how to do the following tasks:

1. Create a SOAP-based Document style web service end point by using JAX-WS.
2. Deployment in Tomcat 7.

Before start coding let's create a java project using the following maven command.

1
mvn archetype:generate -DgroupId=com.techiekernel -DartifactId=webservice-JAX-WS-Web-Metro -Dpackagename=com.techiekernel -DarchetypeArtifactId=maven-archetype-webapp

After you execute, the project will be get created with "pom.xml" file. As I am using JDK 7 and annotations, I have to specify the updated maven plugin. And I have to specify the dependency for GlassFish Metro. So the final pom.xml is shown bellow.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.techiekernel</groupId>
 <artifactId>webservice-JAX-WS-Web</artifactId>
 <packaging>war</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>webservice-JAX-WS-Web Maven Webapp</name>
 <url>http://maven.apache.org</url>
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
  <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.1.5</version>
        </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
   </plugin>
   <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
     <source>1.5</source>
     <target>1.5</target>
    </configuration>
   </plugin>
  </plugins>
  <finalName>webservice-JAX-WS-Web</finalName>
 </build>
</project>

his example I will demonstrate using a Server Object, which will be the return type for one of the web method. So let's create a class called Server, which we will be using to populate the server details and send that back to the client.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.techiekernel.ws.jaxws.document;

public class Server {
 private String name;
 private String ip;
 private String mac;
 private String os;
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getIp() {
  return ip;
 }
 public void setIp(String ip) {
  this.ip = ip;
 }
 public String getMac() {
  return mac;
 }
 public void setMac(String mac) {
  this.mac = mac;
 }
 public String getOs() {
  return os;
 }
 public void setOs(String os) {
  this.os = os;
 }
 @Override
 public String toString() {
  return "Server [name=" + name + ", ip=" + ip + ", mac=" + mac + ", os="
    + os + ", toString()=" + super.toString() + "]";
 }
}

Web Service Endpoint Implementation:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.techiekernel.ws.jaxws.document;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public class FooBarImpl{

 public String callFooBar(String name) {
  // TODO Auto-generated method stub
  return "FooBar called by " + name;
 }

 public Server getServerDetail(String client) {
  // TODO Auto-generated method stub
  Server server = new Server();
  server.setName("Techie Kernel");
  server.setIp("192.168.1.0");
  server.setMac("12-75-61-09-12-22");
  server.setOs("Ubuntu");
  return server;
 }
}

In order to integrate the web service to web application, we have to declare and listener and a front controller in web.xml. So the final "web.xml" will look like this.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>webservice-JAX-WS-Web</display-name>
  <listener>
  <listener-class>
   com.sun.xml.ws.transport.http.servlet.WSServletContextListener
                </listener-class>
 </listener>
 <servlet>
  <servlet-name>WSFrontController</servlet-name>
  <servlet-class>
   com.sun.xml.ws.transport.http.servlet.WSServlet
                </servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>WSFrontController</servlet-name>
  <url-pattern>/*</url-pattern>
 </servlet-mapping>
</web-app>

Once the front controller in place, we have to map the web service url to the end point implementation. That we are going to do in "sun-jaxws.xml" at the same place where web.xml is located i.e. it should be there at the web application class path.

1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8"?>
<endpoints
  xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
  version="2.0">
  <endpoint
      name="FooBarWsDocument"
      implementation="com.techiekernel.ws.jaxws.document.FooBarImpl"
      url-pattern="/foobar"/>
</endpoints>

Now we are set to create our war using maven. But when you try to deploy the war following exception will be thrown. Check here for complete information. 

1
2
SEVERE: WSSERVLET11: failed to parse runtime descriptor: runtime modeler error: Wrapper class com.techiekernel.ws.jaxws.document.jaxws.CallFooBar is not found. Have you run APT to generate them?
com.sun.xml.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class com.techiekernel.ws.jaxws.document.jaxws.CallFooBar is not found. Have you run APT to generate them?

If you remember in my article RPC-style vs Document-Style Web Service, I have said in document style web service there are no overheads of marshalling and de marshalling associated with SOAP engine. So you have to generate the artifact classes for the web services. Once we create the artifact classes and deploy the application, you can notice that for RPC style web services, we don't have to create the artifact classes as SOAP engine will take the responsibility to marshal and unmarshal the request/ response xml. You can use the "wsgen" tool from JDK to generate the artifact classes or you can use the maven plugin to achieve that. I am doing to show both way to generate the artifact classes.

1
wsgen -verbose -keep -cp target/classes/ com.techiekernel.ws.jaxws.document.FooBarImpl -d src/main/java/

After adding the plug in the "pom.xml" will look like this.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.techiekernel</groupId>
 <artifactId>webservice-JAX-WS-Web</artifactId>
 <packaging>war</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>webservice-JAX-WS-Web Maven Webapp</name>
 <url>http://maven.apache.org</url>
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
  <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.1.5</version>
        </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
   </plugin>
   <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
     <source>1.5</source>
     <target>1.5</target>
    </configuration>
   </plugin>
   <!-- wsgen for web service artifact generation -->
   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>1.11</version>
    <executions>
     <execution>
      <id>document</id>
      <goals>
       <goal>wsgen</goal>
      </goals>
      <configuration>
       <sei>com.techiekernel.ws.jaxws.document.FooBarImpl</sei>
       <genWsdl>true</genWsdl>
       <keep>true</keep>
       <verbose>true</verbose>
      </configuration>
     </execution>
     <execution>
      <id>mtom</id>
      <goals>
       <goal>wsgen</goal>
      </goals>
      <configuration>
       <sei>com.techiekernel.ws.jaxws.mtom.FileImageServer</sei>
       <genWsdl>true</genWsdl>
       <keep>true</keep>
       <verbose>true</verbose>
      </configuration>
     </execution>
    </executions>
   </plugin>
  </plugins>
  <finalName>webservice-JAX-WS-Web</finalName>
 </build>
</project>

After executing the command following class files will be get created.

CallFooBar

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.techiekernel.ws.jaxws.document.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "callFooBar", namespace = "http://document.jaxws.ws.techiekernel.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "callFooBar", namespace = "http://document.jaxws.ws.techiekernel.com/")
public class CallFooBar {

    @XmlElement(name = "arg0", namespace = "")
    private String arg0;

    /**
     * 
     * @return
     *     returns String
     */
    public String getArg0() {
        return this.arg0;
    }

    /**
     * 
     * @param arg0
     *     the value for the arg0 property
     */
    public void setArg0(String arg0) {
        this.arg0 = arg0;
    }

}

CallFooBarResponse

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
ackage com.techiekernel.ws.jaxws.document.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "callFooBarResponse", namespace = "http://document.jaxws.ws.techiekernel.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "callFooBarResponse", namespace = "http://document.jaxws.ws.techiekernel.com/")
public class CallFooBarResponse {

    @XmlElement(name = "return", namespace = "")
    private String _return;

    /**
     * 
     * @return
     *     returns String
     */
    public String getReturn() {
        return this._return;
    }

    /**
     * 
     * @param _return
     *     the value for the _return property
     */
    public void setReturn(String _return) {
        this._return = _return;
    }

}

GetServerDetail

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.techiekernel.ws.jaxws.document.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "getServerDetail", namespace = "http://document.jaxws.ws.techiekernel.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getServerDetail", namespace = "http://document.jaxws.ws.techiekernel.com/")
public class GetServerDetail {

    @XmlElement(name = "arg0", namespace = "")
    private String arg0;

    /**
     * 
     * @return
     *     returns String
     */
    public String getArg0() {
        return this.arg0;
    }

    /**
     * 
     * @param arg0
     *     the value for the arg0 property
     */
    public void setArg0(String arg0) {
        this.arg0 = arg0;
    }

}

GetServerDetailResponse

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.techiekernel.ws.jaxws.document.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "getServerDetailResponse", namespace = "http://document.jaxws.ws.techiekernel.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getServerDetailResponse", namespace = "http://document.jaxws.ws.techiekernel.com/")
public class GetServerDetailResponse {

    @XmlElement(name = "return", namespace = "")
    private com.techiekernel.ws.jaxws.document.Server _return;

    /**
     * 
     * @return
     *     returns Server
     */
    public com.techiekernel.ws.jaxws.document.Server getReturn() {
        return this._return;
    }

    /**
     * 
     * @param _return
     *     the value for the _return property
     */
    public void setReturn(com.techiekernel.ws.jaxws.document.Server _return) {
        this._return = _return;
    }

}

You may encounter the following error while executing the maven. Try changing the plugin version of jaxws-maven-plugin. In my case, it worked from changing it from 1.10 to 1.11. Click here to know more.


1
2
3
4
5
6
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to execute wsgen

Embedded error: com/sun/mirror/apt/AnnotationProcessorFactory
com.sun.mirror.apt.AnnotationProcessorFactory


Any way now you are ready to create a war and depoly the war to the web server.

Code Base:

You can pull the entire source code from GitHub.