Hi All,

Jay SenSharma

Jay SenSharma

In this Example we are going to publish an EJB3.0 into the JAX-WS WebService. For this purpose we need to use atleast @javax.ejb.Stateless and @javax.jws.WebService Annotations.
It depends on the requirement that we want to generate client side artifacts for this webservice using JAX-WS or JAX0RPC model.

(This application is intended to run in WebLogic-10 or it’s later versions because earlier versions of WebLogic doesn’t allow us to develope any JAXWS based webservices even previous versions doesnt support EJB3).

Step1). First of all we will write “TransactionServiceBean.java” EJB3.0 webService.

package ejbws;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;

import javax.jws.WebMethod;
import javax.jws.WebService;

@Stateless(mappedName="TransactionEJB")
@WebService
public class TransactionServiceBean
{
private SessionContext sc;

@WebMethod()
public String sayHello(String message)
{
System.out.println("sayHello:" + message);
return "Here is the message: '" + message + " --returned by EJB-SLSB'";
}

// Standard EJB methods. Typically there's no need to override the methods.
public void ejbCreate() { System.out.println("ntejbCreate() called...");}
public void ejbActivate(){ System.out.println("ntejbActivate() called...");}
public void ejbRemove() { System.out.println("nt ejbRemove() called...");}
public void ejbPassivate() { System.out.println("ntejbPassivate() called...");}
public void setSessionContext(SessionContext sc) { System.out.println("ntsetSessionContext(sc) called..."); this.sc=sc;}
}

Step2). Now we are going to write the ABT build.xml file sothat we can easily compile the JWS class as well we can make an EAR out of it using the JWSC Task provided by WebLogic. In the same ANT script we are going to use CLIENTGEN Task also sothat we can generate the Client Side Artifacts to hit this WebService.
“build.xml”

<project name="webservices-Maths_world" default="all">
<!-- set global properties for this build -->
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="weblogic" />
<property name="wls.hostname" value="localhost" />
<property name="wls.port" value="7001" />
<property name="wls.server.name" value="AdminServer" />
<property name="ear.deployed.name" value="TransactionBeanEar" />
<property name="example-output" value="output" />
<property name="ear-dir" value="${example-output}/TransactionBeanEar" />
<property name="clientclass-dir" value="${example-output}/clientclasses"/>

<path id="client.class.path">
<pathelement path="${clientclass-dir}"/>
<pathelement path="${java.class.path}"/>
</path>

<taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask" />
<taskdef name="clientgen" classname="weblogic.wsee.tools.anttasks.ClientGenTask" />
<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<target name="all" depends="clean,build-service,deploy,client" />

<!--#################Cleaning##################### -->
<target name="clean" depends="undeploy">
<delete dir="${example-output}"/>
</target>

<!--#################Build-Service##################### -->
<!--########NOTE:   see we have specified here type="JAXWS"##### -->
<target name="build-service">
<jwsc srcdir="src" destdir="${ear-dir}">
<jws file="TransactionServiceBean.java" type="JAXWS"/>
</jwsc>
</target>

<!--#################Deploy##################### -->
<target name="deploy">
<wldeploy action="deploy" name="${ear.deployed.name}"
source="${ear-dir}" user="${wls.username}"
password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}" />
</target>

<!--#################UnDeploy##################### -->
<target name="undeploy">
<wldeploy action="undeploy" name="${ear.deployed.name}"
failonerror="false"
user="${wls.username}" password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}"
targets="${wls.server.name}" />
</target>

<!--#################Client Stuff Generation##################### -->
<!--########NOTE:   see we have specified here type="JAXWS"##### -->
<target name="client">
<clientgen  wsdl="http://${wls.hostname}:${wls.port}/TransactionService/TransactionService?WSDL"
destDir="${clientclass-dir}"
type="JAXWS"
packageName="test.client"/>
<javac srcdir="${clientclass-dir}" destdir="${clientclass-dir}" includes="**/*.java"/>
<javac srcdir="src" destdir="${clientclass-dir}" includes="test/client/**/*.java"/>
</target>
</project>

Step3). Now we need to set the ClassPath which should contain weblogic.jar, webservices.jar and ANT required Jars. So the easy way to setup the environment is to Just run %Weblogic_Domain/bin/%”setDomainEnv.cmd” file in the command prompt. It will prepare the Environment for us.

Step4). Now we need to just run the ant command.  So just type  “ant” in the command prompt where ever you have placed the build.xml file. The above ANT acript will compile the class, parse and validate  the JWS file, Make an archive of it, it is going to deploy this Archieve as well as it is going to generate the ClientSide artifacts too.

Step5). Once the Client side artifacts are generated we can Test this webService from AdminConsole. WebLogic provided inbuilt Test Client.

.

.

regards

Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.