An external client (i.e., outside of WebSphere Process Server) may need to interact with an application installed in WebSphere Process Server.
The service is exported using a JMS binding, this makes the service available to external clients.
When you have an external client in a Java virtual machine (JVM) separate from WebSphere Process Server, there are several steps you must take in order to make a connection and interact with a JMS Export. The client obtains an InitialContext with the correct values then look up the resources through JNDI. The client then using JMS 1.1 spec client to access the destinations and send and receive messages on the destinations. The default JNDI names of the resources created automatically by the runtime are listed in table xyz. If you have pre-created resources then use those JNDI names.
ConnectionFactory conFact; Connection conn; Session sess; Destination requestQueue, responseQueue; MessageProducer requestProducer; MessageConsumer replyConsumer; String jmsRequestQName = "jms/ExportIn"; String jmsReplyQName = "jms/ExportOut"; String jmsFactoryName = "jms/MyCF"; // the initial context factory to be used to get the JNDI initial context String jndiFactoryName = "com.ibm.websphere.naming.WsnInitialContextFactory"; // URL for bootstrapping, containing ip address of WPS host machine // and bootstrapping port that by default is 2809 // you should change it to the values of your host:port String jmsContextURL = "iiop://9.26.237.246:2809/"; TextMessage jmsRequestMessage, jmsReplyMessage; // this is the serialized business object “order”, // we have it already serialized as a String in order to avoid // the extra complexity of serialization to this sample. String message = " " String message = "<order:Order xsi:type=\"order:Order\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:order=\"http://OrderProcessing\"> " + "<orderId>123</orderId>" + "<customerId>456</customerId>" + "<orderDate>2002-01-01Z</orderDate>" + "<orderStatus>Reject</orderStatus>" + "<totalPrice>1000.0</totalPrice>" + "</order:Order>"; System.out.println("JMS Factory name:" + jmsFactoryName); System.out.println("Queue Factory name:" + jmsRequestQName); System.out.println("Initial Context Provider URL:" + jmsContextURL); System.out.println(); try { Hashtable jndiHash = new Hashtable(); jndiHash.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, jndiFactoryName); jndiHash.put(javax.naming.Context.PROVIDER_URL, jmsContextURL); javax.naming.Context ctx = new InitialContext(jndiHash); System.out.println("Got Initial Context from provider: " + jmsContextURL); conFact = (ConnectionFactory) ctx.lookup(jmsFactoryName); if (conFact != null) { System.out.println("Got Connection Factory: " + jmsFactoryName); System.out.println(conFact.toString()); } conn = conFact.createConnection(); conn.start(); System.out.println("Created Queue Connection..."); System.out.println(conn.toString()); sess = conn.createSession(true, Session.AUTO_ACKNOWLEDGE); System.out.println("created Session..."); System.out.println(sess.toString()); System.out.println(conn.toString()); requestQueue = (Queue) ctx.lookup(jmsRequestQName); if (requestQueue != null) { System.out.println("Found JMS request Destination " + jmsRequestQName); System.out.println(requestQueue.toString()); } responseQueue = (Queue) ctx.lookup(jmsReplyQName); if (requestQueue != null) { System.out.println("Found JMS reply-to Queue " + jmsReplyQName); } requestProducer = sess.createProducer(requestQueue); System.out.println("Created Sender..."); jmsRequestMessage = sess.createTextMessage(); System.out.println("Creating Message..."); jmsRequestMessage.setText(message); jmsRequestMessage.setJMSReplyTo(responseQueue); jmsRequestMessage.setStringProperty("TargetFunctionName", "submitOrderRequestResponse"); requestProducer.send(jmsRequestMessage); sess.commit(); System.out.println("MESSAGE SENT!"); System.out.println(); System.out.println("JMS Correlation ID: "); String corrID = jmsRequestMessage.getJMSCorrelationID(); if (corrID != null) { System.out.println(jmsRequestMessage.getJMSCorrelationID()); } else { System.out.println("NULL"); } System.out.println(); System.out.println("JMS Message: "); System.out.println(jmsRequestMessage.toString()); System.out.println(); System.out.println("WAITING FOR THE RESPONSE..."); System.out.println(); responseQueue = (Queue) ctx.lookup(jmsReplyQName); if (responseQueue != null) { System.out.println("Found JMS response Destination " + jmsReplyQName); System.out.println(responseQueue.toString()); } else { System.out.println("JMS response Destination not found: " + jmsReplyQName); } replyConsumer = sess.createConsumer(responseQueue); jmsReplyMessage= (TextMessage)replyConsumer.receive(10000); if (jmsReplyMessage != null) { System.out.println("MESSAGE RECEIVED!!"); System.out.println(); System.out.println("JMS Message: "); System.out.println(jmsRequestMessage.toString()); } else { System.out.println("DIDN'T FIND MESSAGE IN THE REMOTE QUEUE: " + jmsReplyQName); } sess.commit(); requestProducer.close(); replyConsumer.close(); sess.close(); conn.close(); } catch (Exception j) { System.out.println("There was an exception, (for whole stack trace look in SystemErr.log): " + j.getMessage()); j.printStackTrace(); }
Last updated: Wed 06 Dec 2006 07:08:08
(c) Copyright IBM Corporation 2005, 2006.
This information center is powered by Eclipse technology (http://www.eclipse.org)