users@glassfish.java.net

Issue connecting to a remote JMS queue from standalone client

From: <forums_at_java.net>
Date: Thu, 3 Jan 2013 12:44:23 -0600 (CST)

I had already posted this issue in JMS Forum [1] and was suggested to post
here too.
-------------------------------------------------------------------------------------
I am new to JMS and have an issue connecting to a remote JMS queue from my
standalone client. Any hints on resolving this issue would be highly
appreciated. Right now I have a JavaFX standalone application that runs on
multiple clients and a glassfish server 3.1.2.2 running on a remote Unix
machine. I am having a hard time pushing messages from my standalone app on
to the queue that is residing on the server.
-------------------------------------------------------------------------------------
Client Mc: Windows PC (No server installed) Remote Mc: Unix (GlassFish
3.1.2.2 installed)
-------------------------------------------------------------------------------------
*JMS resources on the server:* +JMS Destination Resource+ JNDI Name:
jms/ReferralQueue Physical Destination Name: ReferralQueue Resource Type:
javax.jms.Queue +JMS Connection Factory+ Pool Name:
jms/ReferralConnectionFactory JNDI Name: jms/ReferralConnectionFactory
Resource Type: javax.jms.QueueConnectionFactory JMS Service Type: Embedded
JMS Message Store Type: File *Client Side Code to connect to the server:*
+jms.properties:+ org.omg.CORBA.ORBInitialHost=UNIX MC URL
org.omg.CORBA.ORBInitialPort=3700
java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
+Service Locator design to implement resource caching+ {code}public class
JMSServiceLocator { private static JMSServiceLocator singletonService = null;
private static QueueConnectionFactory qFactory; private static Queue queue;
private InitialContext context; private static Properties properties = new
Properties(); private Map cache; static { try { singletonService = new
JMSServiceLocator(); } catch (Exception e) { //error handling } } private
JMSServiceLocator() { try { loadProperties(); context = new
InitialContext(properties); cache = Collections.synchronizedMap(new
HashMap()); } catch (Exception e) { //error handling } } public static
JMSServiceLocator getInstance() { return singletonService; } public
QueueConnectionFactory getQueueConnectionFactory() { String qConnFactoryName
= "jms/ReferralConnectionFactory"; qFactory = null; try {
System.out.println("/********************Comment after
Testing*****************************/"); Hashtable env =
context.getEnvironment(); System.out.println("**env.size::" + env.size());
Enumeration names = env.keys(); while (names.hasMoreElements()) { String str
= (String) names.nextElement(); System.out.println("**" + str + "=" +
env.get(str)); }
System.out.println("/**********************************************************************/");
if (cache.containsKey(qConnFactoryName)) { qFactory =
(QueueConnectionFactory) cache.get(qConnFactoryName); } else { qFactory =
(QueueConnectionFactory) context.lookup(qConnFactoryName);
cache.put(qConnFactoryName, qFactory); } } catch (Exception e) { //error
handling } return qFactory; } public Queue getQueue() { String queueName =
"jms/ReferralQueue"; queue = null; try { if (cache.containsKey(queueName)) {
queue = (Queue) cache.get(queueName); } else { queue = (Queue)
context.lookup(queueName); cache.put(queueName, queue); } } catch (Exception
e) { //error handling } return queue; } private static void loadProperties()
{ //Load jms properties } }{code} +Eventually sending message to the server:+
{code}JMSServiceLocator jmsLocator = JMSServiceLocator.getInstance();
QueueConnectionFactory qConnFactory = jmsLocator.getQueueConnectionFactory();
qConnection = qConnFactory.createQueueConnection(); session =
qConnection.createSession(false, ession.AUTO_ACKNOWLEDGE); queue =
jmsLocator.getQueue(); // Push and publish the message messageProducer =
session.createProducer(queue); textMessage = session.createTextMessage();
textMessage.setText(message); messageProducer.send(textMessage);{code}
-------------------------------------------------------------------------------------
However using the above implementation, I am unsuccessful in achieving this.
However I am able to achieve this if I have a server installed on the local
system too, with 'addresslist' property defined to my local server connection
factory. As I cannot install server on every client machine, this would not
work in my case. Any hints on resolving this would be highly appreciated.
Thanks.

[1]
https://forums.oracle.com/forums/thread.jspa?threadID=2482195&amp;tstart=0

--
[Message sent by forum member 'sirishvadala']
View Post: http://forums.java.net/node/893590