HI,

Jay SenSharma

Jay SenSharma

Here is a Simple Sample for using JAXRPC WebService  which uses JMS Tranport rather than HTTP …

Typically, client applications use HTTP/S as the connection protocol when invoking a WebLogic Web Service. You can, however, configure a WebLogic Web Service so that client applications use JMS as the transport instead. You configure transports using either JWS annotations or child elements of the jwsc Ant task, as described in later sections.

When a WebLogic Web Service is configured to use JMS as the connection transport, the endpoint address specified for the corresponding port in the generated WSDL of the Web Service uses jms:// in its URL rather than http://. An example of a JMS endpoint address is as follows:

jms://myHost:7001/transports/JMSTransport?URI=JMSTransportQueue

The URI=JMSTransportQueue section of the URL specifies the JMS queue that has been configured for the JMS transport feature. Although you cannot invoke the Web Service using HTTP, you can view its WSDL using HTTP, which is how the clientgen is still able to generate JAX-RPC stubs for the Web Service.

For each transport that you specify, WebLogic Server generates an additional port in the WSDL. For this reason, if you want to give client applications a choice of transports they can use when they invoke the Web Service (JMS, HTTP, or HTTPS), you should explicitly add the transports using the appropriate JWS annotations or child elements of jwsc.

Step1). Start WebLogic Server and Login to Admin Console…then Create a JMS Server Targeted to AdminServer Like Following : MyJMSServer

JMS_JAXRPC_WebService

JMS_JAXRPC_WebService

Step2). Create a JMS System Module: SystemModule-A

Step3). Inside the System Module Configure the JMS resources…and Create a ConnectionFactory and a Queue like following:

ConnectionFactory & Queue

ConnectionFactory & Queue

Step4. . Create Directory some where in your file system…like:

C:MyJMX_Servicesrc

Step5). Now write the WebService “JMSService.java” inside the “C:MyJMX_Servicesrc

package ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import weblogic.jws.*;
@WebService(name="JMSServicePortType", serviceName="JMSService", targetNamespace="http://example.org")
@WLJmsTransport(serviceUri="JMSService",portName="JMSServicePortJMS",contextPath="JMSService",connectionFactory="QCF",queue="TestQ")
public class JMSService
{
@WebMethod()
public String sayHello(String message)
{
System.out.println("sayHello:" + message);
return "Here is the message: '" + message + " --returned by EJB-SLSB'";
}
}

Step 6). Now The Client of this Service “Main.java” in “C:MyJMX_Servicesrc” Directory

package client;
import weblogic.wsee.jaxrpc.WLStub;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.Stub;
import test.client.*;

public class Main
{
public static void main(String[] args) throws ServiceException, RemoteException
{
JMSService service = new JMSService_Impl();
test.client.JMSServicePortType port=service.getJMSServicePortJMS();

Stub stub = (Stub) port;
stub._setProperty(WLStub.JMS_TRANSPORT_JNDI_URL, "t3://localhost:7001");
try {
String result = null;
result = port.sayHello("Hi there! ");
System.out.println( "nntGot JMS result: " + result );
}
catch (RemoteException e)
{
System.out.println("nnt Exception e: "+e);
}
}
}

Step 7 & 8). Now write the Ant Build to Build the Service …deploy…Generate the ClientArtifacts as well to run the Client.

<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="JMSServiceEar" />
<property name="example-output" value="output" />
<property name="ear-dir" value="${example-output}/JMSServiceEar" />
<property name="clientclass-dir" value="${example-output}/clientclasses"/>

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

<!--################# Task Definitions ##################### -->

<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,run" />

<!--#################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="JMSService.java"/>
    </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}/JMSService/JMSService?WSDL"
            destDir="${clientclass-dir}" packageName="test.client"/>
  <javac srcdir="${clientclass-dir}" destdir="${clientclass-dir}" includes="**/*.java"/>
  <javac srcdir="src" destdir="${clientclass-dir}" includes="**/*.java"/>
</target>
<!--#################Running##################### -->
<target name="run">
   <java classname="client.Main" fork="true" failonerror="true" >
      <classpath refid="client.class.path"/>
      <arg line="http://${wls.hostname}:${wls.port}/TransactionService/TransactionService" />
      <jvmarg value="-Dweblogic.security.TrustKeyStore=DemoTrust" />
   </java>
</target>
</project>

