Web services using JAXB

Hi Guys here is my brief post on how to develop web services using jaxb notation.

The Java Architecture for XML Binding API (JAXB) makes it easy to access XML documents from applications written in the Java programming language. JAXB is an alternative to using a SAX or DOM parser to access the data in an XML document. When you access an XML document with JAXB, first you bind the schema for the XML document into a set of Java classes that represents the schema. Then you unmarshal the XML document. Unmarshalling a document means creating a tree of content objects that represents the content and organization of the document.

You can also use JAXB to build an XML document. To build an XML document with JAXB, you first bind the schema for the XML document you want to build. Then you create a content tree. Lastly, you marshal the content tree into an XML document.

The following diagram, from Java Architecture for XML Binding API, shows the processes both for accessing and for building XML documents from Java applications.


Working with JAXB is easy, just annotate object with JAXB annotation, later use jaxbMarshaller.marshal() or jaxbMarshaller.unmarshal() to do the object / XML conversion.
No extra jaxb libraries are required if you are using JDK1.6 or above, because JAXB is bundled in JDK 1.6.
Note
For JDK < 1.6, download JAXB from here and put “jaxb-api.jar” and “jaxb-impl.jar” on your project classpath.

now lets see how to code with “jaxb”

/**
 * 
 */
package com.spark.jaxb.model;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * @author Pavan Mantha
 * 
 */
@SuppressWarnings("serial")
@XmlRootElement
public class Customer implements Serializable {

	private int id;
	private String firstName;
	private String lastName;
	private String designation;
	private String phoneNumber;

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	@XmlAttribute
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @param firstName
	 *            the firstName to set
	 */
	@XmlElement
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @param lastName
	 *            the lastName to set
	 */
	@XmlElement
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @return the designation
	 */
	public String getDesignation() {
		return designation;
	}

	/**
	 * @param designation
	 *            the designation to set
	 */
	@XmlElement
	public void setDesignation(String designation) {
		this.designation = designation;
	}

	/**
	 * @return the phoneNumber
	 */
	public String getPhoneNumber() {
		return phoneNumber;
	}

	/**
	 * @param phoneNumber
	 *            the phoneNumber to set
	 */
	@XmlElement
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

}

now its time to code jaxb marshaller,

/**
 * 
 */
package com.spark.jaxb.marshaller;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import com.spark.jaxb.model.Customer;

/**
 * @author Pavan Mantha
 * 
 */
public class JaxbMarshaller {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Customer customer = new Customer();
		customer.setId(100);
		customer.setFirstName("Pavan");
		customer.setLastName("Mantha");
		customer.setDesignation("SoftwareEngineer");
		customer.setPhoneNumber("123-4567-890");

		try {

			File file = new File("C:\\customer.xml");
			JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
			Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

			// output pretty printed
			jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

			jaxbMarshaller.marshal(customer, file);
			jaxbMarshaller.marshal(customer, System.out);

		} catch (JAXBException e) {
			e.printStackTrace();
		}
	}

}

and unmarshaller as below.

/**
 * 
 */
package com.spark.jaxb.unmarshaller;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import com.spark.jaxb.model.Customer;

/**
 * @author Pavan Mantha
 * 
 */
public class JaxbUnmarshaller {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {

			File file = new File("C:\\customer.xml");
			JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);

			Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
			Customer customer = (Customer) jaxbUnmarshaller.unmarshal(file);
			System.out.println(customer);

		} catch (JAXBException e) {
			e.printStackTrace();
		}
	}

}

Happy Coding 🙂

Building REST web services using Jersey and Maven

Hi guys, here is my post regarding how to develop restful web services using jersey and maven. Before we go into development of service lets discuss some concepts of REST.
What Are RESTful Web Services?

