

Web Security :=




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

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

Step-2 .
Creating WSDL (contract)

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

Step-4 . Creating Service Provider
@WebService(name
= "AccountDetailsService",
portName = "AccountDetailsPort",
endpointInterface = "com.mg.ws.AccountDetailsPortType",
wsdlLocation = "WEB-INF/wsdl/accounts.wsdl",
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
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.
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>



Generating Client Program

wsimport http://localhost:8090/JAX-TOP-DOWN/details?wsdl
-p com.mg.ws -keep –Xnocompile

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();
}
}
}
This comment has been removed by the author.
ReplyDeleteThese diagrammatic representations and the steps are really easy to understand. Good one for Spring Framework:)
ReplyDelete