jump to navigation

Web Service Endpoint Development using JAX-RPC August 20, 2007

Posted by ninadgawad in Web Services.
trackback

Software Required:

1. Java Web Services Developer Pack (JWSDP 1.5)

2. Tomcat-JWSDP.

3. Java 2 Enterprise Edition (J2EE) 1.4.

Set Environment variables and class-path:

· JAVA_HOME=JDK location

eg. JAVA_HOME=C:\jdk1.5

· CATALINA_HOME=JWSDP location

eg. CATALINA_HOME=C:\tomcat50-jwsdp

· Add CATALINA_HOME\jaxrpc\bin to class-path .

(for using wsdeploy & wscomplie tool)

The following files are required to make Service Endpoint Interface: (Servlet based)

  • Interface Class
  • Implementation Class
  • web.xml
  • jaxrpc-ri.xml

Package Structure Diagram:

Package Structure Diagram

Files required for sample Example “HelloWorld”

1. HelloIF.java (Interface)

2. HelloImpl.java (Implementation)

3. web.xml (Deployment descriptor)

4. jaxrpc-ri.xml (Configuration file read by the wsdeploy tool)

Source Code:

HelloIF.java

package hello;

import java.rmi.RemoteException;

public interface HelloIF extends java.rmi.Remote {

public String sayHello() throws java.rmi.RemoteException;

}

HelloImpl.java

package hello;

public class HelloImpl implements HelloIF{

public String sayHello() {

return “Hello to WebService World.”;

}

}

web.xml

<?xml version=”1.0″ encoding=”UTF-8″ ?>

<!DOCTYPE web-app PUBLIC “-//Sun Microsystems,Inc.//DTD Web Application 2.3//EN” “http://java.sun.com/j2ee/dtds/webapp_2_3.dtd”>

<web-app>

<display-name>Hello Service</display-name>

<description>

Returns a String saying Hello

</description>

</web-app>

jaxrpc-ri.xml

<?xml version=”1.0″ encoding=”UTF-8″?>

<webServices xmlns=”http://java.sun.com/xml/ns/jax-rpc/ri/dd”

version=”1.0″

targetNamespaceBase=”http://mysite.org/wsdl”

typeNamespaceBase=”http://mysite.org/types”

urlPatternBase=”/Hello”>

<endpoint

name=”Hello”

displayName=”Hello World”

description=”This is a Hello World Service”

wsdl=”/WEB-INF/Hello.wsdl”

interface=”hello.HelloIF”

implementation=”hello.HelloImpl”

/>

<endpointMapping

endpointName=”Hello”

urlPattern=”/hello”/>

</webServices>

Using wsdeploy tool:

Package all files in war folder into a portable WAR file

Use this command line in your “war\” directory:

> jar -cfv temp.war *.*

1. -c create new archive

2. -f specify archive file name

3. -v generate verbose output on standard output

* This packages up all of the files and directory structure into a portable WAR file.

* Make the WAR file deployable(also called cooking the raw war)

You should now run the wsdeploy command in your “war” folder:


> wsdeploy -verbose -o Hello.war temp.war

1. -o specify where to place the generated war file

2. -verbose output messages about what the compiler is doing

This tool converts the portable WAR file into an implementation specific WAR file by generating all of the tie classes and a WSDL file from your Java interface class.


Deploy Your Service on Server:

  • The final step is to copy your deployable WAR file, Hello.war, to the “webapps” folder of your JWSDP Tomcat installation. This should automatically deploy the web service contained in the WAR file into the server.
  • You Service will be available at http://IP-ADDRESS:PORTNO/Hello/hello
  • WSDL file available at http://IP-ADDRESS:PORTNO/Hello/hello?WSDL
  • Your Web Service is redy to be consumed by client.

Reference:

Ø http://java.sun.com/

Ø http://jax-rpc.dev.java.net/

Ø http://xyzws.com

Comments»

1. Web Service Client Development using JAX-RPC API « Ninad Gawad - August 26, 2007

[...] About « Web Service Endpoint Development using JAX-RPC [...]