RESTful web services are built to work best on the Web. Representational State Transfer (REST) is an architectural style that specifies constraints, such as the uniform interface, that if applied to a web service induce desirable properties, such as performance, scalability, and modifiability, that enable services to work best on the Web. In the REST architectural style, data and functionality are considered resources and are accessed using Uniform Resource Identifiers (URIs), typically links on the Web. The resources are acted upon by using a set of simple, well-defined operations. The REST architectural style constrains an architecture to a client/server architecture and is designed to use a stateless communication protocol, typically HTTP. In the REST architecture style, clients and servers exchange representations of resources by using a standardized interface and protocol.

The following principles encourage RESTful applications to be simple, lightweight, and fast:

Resource identification through URI: A RESTful web service exposes a set of resources that identify the targets of the interaction with its clients. Resources are identified by URIs, which provide a global addressing space for resource and service discovery. See The @Path Annotation and URI Path Templates for more information.

Uniform interface: Resources are manipulated using a fixed set of four create, read, update, delete operations: PUT, GET, POST, and DELETE. PUT creates a new resource, which can be then deleted by using DELETE. GET retrieves the current state of a resource in some representation. POST transfers a new state onto a resource. See Responding to HTTP Methods and Requests for more information.

Self-descriptive messages: Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others. Metadata about the resource is available and used, for example, to control caching, detect transmission errors, negotiate the appropriate representation format, and perform authentication or access control. See Responding to HTTP Methods and Requests and Using Entity Providers to Map HTTP Response and Request Entity Bodies for more information.

Summary of JAX-RS Annotations

@Path
The @Path annotation’s value is a relative URI path indicating where the Java class will be hosted: for example, /helloworld. You can also embed variables in the URIs to make a URI path template. For example, you could ask for the name of a user and pass it to the application as a variable in the URI: /helloworld/{username}.

@GET
The @GET annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP GET requests. The behavior of a resource is determined by the HTTP method to which the resource is responding.

@POST
The @POST annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP POST requests. The behavior of a resource is determined by the HTTP method to which the resource is responding.

@PUT
The @PUT annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP PUT requests. The behavior of a resource is determined by the HTTP method to which the resource is responding.

@DELETE
The @DELETE annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP DELETE requests. The behavior of a resource is determined by the HTTP method to which the resource is responding.

@HEAD
The @HEAD annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP HEAD requests. The behavior of a resource is determined by the HTTP method to which the resource is responding.

@PathParam
The @PathParam annotation is a type of parameter that you can extract for use in your resource class. URI path parameters are extracted from the request URI, and the parameter names correspond to the URI path template variable names specified in the @Path class-level annotation.

@QueryParam
The @QueryParam annotation is a type of parameter that you can extract for use in your resource class. Query parameters are extracted from the request URI query parameters.

@Consumes
The @Consumes annotation is used to specify the MIME media types of representations a resource can consume that were sent by the client.

@Produces
The @Produces annotation is used to specify the MIME media types of representations a resource can produce and send back to the client: for example, “text/plain”.

@Provider
The @Provider annotation is used for anything that is of interest to the JAX-RS runtime, such as MessageBodyReader and MessageBodyWriter. For HTTP requests, the MessageBodyReader is used to map an HTTP request entity body to method parameters. On the response side, a return value is mapped to an HTTP response entity body by using a MessageBodyWriter. If the application needs to supply additional metadata, such as HTTP headers or a different status code, a method can return a Response that wraps the entity and that can be built using Response.ResponseBuilder.

Now lets see how to develop the rest service.
1.first create a maven project and add the following dependencies to your POM.xml as below –

<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.spark.jersy.service</groupId>
	<artifactId>JersyService</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<name>JersyService</name>
	<description>JersyService</description>


	<dependencies>
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-server</artifactId>
			<version>1.17</version>
		</dependency>
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-servlet</artifactId>
			<version>1.17</version>
		</dependency>
		<dependency>
			<groupId>javax.ws.rs</groupId>
			<artifactId>jsr311-api</artifactId>
			<version>1.1.1</version>
		</dependency>
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-client</artifactId>
			<version>1.17</version>
		</dependency>
	</dependencies>
</project>

