Exposing a Stateless Session Bean as a Web Service a la J2EE 1.4

Objectives

This labs will show you how to expose a Stateless Session Bean as a J2EE 1.4 compliant Web Service.
We will use a standalone client to invoke our service through SOAP (Simple Object Access Protocol)
.

UML 2 view

Write the HelloWorldEndPoint.java

package org.jyperion.ws14style;

import java.rmi.Remote;
import java.rmi.RemoteException;

/**
 * @author janaudyt
 */
public interface HelloWorldEndPoint extends Remote {
    public String hello(String name) throws RemoteException;
}

Generate the WSDL file from HelloWorldEndPoint.class

Use the axis-java2wsdl task for this:
    <!-- ================================= 
          target: java2wsdl              
         ================================= -->
    <target name="java2wsdl" depends="setup-env,compile">
    	<axis-java2wsdl classname="org.jyperion.ws14style.HelloWorldEndPoint" 
    		        namespace="http://jyperion.com/helloworld-service" 
    			location="http://jyperion.com" 
                 	serviceElementName="HelloWorldServiceEJB"
                 	servicePortName="HelloWorldPort"
    			style="rpc" 
    			use="literal" 
    			output="${wsdl}/${wsdl-file}">
    		<classpath>
    			<pathelement path="${classes}"/>
    			<path refid="all.classpath"/>
    		</classpath>
    	</axis-java2wsdl>
    </target>

Write the jaxrpc-mapping.xml file

Sorry, to task for this yet:
<?xml version="1.0" encoding="UTF-8"?>

<java-wsdl-mapping 
  xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://www.ibm.com/webservices/xsd/j2ee_jaxrpc_mapping_1_1.xsd"
  version="1.1">

  <package-mapping>
    <package-type>org.jyperion.ws14style</package-type>
    <namespaceURI>http://jyperion.com/helloworld-service</namespaceURI>
  </package-mapping>

</java-wsdl-mapping>

Write the webservices.xml file

Sorry, no task as well:
<?xml version="1.0" encoding="UTF-8"?>

<webservices xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:impl="http://com.underworld.crimeportal/ws4ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd"
  version="1.1">

  <webservice-description>
    <webservice-description-name>HelloWorldServiceEJB</webservice-description-name>
    <wsdl-file>META-INF/wsdl/helloworld.wsdl</wsdl-file>
    <jaxrpc-mapping-file>META-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
    <port-component>
      <port-component-name>HelloWorld</port-component-name>
      <wsdl-port>HelloWorldPort</wsdl-port>
      <service-endpoint-interface>org.jyperion.ws14style.HelloWorldEndPoint</service-endpoint-interface>
      <service-impl-bean>
        <ejb-link>HelloWorld</ejb-link>
      </service-impl-bean>
    </port-component>
  </webservice-description>
</webservices>

Create the EJB.jar file

The wsdl file goes under META-INF/wsdl, jaxrpc-mapping.xml and webservices.xml under META-INF:
    <!-- ================================= 
          target: packaging              
         ================================= -->
    <target name="packaging">
    	<mkdir dir="${classes}/META-INF"/>
    	<mkdir dir="${classes}/META-INF/wsdl"/>
    	
    	<copy todir="${classes}/META-INF">
    		<fileset dir="${meta-inf}"/>
    	</copy>
    	<copy file="${wsdl}/${wsdl-file}" todir="${classes}/META-INF/wsdl"/>
    	<copy file="${conf}/jaxrpc-mapping.xml" todir="${classes}/META-INF"/>
    	<copy file="${conf}/webservices.xml" todir="${classes}/META-INF"/>
    	
    	 <jar destfile="${dist}/${myjar}"
    	      basedir="${classes}"/>  
    </target>

Deployment

When depploying the jar, the console should show:
12:07:42,140 INFO  [EjbModule] Deploying HelloWorld
12:07:42,515 INFO  [EJBDeployer] Deployed: file:/C:/J2EE1.4/ZeLabs/_tools/jboss-4.0.0/server/default/deploy/helloworld-ws.jar
12:07:42,843 INFO  [WSDLFilePublisher] WSDL published to: file:/C:/J2EE1.4/ZeLabs/_tools/jboss-4.0.0/server/default/data/wsdl/helloworld-ws.jar/helloworld.wsdl
12:07:43,187 INFO  [AxisService] WSDD published to: C:\J2EE1.4\ZeLabs\_tools\jboss-4.0.0\server\default\data\wsdl\helloworld-ws.jar\HelloWorldServiceEJB.wsdd
12:07:44,109 INFO  [AxisService] Web Service deployed: http://localhost:8080/helloworld-ws/HelloWorldServiceEJB
12:07:44,359 INFO  [TomcatDeployer] deploy, ctxPath=/helloworld-ws, warUrl=file:/C:/J2EE1.4/ZeLabs/_tools/jboss-4.0.0/server/default/tmp/deploy/helloworld-ws.jar22869.war/
Open a browser and point it to http://localhost:8080/helloworld-ws/HelloWorldServiceEJB, you can click on the wsdl link and see:


Client part

Just download the labs - and you'll see the code: just use axis-wsdl2java

Exercise