SIMPLE WEB SERVICE
PROVIDER SIDE APPLICATION
Requirement:
Develop
a web service provider side application which, provide complete information
about a book by giving a book name as input.
Web service development environment:
1.
Using Jax-rpc api si (sun implementation)
2.
Contract as last
3.
Synchronous reply/response message exchange
pattern
4.
rpc-encoded
5.
servlet end-point
Software requirements:
1.
java 1.5.0_22and java 1.6.0 in between
2.
jax-rpc specific jar files
3.
apache-
tomcat 6.x serve
4.
Jwsdp 2.0 tool
Development procedure:
Step 1:
Create
a dynamic project in eclipse as follows.
File->New->Others->Dynamic web project
Give the project name and set server as tomcat
project Name: bookproject
Create a package under project : bookproject as shown
Package name: com.bookweb.service
Step 2:
Copy
the all jax-rpc specific jar files into lib folder.
Step 3:
Create
a SEI interface as follows
Interface
name: BookInterface
package com.bookweb.service;
import java.rmi.Remote;
import
java.rmi.RemoteException;
public interface BookInterface extends Remote {
float getBookPrice(String
isbn) throws RemoteException;
}
Step 4:
Implemented
class name: BookImpl.java
Provide
implementation for SEI interface, which is full fill our business requirements
package com.bookweb.service;
import
java.rmi.RemoteException;
public class BookImpl implements BookInterface {
public float getBookPrice(String
isbn) throws RemoteException {
float bookprice=0.0f;
if(isbn.equals("java"))
bookprice=234.56f;
return bookprice;
}
}
Step 5:
Write a configuration
file under WEB-INF folder as following tags
Configuration file name: config.xml
<?xml version="1.0"
encoding="UTF-8"?>
<configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<service name="BookInfoService"
targetNamespace="http://bookinfoservice.org/wsdl"
typeNamespace="http://bookinfoservice.org/types"
packageName="com.bookweb.service.binding">
<interface name="com.bookweb.service.BookInterface"
servantName="com.bookweb.service.BookImpl" />
</service>
</configuration>
Step 5:
Install
jwsdp2.0 tool
Set path for bin as C:\Sun\jwsdp-2.0\jaxrpc\bin
Run wscompile.bat with following options and pass config.xml
as input
C:\Users\sant\workspace\BookService>wscompile -keep -verbose
-gen:server -d src
-cp build\classes -model model-rpc-enc.xml.gz
WebContent\WEB-INF\config.xml
It will generates wsdl file and model files and saxparsers
and java classes
Move the wsdl and model file into WEB-INF folder
Step 5:
Write
one more configuration file jax-rpc.xml (file name with same name only) under
WEB-INF
<?xml version="1.0"
encoding="UTF-8"?>
<webServices
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/dd"
version="1.0"
targetNamespaceBase="http://bookinfoservice.org/wsdl"
typeNamespaceBase="http://bookinfoservice.org/types"
urlPatternBase="/getBookPrice">
<endpoint
name="booksriceservice"
displayName="Book Service"
description="A simple web service"
wsdl="/WEB-INF/BookInfoService.wsdll"
interface="com.bookweb.service.BookInterface"
implementation="com.bookweb.service.BookImpl"
model="/WEB-INF/model-rpc-enc.xml.gz">
</endpoint>
<endpointMapping
endpointName="booksriceservice"
urlPattern="/getBookPrice"/>
</webServices>
Step 6:
Export
project as .war file
Give the war as input to the wsdeploy.bat
C:\wsdeploy –o taget.war bookproject.war
It generates the jax-rpc-runtime.xml and web.xml
Copy the same file into the project WEB-INF folder
Step 7:
Deploy the project in server and run the server and provide
the url;
output as follows:
Web Services
Port Name
|
Status
|
Information
|
||||||||||||
booksriceservice
|
ACTIVE
|
|