now its to code your rest service, lets name the service as RestService in the package “com.spark.rest.service” as below –

/**
 * 
 */
package com.spark.rest.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 * @author Sony
 *
 */
@Path("/hello")
public class RestService {

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	@Path("/{name}")
	public String getMessage(@PathParam("name") String name){

		return "{'name':"+name+",'desg':'SoftWareEngg','Age':'26'}";
	}

}

lets publish our web service as a servlet so, lets code web.xml as below –

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	
	<servlet>
		<servlet-name>jersey-servlet</servlet-name>
		<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
		
		<init-param>
			<param-name>com.sun.jersey.config.property.packages</param-name>
			<param-value>com.spark.rest.service</param-value>
		</init-param>
		
		<load-on-startup>1</load-on-startup>
	</servlet>
	
	<servlet-mapping>
		<servlet-name>jersey-servlet</servlet-name>
		<url-pattern>/rest/*</url-pattern>
	</servlet-mapping>
</web-app>

Test your service by deploying into Tomcat(any version, preferably >5.x) and request from browser as below –
http://localhost:8080/JerseyService/rest/hello/{yourname}”, in return you get a response of JSON string.

suppose, if u want to test the web service using a standalone client lets code a main method as below –

/**
 * 
 */
package com.spark.rest.service.client;

import java.net.URI;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;

/**
 * @author Sony
 * 
 */
public class JerseyRestClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		ClientConfig clientConfig = new DefaultClientConfig();
		Client client = Client.create(clientConfig);

		WebResource webResource = client.resource(getBaseURI());

		System.out.println(webResource.path("rest").path("hello/pavan")
				.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class)
				.toString());

	}

	public static URI getBaseURI() {
		return UriBuilder.fromUri("http://localhost:8080/JersyService").build();
	}

}

References:(with courtesy)
1.http://docs.oracle.com/javaee/6/tutorial/doc/giepu.html
2.http://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/
3.http://www.vogella.com/articles/REST/article.html

Happy RESTful coding 🙂

Building Web services on JBoss AS 7

Hi guys, here is my post regarding how to build web services on JBoss AS 7.x version. This post is fully self explanatory please follow the comments on the code.

step 1: create dynamic web project in eclipse with Jboss AS 7 as runtime configuration
step 2: in “src” folder code an interface as follows.

/**
 *
 */
package com.spark.webservice;

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

/**
 * @author Mantha Pavan Kumar
 *
 */
@WebService
public interface TemperatureConverter {

	@WebMethod
	public double convertCelsiusToFahrenheit(double value);
	@WebMethod
	public double convertFahrenheitToCelsius(double value);
}

step 3: code an implementation of the above interface as below.

/**
 *
 */
package com.spark.webservice.impl;

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

import com.spark.webservice.TemperatureConverter;

/**
 * @author Mantha Pavan Kumar
 *
 */
@WebService(endpointInterface="com.spark.webservice.TemperatureConverter",serviceName = "TemperatureConverter")
public class TemperatureConverterImpl implements TemperatureConverter{

	@Override
	@WebMethod
	public double convertCelsiusToFahrenheit(double value) {
		return value*(9/5)+32;
	}

	@Override
	@WebMethod
	public double convertFahrenheitToCelsius(double value) {
		return (value-32)*(5/9);
	}

}

step 4: now we deploy our web service as servlet on jboss, so lets code web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="jbosswebservices" version="2.5">
	
	<servlet>
		<servlet-name>webService</servlet-name>
		<servlet-class>com.spark.webservice.impl.TemperatureConverterImpl</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>webService</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>

</web-app>

step 5: once step 4 is done lets deploy it in the JBoss AS 7 in the “standalone/deployments” folder
step 6: start the server:

Note:In order to use Web services in the new application server release you need the following extension in your configuration file:

<extension module="org.jboss.as.webservices"/>	

If you are using JBoss AS 7.1.1 this extension is already included in the standalone.xml configuration file, otherwise earlier releases include it in the standalone-preview.xml configuration files so for example if you want to start the standalone server and user webservices you need to use the –server-config option. For example:

