Hi,

Jay SenSharma

Jay SenSharma

For normal JAXWS based WebServices we can use <wlhttptransport> the as a Child Element of  jwsc  anttask to change the Context-root and the ServiceURI like following:

.
<jwsc srcdir=”src” destdir=”output”>
<jws file=”examplesHelloService.java” type=”JAXWS”>
<wlhttptransport
contextPath=”weblogic” serviceUri=”sicasws”
portName=”RENOVACIO_PAS_UNICSOAP11port_http”>
</wlhttptransport>
</jws>
</jwsc>

But the Problem happens when we try to develop a JAXWS WebService which is Based on EJB3 … there We cannot use Tag as a Child tag of task to change the Context-Root of our WebService.
So in this case we can achieve it in the following Manner.

NOTE: It looks like a BUG of (WLS10.3 GA )  if you use generateDescriptors=”true”
in your <jws> task as an attribute then you won’t be able to deploy your JAXWS-EJB Based WebService … It will fail and  while deploying WebService you will find that WSDL is not found. So please try the sample in WLS10.3.1 or Higher. Or file a Bug for WLS10.3

Step1). Create a Directory in the Following some Location in your file system:

Example: C:EJB_JAXWS

Step2). Create a “src” directory inside “C:EJB_JAXWS”

Step3). Write “TransactionServiceBean.java” WebService which is EJB based inside “C:EJB_JAXWSsrc” Like following:

package ejbws;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.ejb.Stateless;

@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;}
}

Step4). Write the Ant “build.xml” file inside “C:EJB_JAXWS” location…

<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##################### -->
<target name="build-service">
<jwsc srcdir="src" destdir="${ear-dir}">
<jws file="TransactionServiceBean.java" type="JAXWS" generateDescriptors="true" />
</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##################### -->
<target name="client">
<clientgen wsdl="http://${wls.hostname}:${wls.port}/TransactionService/TransactionService?WSDL"
destDir="${clientclass-dir}"
packageName="test.client"/>
<javac srcdir="${clientclass-dir}" destdir="${clientclass-dir}" includes="**/*.java"/>
<javac srcdir="src" destdir="${clientclass-dir}" includes="test/client/**/*.java"/>
</target>

<!--#################Running##################### -->
<target name="run">
<java classname="maths.client.Main" fork="true" failonerror="true" >
<classpath refid="client.class.path"/>
<arg line="http://${wls.hostname}:${wls.port}/TransactionService/TransactionService" />
</java>
</target>
</project>

Step5). Run the “. ./setWLSEnv.sh” or “setWLSEnv.cmd” in a fresh command prompt and then move to “C:EJB_JAXWS” directory. Then run the Ant like following:

C:EJB_JAXWS> ant build-service

Step6). As soon as you run the “build-service” anttask then you will see that a Jar file “TransactionServiceBean.jar” is generated inside “C:EJB_JAXWSoutputTransactionBeanEar” Location.

Step7). As we have already used <jws file=”TransactionServiceBean.java” type=”JAXWS” generateDescriptors=”true” />

So It will generate the “META-INF/weblogic-webservices.xml” descriptor file inside the JAR “TransactionServiceBean.jar”.

Step8). Just extract the Jar File and then Edit “META-INF/weblogic-webservices.xml” file and change the “webservice-contextpath” and “webservice-serviceuri” according to your requirement:

ORIGINAL FILE BELOW:

<?xml version='1.0' encoding='UTF-8'?>
<weblogic-webservices xmlns="http://www.bea.com/ns/weblogic/weblogic-webservices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-webservices http://www.bea.com/ns/weblogic/weblogic-webservices/1.0/weblogic-webservices.xsd">
<webservice-description>
<webservice-description-name>ejbws.TransactionServiceBean</webservice-description-name>
<webservice-type>JAXWS</webservice-type>
<port-component>
<port-component-name>TransactionServiceBeanPort</port-component-name>
<service-endpoint-address>
<webservice-contextpath>TransactionServiceBean</webservice-contextpath>
<webservice-serviceuri>/TransactionServiceBeanService</webservice-serviceuri>
</service-endpoint-address>
</port-component>
</webservice-description>
</weblogic-webservices>

EDITED FILE BELOW:

<?xml version='1.0' encoding='UTF-8'?>
<weblogic-webservices xmlns="http://www.bea.com/ns/weblogic/weblogic-webservices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-webservices http://www.bea.com/ns/weblogic/weblogic-webservices/1.0/weblogic-webservices.xsd">
<webservice-description>
<webservice-description-name>ejbws.TransactionServiceBean</webservice-description-name>
<webservice-type>JAXWS</webservice-type>
<port-component>
<port-component-name>TransactionServiceBeanPort</port-component-name>
<service-endpoint-address>
<webservice-contextpath>ChangedContextPath</webservice-contextpath>
<webservice-serviceuri>/ChangedServiceUri</webservice-serviceuri>
</service-endpoint-address>
</port-component>
</webservice-description>
</weblogic-webservices>

Step9). Now again recreate the “TransactionServiceBean.jar” file with the Changes we made.

Step10). Now deploy the Service. Then you can see that the ContextRoot And ServiceURI is changed …

.

.

Try the Above Sample In the Higher Version of WLS10.3.GA….better try it in WLS10.3.2

NOTE: If you will use the <jws file=”TransactionServiceBean.java” type=”JAXWS” generateDescriptors=”true” explode=”true”  generatewsdl=”true”/> in your WLS 10.3 GA Then you will find some Exception like following while deploying your WebService:

deploy:
[wldeploy] weblogic.Deployer -verbose -noexit -name TransactionBeanEar -source C:EJB_JAXWSEJB_JAXWS_2outputTransactionBeanEar -targets
AdminServer -adminurl t3://localhost:7001 -user weblogic -password ******** -deploy
[wldeploy] weblogic.Deployer invoked with options:  -verbose -noexit -name TransactionBeanEar -source C:EJB_JAXWSEJB_JAXWS_2outputTransactionBeanEar -targets AdminServer -adminurl t3://localhost:7001 -user weblogic -deploy
[wldeploy] <May 20, 2010 1:27:14 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, TransactionBeanEar [archive: C:EJB_JAXWSEJB_JAXWS_2outputTransactionBeanEar], to AdminServer .>
[wldeploy] Task 19 initiated: [Deployer:149026]deploy application TransactionBeanEar on AdminServer.
[wldeploy] Task 19 failed: [Deployer:149026]deploy application TransactionBeanEar on AdminServer.
[wldeploy] Target state: deploy failed on Server AdminServer
[wldeploy] weblogic.wsee.ws.WsException: wsdl “META-INFTransactionServiceBeanService.wsdl” is not found in the deployment ExplodedJarFile{C:EJB_JAXWSEJB_JAXWS_2outputTransactionBeanEarTransactionServiceBean}
[wldeploy]
[wldeploy]
[wldeploy] Target Assignments:
[wldeploy] + TransactionBeanEar  AdminServer

BUILD FAILED
C:EJB_JAXWSEJB_JAXWS_2build.xml:43: weblogic.Deployer$DeployerException: weblogic.deploy.api.tools.deployer.DeployerException: Task 19 failed: [Deployer:149026]deploy application TransactionBeanEar on AdminServer.
Target state: deploy failed on Server AdminServer
weblogic.wsee.ws.WsException: wsdl “META-INFTransactionServiceBeanService.wsdl” is not found in the deployment ExplodedJarFile{C:EJB_JAXWS
EJB_JAXWS_2outputTransactionBeanEarTransactionServiceBean}

.
Thanks
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.