Step 9). Now open a command Window and then run “setWLSEnv.sh” or “setWLSEnv.cmd” then Just Run ant
OUTPUT:
C:MyJMX_Service>ant
Buildfile: build.xml
undeploy:
[wldeploy] weblogic.Deployer -verbose -noexit -name JMSServiceEar -targets AdminServer -adminurl t3://localhost:7001 -user weblogic -passwo
rd ******** -undeploy
[wldeploy] weblogic.Deployer invoked with options:  -verbose -noexit -name JMSServiceEar -targets AdminServer -adminurl t3://localhost:7001
-user weblogic -undeploy
[wldeploy] <Jan 27, 2010 11:32:57 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating undeploy operation for application, JMSServ
iceEar [archive: null], to AdminServer .>
[wldeploy] Task 2 initiated: [Deployer:149026]remove application JMSServiceEar on AdminServer.
[wldeploy] Task 2 completed: [Deployer:149026]remove application JMSServiceEar on AdminServer.
[wldeploy] Target state: undeploy completed on Server AdminServer
[wldeploy]
clean:
[delete] Deleting directory F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSoutput
build-service:
[jwsc] JWS: processing module /JMSService
[jwsc] Parsing source files
[jwsc] Parsing source files
[jwsc] 1 JWS files being processed for module /JMSService
[jwsc] JWS: F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSsrcJMSService.java Validated.
[jwsc] Compiling 2 source files to C:DOCUME~1DELLUS~1LOCALS~1Temp_5cpdw4
[jwsc] Building jar: F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSoutputJMSServiceEarJMSService.war
[jwsc] Created JWS deployment outputFile: F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSoutputJMSServiceEarJMSService.w
ar
[jwsc] [EarFile] Application File : F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSoutputJMSServiceEarMETA-INFapplicati
on.xml
[AntUtil.deleteDir] Deleting directory C:DOCUME~1DELLUS~1LOCALS~1Temp_5cpdw4
deploy:
[wldeploy] weblogic.Deployer -verbose -noexit -name JMSServiceEar -source F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSoutpu
tJMSServiceEar -targets AdminServer -adminurl t3://localhost:7001 -user weblogic -password ******** -deploy
[wldeploy] weblogic.Deployer invoked with options:  -verbose -noexit -name JMSServiceEar -source F:DELETEBLOG_REPLIESJMX_WebServiceJMS_
SSL_EJB_JAXRPC_WSoutputJMSServiceEar -targets AdminServer -adminurl t3://localhost:7001 -user weblogic -deploy
[wldeploy] <Jan 27, 2010 11:33:03 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, JMSServic
eEar [archive: F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSoutputJMSServiceEar], to AdminServer .>
[wldeploy] Task 3 initiated: [Deployer:149026]deploy application JMSServiceEar on AdminServer.
[wldeploy] Task 3 completed: [Deployer:149026]deploy application JMSServiceEar on AdminServer.
[wldeploy] Target state: deploy completed on Server AdminServer
[wldeploy]
[wldeploy] Target Assignments:
[wldeploy] + JMSServiceEar  AdminServer
client:
[clientgen] Ignoring JAX-WS options – building a JAX-RPC client
[clientgen]
[clientgen] *********** jax-rpc clientgen attribute settings ***************
[clientgen]
[clientgen] wsdlURI: http://localhost:7001/JMSService/JMSService?WSDL
[clientgen] serviceName : null
[clientgen] packageName : test.client
[clientgen] destDir : F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSoutputclientclasses
[clientgen] handlerChainFile : null
[clientgen] generatePolicyMethods : false
[clientgen] autoDetectWrapped : true
[clientgen] jaxRPCWrappedArrayStyle : true
[clientgen] generateAsyncMethods : true
[clientgen]
[clientgen] *********** jax-rpc clientgen attribute settings end ***************
[clientgen] Package name is test.client
[clientgen] DestDir is F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSoutputclientclasses
[clientgen] class name is JMSServicePortType_Stub
[clientgen] service class name is JMSService
[clientgen] Porttype name is JMSServicePortType
[clientgen] service impl name is JMSService_Impl
[javac] Compiling 4 source files to F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSoutputclientclasses
[javac] Note: F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSoutputclientclassestestclientJMSServicePortType_Stub.java
uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] Compiling 2 source files to F:DELETEBLOG_REPLIESJMX_WebServiceJMS_SSL_EJB_JAXRPC_WSoutputclientclasses
run:

[/java]

Got JMS result: Here is the message: ‘Hi there!  –returned by EJB-SLSB’

all:
BUILD SUCCESSFUL
Total time: 14 seconds
——————–
Step 10). Now login to Admin Console and then Monitor the Queue Message…
.
.
Thanks
Jay SenSharma
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.