standalone.bat --server-config=standalone-preview.xml

once deployed and the server started without any error open the server admin-console, in the web services menu u should see as below

Name Context
webService JBossWebServices

Web Service


Name: webService Context: JBossWebServices
Class: TemperatureConverterImpl Type: JAXWS_JSE
WSDL Url: http://localhost:8080/JBossWebServices?wsdl

Now its time to code the web service client.

step 1: download the following jar files:
a)cxf-bundle-2.0.8.jar,
b)org.apache.servicemix.bundles.jaxb-impl-2.1.6_1.jar,
c)org.apache.servicemix.bundles.xmlresolver-1.2_1.jar,
d)org.apache.servicemix.bundles.xmlschema-1.4.3_1.jar.

and call the web service as below.

/**
 * 
 */
package com.spark.webservice.test;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.spark.webservice.TemperatureConverter;


/**
 * @author Mantha Pavan Kumar
 *
 */
public class TemperatureConverterTest {
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
		factoryBean.getInInterceptors().add(new LoggingInInterceptor());
		factoryBean.getOutInterceptors().add(new LoggingOutInterceptor());
		factoryBean.setServiceClass(TemperatureConverter.class);
		factoryBean.setAddress("http://localhost:8080/JBossWebServices");
		TemperatureConverter converter = (TemperatureConverter)factoryBean.create();
		System.out.println(converter.convertCelsiusToFahrenheit(10));
	}
}

The out put should look as below:

Mar 11, 2013 2:47:40 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://webservice.spark.com/}TemperatureConverterService from class com.spark.webservice.TemperatureConverter
Mar 11, 2013 2:47:42 PM org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose
INFO: Outbound Message
---------------------------
Encoding: UTF-8
Headers: {SOAPAction=[""], Accept=[*]}
Messages: 
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:convertCelsiusToFahrenheit xmlns:ns1="http://webservice.spark.com/"><arg0>10.0</arg0></ns1:convertCelsiusToFahrenheit></soap:Body></soap:Envelope>
--------------------------------------
Mar 11, 2013 2:47:44 PM org.apache.cxf.interceptor.LoggingInInterceptor logging
INFO: Inbound Message
----------------------------
Encoding: UTF-8
Headers: {content-type=[text/xml;charset=UTF-8], Date=[Mon, 11 Mar 2013 09:17:44 GMT], Content-Length=[252], Server=[Apache-Coyote/1.1]}
Messages: 
Message:

Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:convertCelsiusToFahrenheitResponse xmlns:ns2="http://webservice.spark.com/"><return>42.0</return></ns2:convertCelsiusToFahrenheitResponse></soap:Body></soap:Envelope>
--------------------------------------
42.0

Happy Coding 🙂

WebSevices Theory

Hi guys in my last post of web services we saw a practical implementation of java web services but here i want to explain some of the important theory concepts that are involved in design and implementation of web services.

What are Web Services?

  • Web services are application components
  • Web services communicate using open protocols
  • Web services are self-contained and self-describing
  • Web services can be discovered using UDDI
  • Web services can be used by other applications
  • XML is the basis for Web services

How Do WebServices Work?

The basic Web services platform is XML + HTTP.

XML provides a language which can be used between different platforms and programming languages and still express complex messages and functions.The HTTP protocol is the most used Internet protocol.

Web services platform elements:

  • SOAP (Simple Object Access Protocol)
  • UDDI (Universal Description, Discovery and Integration)
  • WSDL (Web Services Description Language)

Interoperability plays major role in webservice implementation

When all major platforms could access the Web using Web browsers, different platforms couldn’t interact. For these platforms to work together, Web-applications were developed.

Web-applications are simply applications that run on the web. These are built around the Web browser standards and can be used by any browser on any platform.

What is SOAP?

SOAP is an XML-based protocol to let applications exchange information over HTTP.Or more simple: SOAP is a protocol for accessing a Web Service.

