Monday, 6 May 2013






Web Security :=










#########
Email Content for reference purpose only



cid:image005.jpg@01CD44A6.62339520


Step-1 Creating Dynamic project and copying all the jar into lib folder.

cid:image003.png@01CD4499.E08DD910


Step-2 .
Creating WSDL (contract)

cid:image006.png@01CD449B.5E89A0F0


Step-3 . generating artifacts
Artifacts are java files which will be used to created Service Provider and Web Service Client.

cid:image009.jpg@01CD44A6.62339520


Step-4 . Creating Service Provider

@WebService(name = "AccountDetailsService",
                       portName = "AccountDetailsPort",
                       endpointInterface = "com.mg.ws.AccountDetailsPortType",
                       wsdlLocation = "WEB-INF/wsdl/accounts.wsdl",
                       targetNamespace="http://gognamunish.com/accounts")
public class AccountDetailsServiceImpl implements AccountDetailsPortType {

          @Override
          public AccountDetailsTO getAccountDetails(GeAccountDetailsINTO parameters,
                             SecurityToken requestHeader) throws AccountDetailsFault_Exception {
                   AccountDetailsTO detailsTO = new AccountDetailsTO();


Step-5 .
Create an another required web service deployment descriptor(sun-jaxws.xml) under the WEB-INF folder.
This file is needed by the JAX-WS reference implementation(Service Provider) to map the service implementation class
 with the service interface.

<?xml version="1.0" encoding="UTF-8"?>
<endpoints
  version="2.0">
  <endpoint name="AccountDetailsServiceEndPoint"
            service ="{http://gognamunish.com/accounts}AccountDetailsService"
      port="{http://gognamunish.com/accounts}AccountDetailsPort"
      implementation="com.mg.ws.impl.AccountDetailsServiceImpl"
      url-pattern="/details"
      wsdl="WEB-INF/wsdl/accounts.wsdl"/>
</endpoints>

sun-jaxws.xml descriptor: Each endpoint definition, in this descriptor indicates the name of the web service, implementation class and the url-pattern
that routes to this web service invocation. This is read by the context listener and handed-over to the web service delegate created by it,
so that the delegate knows which implementation class to invoke when a web service request came-in.

Step-6
web.xml

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

Note : above listener will read sun-jaxws.xml.


Step-7
The servlet definition and it’s mapping is used to intercept the url-pattern
that should be considered as web service request.
The class(com.sun.xml.ws.transport.http.servlet.WSServlet) acts as a dispatching servlet that routes the request to appropriate implementation class through the delegate received from the servlet context created by the listener as stated above.
web.xml


    <servlet>
                   <servlet-name>AccountDetailsService</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>AccountDetailsService</servlet-name>
                   <url-pattern>/details</url-pattern>
          </servlet-mapping>


cid:image010.jpg@01CD44A6.62339520


cid:image014.png@01CD449F.4DB886C0


cid:image015.jpg@01CD44A6.62339520



Generating Client Program

cid:image017.png@01CD44A4.AECE8DB0

wsimport http://localhost:8090/JAX-TOP-DOWN/details?wsdl  -p com.mg.ws -keep –Xnocompile
cid:image020.jpg@01CD44A6.62339520

AccessDataClient.java

package com.mg.ws;

import java.util.Date;
import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class AccessDataClient {
          public static void main(String[] args) {
                  
                   AccountDetailsService accountDetailsService=new AccountDetailsService();
                   AccountDetailsPortType accountDetailsPortType=accountDetailsService.getAccountDetailsPort();
                   GeAccountDetailsINTO parameters=new GeAccountDetailsINTO();
                   parameters.setAccountNo("23234234");
                   SecurityToken requestHeader=new SecurityToken();
                   requestHeader.setToken("83711070");
                  
                   Date date=new Date();
                   GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeInMillis(date.getTime());
        DatatypeFactory df = null;
        try {
                             df = DatatypeFactory.newInstance();
                   } catch (DatatypeConfigurationException e1) {
                             e1.printStackTrace();
                    }
        XMLGregorianCalendar xgc= df.newXMLGregorianCalendar(gc);
                   requestHeader.setValidTill(xgc);
                   try {
                             AccountDetailsTO accountDetailsTO=accountDetailsPortType.getAccountDetails(parameters, requestHeader);
                             System.out.println(accountDetailsTO.getAccType());
                   } catch (AccountDetailsFault_Exception e) {
                             e.printStackTrace();
                   }
          }

}









2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. These diagrammatic representations and the steps are really easy to understand. Good one for Spring Framework:)

    ReplyDelete