Saturday, 17 October 2015

Developing SOAP Web service using Metro framework @ Bottom Up

Step-1
Create web project with maven support


























step-2
Add below dependency to add feature of metro framework in the project..


!-- This jar is for metro implementation -->
          <dependency>
              <groupId>com.sun.xml.ws</groupId>
              <artifactId>jaxws-rt</artifactId>
              <version>2.2.3</version>
          </dependency>


Step-3
create business object...
public class Frog {

private String fid;
private String name;
private String color;
private String breed;
private String email;

private int age;
}


Step-4
//This is called web service provider/web service endpoint
//here we are exposing the data for other application.
//this will communicate with under laying system and
//expose data to the other application.

@WebService
public class FrogDataProvider {

public String uploadFrog(Frog frog){
System.out.println("_@_#_#_#_#_#_"+frog);
System.out.println("_@_#_#_#_#_#_"+frog);
System.out.println("_@_#_#_#_#_#_"+frog);
System.out.println("_@_#_#_#_#_#_"+frog);
System.out.println("_@_#_#_#_#_#_"+frog);
return "data is uploaded";
}

public List<Frog> findFrogs(){
List<Frog> frogs=new ArrayList<Frog>();
System.out.println("Fetching web service data");
return frogs;
}

}


Step-5
Registering the web service provider for web service container
create one xml file for soap web service configuration
 name =
/WEB-INF/sun-jaxws.xml

<?xml version="1.0" encoding="UTF-8"?>
<endpoints
  xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
  version="2.0">
  <!-- Here we are registering web service
  our web service can be accessed by below url-pattern
   -->
  <endpoint
      name="FrogDataProvider"
      implementation="com.it.frog.soap.provider.FrogDataProvider"
      url-pattern="/frogDataProvider"/>

</endpoints>

here web service is registered with frogDataProvider



Step-6
Configuring web service container......
web.xml


<listener>
        <listener-class>
                com.sun.xml.ws.transport.http.servlet.WSServletContextListener
        </listener-class>
    </listener>

/WEB-INF/sun-jaxws.xml

Note : above listener will read the xml file configure in step-5
to register all the web service inside web service container...

Step-7
Expose the registered web service............................
to the outside the world......same as servlet..

<servlet>
        <servlet-name>kuchbhi</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>kuchbhi</servlet-name>
        <url-pattern>/frogDataProvider</url-pattern>
    </servlet-mapping>

when you type url-pattern your request will be forwarded to 
WSServlet and it will further forward the request to web service container
created by   WSServletContextListener


Step-8
Access the web service  WSDL(Web Service Description Language)
WSDL is interface/contract between web service provide and consumer...


http://localhost:5555/spring-mvc-app/frogDataProvider















No comments:

Post a Comment