SOAP stands for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is a format for sending messages
SOAP is designed to communicate via Internet
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP allows you to get around firewalls
SOAP is a W3C standard

What is WSDL?

WSDL is an XML-based language for locating and describing Web services.

WSDL stands for Web Services Description Language
WSDL is based on XML
WSDL is used to describe Web services
WSDL is used to locate Web services
WSDL is a W3C standard

What is UDDI?

UDDI is a directory service where companies can register and search for Web services.

UDDI stands for Universal Description, Discovery and Integration
UDDI is a directory for storing information about web services
UDDI is a directory of web service interfaces described by WSDL
UDDI communicates via SOAP

Happy WebServices 🙂

Creating JavaWebService and JavaClient using Apache Axis2

Hi all, I have got lots of requests to demonstrate creation of webservices using java and Apache Axis2 api so here i go.

1. Setup the Development Environment

1.1. First you need to set up the development environment. Following things are needed if you want to create Web Services using Axis2 and Eclipse IDE(Juno 4.2).

Some Eclipse versions have compatibility issues with Axis2. This tutorial is tested with Apache Axis2 1.5.2, Eclipse Helios and Apache Tomcat 6.

1) Apache Axis2 Binary Distribution – Download
2) Apache Axis2 WAR Distribution – Download
3) Apache Tomcat – Download
4) Eclipse IDE(Juno 4.2) – Download
5) Java installed in your Computer – Download

Then click on the Web Service –-> Axis2 Preferences and browse the top level directory of Apache Axis2 Binary Distribution.
2. Creating the Web Service Using Bottom-Up Approach

2.1 First create a new Dynamic Web Project (File –> New –-> Other…) and choose Web –> Dynamic Web Project.
2.2 Set Apache Tomcat as the Target Runtime and click Modify to install Axis2 Web Services project facet.
2.3 Select Axis2 Web Services
2.4 Click OK and then Next. There you can choose folders and click Finish when you are done

3. Create Web Service Class

/**
 *
 */
package com.spark.webservice;

/**
 * @author Mantha Pavan Kumar
 *
 */
public class JavaWebService {

	/**
	 * @param firstnumber
	 * @param secondNumber
	 * @return
	 */
	public int addNumbers(int firstnumber,int secondNumber){

		return firstnumber+secondNumber;
	}
}

Then, select File –> New –-> Other and choose Web Service.
Click Next and make sure Generate a default service.xml file is selected.
You can go to http://localhost:8080/JavaWebService/services/listServices to see your running service which is deployed by Axis2. You can see the WSDL by clicking the link JavaWebService.

Creating a Web service client
Select File –> New –> Other… and choose Web Service Client
Set he newly created Axis2 Web service (http://localhost:8080/JavaWebService/services/listServices) as the Service definition. Then configure the Server runtime as previously and click finish.

This will generate two new classes called JavaWebServiceStub.java and JavaWebServiceCallbackHandler.java. Now we can create test class for client and use our web service. Create new class called ServiceTest.java and paste following code.

/**
 *
 */
package com.spark.webservice;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;

import com.spark.webservice.JavaWebServiceStub.AddNumbers;
import com.spark.webservice.JavaWebServiceStub.AddNumbersResponse;

/**
 * @author Mantha Pavan Kumar
 *
 */
public class ServiceTest {

	/**
	 * @param args
	 * @throws RemoteException
	 */
	public static void main(String[] args) throws RemoteException {
		// TODO Auto-generated method stub

		JavaWebServiceStub serviceStub = new JavaWebServiceStub();
		AddNumbers addNumbers = new AddNumbers();
		addNumbers.setFirstnumber(10);
		addNumbers.setSecondNumber(20);

		AddNumbersResponse addNumbersResponse = serviceStub.addNumbers(addNumbers);
		System.out.println( addNumbersResponse.get_return());

	}

}

Now you can run the above code as java application and you will get the output
follow these screen shots for creation of webservices Creation of Java WebService
Happy Coding 🙂