Forum Stats

  • 3,758,186 Users
  • 2,251,351 Discussions
  • 7,870,100 Comments

Discussions

Issue connecting to a remote JMS queue from standalone client

Sirish Reddy
Sirish Reddy Member Posts: 78 Blue Ribbon
edited Jan 4, 2013 1:28PM in Java Message Service (JMS)
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=7676

Service Locator design to implement resource caching
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
    }
}
Eventually sending message to the server:
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);
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.

Answers

  • >
    However using the above implementation, I am unsuccessful in achieving this....

    Any hints on resolving this would be highly appreciated.
    You don't actually say what went wrong. Did you get an error creating your InitialContext? Or did you get a JNDI lookup error? Or did something else happen?

    I suggest you repost your question on the GlassFish forum with some information abotu what went wrong
    http://www.java.net/forums/glassfish/glassfish

    If you haven't already seen this, what you are trying to do is documented in the GlassFish application development guide here:
    http://docs.oracle.com/cd/E26576_01/doc.312/e24930/java-clients.htm#gkuqa

    Nigel
    Nigel Deakin-Oracle
  • Sirish Reddy
    Sirish Reddy Member Posts: 78 Blue Ribbon
    Thanks Nigel! Issue still exists and I will follow up in Glassfish forums too.

    I have followed the exact steps from the GlassFish application server guide. However, I am still getting the same error. For some reason the application is always trying to look up on the local host.

    See the error message below:
    org.omg.CORBA.COMM_FAILURE: FINE: IOP00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700  vmcid: OMG  minor code: 1  completed: No
    	at sun.reflect.GeneratedConstructorAccessor37.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    	at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:248)
    	at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:95)
    	at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.handleFullLogging(WrapperGenerator.java:387)
    	at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.access$400(WrapperGenerator.java:107)
    	at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator$2.invoke(WrapperGenerator.java:511)
    	at com.sun.corba.ee.spi.orbutil.proxy.CompositeInvocationHandlerImpl.invoke(CompositeInvocationHandlerImpl.java:99)
    	at $Proxy27.connectFailure(Unknown Source)
    	at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:257)
    	at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:270)
    	at com.sun.corba.ee.impl.transport.SocketOrChannelContactInfoImpl.createConnection(SocketOrChannelContactInfoImpl.java:129)
    	at com.sun.corba.ee.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:223)
    	at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:228)
    	at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.is_a(CorbaClientDelegateImpl.java:393)
    	at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:130)
    	at org.omg.CosNaming.NamingContextHelper.narrow(NamingContextHelper.java:69)
    	at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNameService(SerialContext.java:1239)
    	at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:410)
    	at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:346)
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
    	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    	at javax.naming.InitialContext.lookup(InitialContext.java:411)
    	at com.sun.appserv.connectors.internal.api.ResourceNamingService.lookup(ResourceNamingService.java:223)
    	at com.sun.enterprise.connectors.service.ConnectorConnectionPoolAdminServiceImpl.getConnectorConnectionPool(ConnectorConnectionPoolAdminServiceImpl.java:870)
    	at com.sun.enterprise.connectors.service.ConnectorConnectionPoolAdminServiceImpl.getConnectorConnectionPool(ConnectorConnectionPoolAdminServiceImpl.java:853)
    	at com.sun.enterprise.connectors.service.ConnectorConnectionPoolAdminServiceImpl.getPoolType(ConnectorConnectionPoolAdminServiceImpl.java:1124)
    	at com.sun.enterprise.connectors.ConnectorRuntime.getPoolType(ConnectorRuntime.java:1091)
    	at com.sun.enterprise.resource.allocator.AbstractConnectorAllocator.createResourceHandle(AbstractConnectorAllocator.java:209)
    	at com.sun.enterprise.resource.allocator.ConnectorAllocator.createResource(ConnectorAllocator.java:163)
    	at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:907)
    	at com.sun.enterprise.resource.pool.ConnectionPool.createResource(ConnectionPool.java:1189)
    	at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:98)
    	at com.sun.enterprise.resource.pool.ConnectionPool.addResource(ConnectionPool.java:282)
    	at com.sun.enterprise.resource.pool.ConnectionPool.createResourceAndAddToPool(ConnectionPool.java:1512)
    	at com.sun.enterprise.resource.pool.ConnectionPool.createResources(ConnectionPool.java:944)
    	at com.sun.enterprise.resource.pool.ConnectionPool.initPool(ConnectionPool.java:230)
    	at com.sun.enterprise.resource.pool.ConnectionPool.internalGetResource(ConnectionPool.java:511)
    	at com.sun.enterprise.resource.pool.ConnectionPool.getResource(ConnectionPool.java:381)
    	at com.sun.enterprise.resource.pool.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:245)
    	at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:170)
    	at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:332)
    	at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:301)
    	at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:190)
    	at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)
    	at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:160)
    	at com.sun.messaging.jms.ra.ConnectionFactoryAdapter._allocateQueueConnection(ConnectionFactoryAdapter.java:239)
    	at com.sun.messaging.jms.ra.ConnectionFactoryAdapter.createQueueConnection(ConnectionFactoryAdapter.java:226)
    	at com.sun.messaging.jms.ra.ConnectionFactoryAdapter.createQueueConnection(ConnectionFactoryAdapter.java:208)
    	at gov.ca.lc.utilities.MessageDispatcher.sendMessageData(MessageDispatcher.java:22)
    	at gov.ca.lc.controllers.BillReferralController.saveBillReferral(BillReferralController.java:484)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1435)
    	at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
    	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
    	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
    	at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
    	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
    	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
    	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
    	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    	at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
    	at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)
    	at javafx.event.Event.fireEvent(Event.java:171)
    	at javafx.scene.Node.fireEvent(Node.java:6863)
    	at javafx.scene.control.Button.fire(Button.java:179)
    	at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:193)
    	at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:336)
    	at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:329)
    	at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:64)
    	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
    	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
    	at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
    	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
    	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
    	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
    	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
    	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    	at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
    	at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
    	at javafx.event.Event.fireEvent(Event.java:171)
    	at javafx.scene.Scene$MouseHandler.process(Scene.java:3324)
    	at javafx.scene.Scene$MouseHandler.process(Scene.java:3164)
    	at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3119)
    	at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1559)
    	at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2261)
    	at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:228)
    	at com.sun.glass.ui.View.handleMouseEvent(View.java:528)
    	at com.sun.glass.ui.View.notifyMouse(View.java:922)
    	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    	at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
    	at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
    	at java.lang.Thread.run(Thread.java:722)
    Caused by: java.lang.RuntimeException: java.net.ConnectException: Connection refused: connect
    	at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:339)
    	at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:242)
    	... 91 more
    Caused by: java.net.ConnectException: Connection refused: connect
    	at sun.nio.ch.Net.connect0(Native Method)
    	at sun.nio.ch.Net.connect(Net.java:364)
    	at sun.nio.ch.Net.connect(Net.java:356)
    	at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:623)
    	at com.sun.corba.ee.impl.orbutil.ORBUtility.openSocketChannel(ORBUtility.java:110)
    	at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:324)
    	... 92 more
    Jan 03, 2013 10:34:52 AM com.sun.enterprise.resource.allocator.AbstractConnectorAllocator createResourceHandle
    WARNING: RAR8067: Unable to determine pool type for pool [ jms/ReferralConnectionFactory ], using default pool type
    Thanks.
    nigeldeakin wrote:
    >
    However using the above implementation, I am unsuccessful in achieving this....

    Any hints on resolving this would be highly appreciated.
    You don't actually say what went wrong. Did you get an error creating your InitialContext? Or did you get a JNDI lookup error? Or did something else happen?

    I suggest you repost your question on the GlassFish forum with some information abotu what went wrong
    http://www.java.net/forums/glassfish/glassfish

    If you haven't already seen this, what you are trying to do is documented in the GlassFish application development guide here:
    http://docs.oracle.com/cd/E26576_01/doc.312/e24930/java-clients.htm#gkuqa

    Nigel
  • Sirish Reddy
    Sirish Reddy Member Posts: 78 Blue Ribbon
    Hmmm... Now I observe a strange behavior...

    I created a new GlassFish 3.1.2.2 server instance on the client machine with no jndi, no connection factories, and no jms queues what so ever.

    I have started this server instance and executed the standalone client application. Strangely, everything works fine and the message is directly being pushed to the remote queue.

    Did any one come across this kind of issue? I am suspecting that probably the application is loading the dependent GlassFish jars in the classpath only when a server instance (could be any random instance, totally unrelated) is started.

    I have the following jars in my standalone application classpath:

    *C:\Program Files\glassfish-3.1.2.2\glassfish\lib\gf-client.jar
    *C:\Program Files\glassfish-3.1.2.2\glassfish\lib\appserv-rt.jar
    *C:\Program Files\glassfish-3.1.2.2\glassfish\lib\install\applications\jmsra\imqbroker.jar
    *C:\Program Files\glassfish-3.1.2.2\glassfish\lib\install\applications\jmsra\imqjmsra.jar

    I have spent a lot of time on this and do not want to give up at this point. Any help on this issue would be highly appreciated.

    Thanks.
This discussion has been closed.