users@glassfish.java.net

Re: About the [MQ Scheme] and [MQ Service] in glassfish's JMS Service Configurations.

From: xuqingkang2 <xuqingkang2_at_163.com>
Date: Thu, 15 Jul 2010 13:42:48 +0800 (CST)

I hava tried to use MQ connection factory(not a RA connection factory), and it successed.
But,there seems to be some misunderstand,why the connection factory which created and configured on admin console(http://localhost:4848) can't not get the connection to mq broker.
 My appclient is simple,code are like following, and the "jms/connFac" Connection Factory had been configured with addressList(http://localhost:8080/httpjms/tunnel).
 The problem is that,once I configured the [MQ Scheme] as "http",it always use the URL(http://$host:$mq-primary-port/...) bases on the JMS Service's configuration rather than one of addressList when use the connection factory managed by glassfish server.even through run the client by using Application Client Container.
  ---
import java.util.Properties;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

public class Main {
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  new Main();
 }
 /* (non-Java-doc)
  * @see java.lang.Object#Object()
  */
 public Main() {
  Properties properties = new Properties();
  properties.setProperty(InitialContext.URL_PKG_PREFIXES,
    "com.sun.enterprise.naming");
  properties.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,
    "com.sun.enterprise.naming.SerialInitContextFactory");
  properties.setProperty(InitialContext.STATE_FACTORIES,
    "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
  properties.setProperty(InitialContext.PROVIDER_URL, "localhost:3700");
  Context context;
  Connection conn = null;
  Session session = null;
  try {
   context = new InitialContext(properties);
   ConnectionFactory connectionFactory = (ConnectionFactory)context.lookup("jms/connFac");
   System.out.println("Found JMS Connection Factory From JNDI Context.");
   conn = connectionFactory.createConnection();
   session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   
   Queue queue = (Queue)context.lookup("jms/queue");
   MessageProducer producer = session.createProducer(queue);
   TextMessage message = session.createTextMessage("This is Test Message.");
   conn.start();
   producer.send(message);
   System.out.println("Send Message successfully.");
   
   MessageConsumer consumer = session.createConsumer(queue);
   Message receivedMessage = consumer.receive();
   if(receivedMessage != null){
    System.out.println("Received Message:" + receivedMessage.toString());
   }else{
    System.err.println("No Message...");
   }
   System.exit(0);
  } catch (Exception e) {
   e.printStackTrace();
  }finally{
   try {
    conn.close();
   } catch (JMSException e) {
    e.printStackTrace();
   }
  }
 }
}
---
 
>A remote client (using ACC) needs its connection factory to have the correct addressList property so that it knows to
>connect to the MQ broker via the tunnel servlet (e.g. http://localhost:8080/httpjms/tunnel) rather than connecting
>directly to the broker via TCP. Note this configuration property only affects client connections. You have to configure
>the broker and tunnel servlet separately.
>
>Have you tried creating the MQ connection factory programmatically? This will allow you to confirm whether the problem
>is on your client or not.
>
>QueueConnectionFactory queueConnectionFactory = new com.sun.messaging.QueueConnectionFactory();
>queueConnectionFactory.setProperty("imqAddressList", "http://localhost:8080/httpjms/tunnel");
>QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
>
>(Note that since this is a MQ connection factory, not a RA connection factory, the property you need to configure is
>imqAddressList rather than addressList).
>
>Nigel
>
>P.S. Did you modify the Application Servers Security Policy File, as described in the the admin guide?
>http://docs.sun.com/app/docs/doc/821-0027/aeopp?l=en&a=view&q=Enabling+HTTP%2FHTTPS+Support
>I don't know whether this is relevant, but you didn't mention it.
>
>xuqingkang2 wrote, on 14/07/2010 13:12:
>> Hi Nigel:
>> Thank you!
>> I have tested it in Application Client Container(use
>> glassfish/bin/appclient.bat), It also failed due to same exception.
>> I am confused, what's the purpose of letting user configure the [MQ
>> Scheme] and [MQ Service]?
>> Letting user configure the [MQ Scheme] and [MQ Service] put the
>> integration of Open MQ and glassfish in confusion, I think. Because
>> following opinion:
>> --> Specified [MQ Scheme] as http,but glassfish hadn't auto configure
>> the mq broker to support http connection service(User must modify the
>> config.properties file manually.)
>> -->Specified [MQ Scheme] as http,but glassfish hadn't auto use the http
>> listener port in URL.
>> --> Specified [MQ Scheme] as http,for disposing glassfish use the http
>> listener port in URL, It is neccessary to create one another JMS
>> Host(whose port is http listener's port);in addition if so,MQ's type
>> must be the Remote,Because when Local/Embedded glassfish willn't be
>> startup because port conflict(glassfish's http listener and mq use the
>> same port.);furthermore, i must use another web container for deploying
>> the HTTP Tunnel Servlet,Because in glassfish JMS Service's startup
>> precede web container in time,so JMS Service's startup always failed due
>> to Servlet can't be used.
>> --> and so on...
>>
>> >The JMS Resource Adapter (which is the class that is throwing that
>> exception) is only for use within the application
>> >client container, or the Glassfish server itself. And because you
>> defined your connection factory in Glassfish it is
>> >configured to use a resource adapter.
>> >
>> >If you want to define your connection factories using Glassfish's JNDI
>> you need to use the Application Client Container
>> >(see http://docs.sun.com/app/docs/doc/820-4336/beaku?a=view for how to
>> use this).
>> >
>> >(You could also by-pass Glassfish altogether and use a simple MQ
>> client, creating your connection factory either in code
>> >or using the MQ admin console).
>> >
>> >Nigel
>> >
>> >
>> >xuqingkang2 wrote, on 14/07/2010 02:34:
>> >> Hi Nigel:
>> >> Thanks for you reply.
>> >> I am not using the Application Client Container, I only coded one Java
>> >> Main class(add glassfish's jar to classpath) and run it.
>> >> I had configured jms connection factory with two properties(AddressList
>> >> and imqAddressList:value is http://localhost:8080/httpjms/tunnel), but
>> >> it always failed because the same exception which has been mentioned
>> >> previously. It has nothing to do with the AddressList or imqAddressList
>> >> of jms connection factory. When i try to get connection from jms
>> >> connection factory lookuped from JNDI,It always use the
>> >> [http://$host:7676/httpjms],it uses the MQ's primary port(7676) rather
>> >> than the http listener's port.This URL is not right obviously.
>> >>
>> >> At 2010-07-14 01:06:05£¬"Nigel Deakin" <nigel.deakin_at_oracle.com> wrote:
>> >>
>> >> The steps you describe for deploying the tunnel servlet and
>> >> configuring the MQ broker seem just fine. I would expect you to be
>> >> able to connect to this broker from a client (running in a separate
>> >> JVM) using imqAddressList=http://localhost:8080/httpjms/tunnel .
>> >>
>> >> Is your client using the Application Client Container?
>> >>
>> >> Your description doesn't make clear that value of imqAddressList the
>> >> exception you give relates to. If your connection factory is
>> >> configured with imqAddressList=http://localhost:8080/httpjms/tunnel,
>> >> exactly what exception is logged on the client?
>> >>
>> >> Nigel
>> >>
>> >>
>> >> xuqingkang2 wrote, on 12/07/2010 08:51:
>> >>> Hi All:
>> >>> I want use HTTP connection Service of Open MQ in glassfish, but i
>> >>> can't do it,Please help me!
>> >>> I have do following setting:
>> >>> 1,Configure the Open MQ for supporting HTTP Service(add "httpjms"
>> >>> to imq.service.activelist),the
>> >>> domains/domain1/imq/instances/imqbroker/props/config.properties is
>> >>> like
>> >>> ---
>> >>> imq.service.activelist=jms,admin,httpjms
>> >>> ---
>> >>> 2,start glassfish v2.1.1's domain
>> >>> 3,deploy the Web Application which contains HTTP Tunnel Servlet to
>> >>> glassfish's DAS, Specify "httpjms" as Context root.
>> >>> So far,I checked the Open MQ and HTTP Tunnel Servlet.
>> >>> I use [imqcmd list svc],I looked following message which means
>> >>> Http Service had been startup along with Open MQ's startup.
>> >>> -----------------------------------------------
>> >>> Service Name Port Number Service State
>> >>> -----------------------------------------------
>> >>> admin 3697 (dynamic) RUNNING
>> >>> httpjms - RUNNING
>> >>> httpsjms - UNKNOWN
>> >>> jms 3695 (dynamic) RUNNING
>> >>> I open Browser, visit URL[http://localhost:8080/httpjms/tunnel],I
>> >>> have seen following message which means HTTP Tunnel Servlet work well.
>> >>> ---
>> >>> HTTP tunneling servlet ready.
>> >>> Servlet Start Time : Mon Jul 12 11:47:52 CST 2010
>> >>> Accepting TCP connections from brokers on port : 7675
>> >>>
>> >>> Total available brokers = 1
>> >>> Broker List :
>> >>>
>> >>> localhost:imqbroker
>> >>>
>> >>>
>> >>> 4,create a JMS Connection Factory(JNDI Name is:jms/connFac)
>> >>> 5,Use following Java Code for get Connection from "jms/connFac",
>> >>> But it failed.I add the "AddressList"
>> >>> property(value:http://localhost:8080/httpjms/tunnel) to
>> >>> "jms/connFac", it also failed because the same exception.
>> >>> Please tell me how can i get the connection from "jms/connFac"
>> >>> while specified "http" as the JMS Service's MQ schema.
>> >>> ---
>> >>> Properties properties = new Properties();
>> >>> properties.setProperty(InitialContext.URL_PKG_PREFIXES,
>> >>> "com.sun.enterprise.naming");
>> >>> properties.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,
>> >>> "com.sun.enterprise.naming.SerialInitContextFactory");
>> >>> properties.setProperty(InitialContext.STATE_FACTORIES,
>> >>> "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
>> >>> properties.setProperty(InitialContext.PROVIDER_URL, "localhost:3700");
>> >>> Context context;
>> >>> Connection conn = null;
>> >>> Session session = null;
>> >>> try {
>> >>> context = new InitialContext(properties);
>> >>> ConnectionFactory connectionFactory =
>> >>> (ConnectionFactory)context.lookup("jms/connFac");
>> >>> System.out.println("Found JMS Connection Factory From JNDI Context.");
>> >>> conn = connectionFactory.createConnection();
>> >>> session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
>> >>> ......
>> >>> The exception message are:
>> >>> 2010-7-12 14:49:21 com.sun.messaging.jms.ra.ResourceAdapter start
>> >>> ÐÅÏ¢: MQJMSRA_RA1101: SJSMQ JMS Resource Adapter starting...
>> >>> 2010-7-12 14:49:22
>> >>> com.sun.messaging.jmq.jmsclient.ExceptionHandler
>> >>> throwConnectionException
>> >>> ¾¯¸æ: [C4003]: Error occurred on connection creation
>> >>> [http://borland-s:7676/httpjms]. - cause:
>> >>> java.net.ConnectException: Connection refused : Failed to receive
>> >>> response
>> >>> 2010-7-12 14:49:27
>> >>> com.sun.messaging.jmq.jmsclient.ExceptionHandler
>> >>> throwConnectionException
>> >>> ¾¯¸æ: [C4003]: Error occurred on connection creation
>> >>> [http://borland-s:7676/httpjms]. - cause:
>> >>> java.net.ConnectException: Connection refused : Failed to receive
>> >>> response
>> >>> 2010-7-12 14:49:32
>> >>> com.sun.messaging.jmq.jmsclient.ExceptionHandler
>> >>> throwConnectionException
>> >>> ¾¯¸æ: [C4003]: Error occurred on connection creation
>> >>> [http://borland-s:7676/httpjms]. - cause:
>> >>> java.net.ConnectException: Connection refused : Failed to receive
>> >>> response
>> >>> 2010-7-12 14:49:37
>> >>> com.sun.messaging.jmq.jmsclient.ExceptionHandler
>> >>> throwConnectionException
>> >>> ¾¯¸æ: [C4003]: Error occurred on connection creation
>> >>> [http://borland-s:7676/httpjms]. - cause:
>> >>> java.net.ConnectException: Connection refused : Failed to receive
>> >>> response
>> >>> 2010-7-12 14:49:42
>> >>> com.sun.messaging.jmq.jmsclient.ExceptionHandler
>> >>> throwConnectionException
>> >>> ¾¯¸æ: [C4003]: Error occurred on connection creation
>> >>> [http://borland-s:7676/httpjms]. - cause:
>> >>> java.net.ConnectException: Connection refused : Failed to receive
>> >>> response
>> >>> 2010-7-12 14:49:47
>> >>> com.sun.messaging.jmq.jmsclient.ExceptionHandler
>> >>> throwConnectionException
>> >>> ¾¯¸æ: [C4003]: Error occurred on connection creation
>> >>> [http://borland-s:7676/httpjms]. - cause:
>> >>> java.net.ConnectException: Connection refused : Failed to receive
>> >>> response
>> >>> 2010-7-12 14:49:52
>> >>> com.sun.messaging.jmq.jmsclient.ExceptionHandler
>> >>> throwConnectionException
>> >>> ¾¯¸æ: [C4003]: Error occurred on connection creation
>> >>> [http://borland-s:7676/httpjms]. - cause:
>> >>> java.net.ConnectException: Connection refused : Failed to receive
>> >>> response
>> >>> 2010-7-12 14:49:57
>> >>> com.sun.messaging.jmq.jmsclient.ExceptionHandler
>> >>> throwConnectionException
>> >>> ¾¯¸æ: [C4003]: Error occurred on connection creation
>> >>> [http://borland-s:7676/httpjms]. - cause:
>> >>> java.net.ConnectException: Connection refused : Failed to receive
>> >>> response
>> >>> 2010-7-12 14:50:02
>> >>> com.sun.messaging.jmq.jmsclient.ExceptionHandler
>> >>> throwConnectionException
>> >>> ¾¯¸æ: [C4003]: Error occurred on connection creation
>> >>> [http://borland-s:7676/httpjms]. - cause:
>> >>> java.net.ConnectException: Connection refused : Failed to receive
>> >>> response
>> >>> 2010-7-12 14:50:02 com.sun.messaging.jms.ra.ResourceAdapter start
>> >>> ÑÏÖØ: MQJMSRA_RA4001: start:Aborting:JMSException on
>> >>> createConnection=[C4003]: Error occurred on connection creation
>> >>> [http://borland-s:7676/httpjms]. - cause:
>> >>> java.net.ConnectException: Connection refused : Failed to receive
>> >>> response
>> >>> com.sun.messaging.jms.JMSException: [C4003]: Error occurred on
>> >>> connection creation [http://borland-s:7676/httpjms]. - cause:
>> >>> java.net.ConnectException: Connection refused : Failed to receive
>> >>> response
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.ExceptionHandler.throwConnectionException(ExceptionHandler.java:274)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.ExceptionHandler.handleConnectException(ExceptionHandler.java:232)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.protocol.http.HTTPConnectionHandler.<init>(HTTPConnectionHandler.java:93)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.protocol.http.HTTPStreamHandler.openConnection(HTTPStreamHandler.java:101)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.ConnectionInitiator.createConnection(ConnectionInitiator.java:778)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.ConnectionInitiator.createConnectionNew(ConnectionInitiator.java:254)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.ConnectionInitiator.createConnection(ConnectionInitiator.java:208)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.ConnectionInitiator.createConnection(ConnectionInitiator.java:158)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.ProtocolHandler.init(ProtocolHandler.java:836)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.ProtocolHandler.<init>(ProtocolHandler.java:1528)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.ConnectionImpl.openConnection(ConnectionImpl.java:2363)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.ConnectionImpl.init(ConnectionImpl.java:1044)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.ConnectionImpl.<init>(ConnectionImpl.java:430)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.UnifiedConnectionImpl.<init>(UnifiedConnectionImpl.java:60)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.XAConnectionImpl.<init>(XAConnectionImpl.java:58)
>> >>> at
>> >>>
>> com.sun.messaging.XAConnectionFactory.createXAConnection(XAConnectionFactory.java:91)
>> >>> at
>> >>>
>> com.sun.messaging.XAConnectionFactory.createXAConnection(XAConnectionFactory.java:69)
>> >>> at
>> >>>
>> com.sun.messaging.jms.ra.ResourceAdapter.start(ResourceAdapter.java:315)
>> >>> at
>> >>>
>> com.sun.enterprise.connectors.ActiveInboundResourceAdapter$1.run(ActiveInboundResourceAdapter.java:180)
>> >>> at java.security.AccessController.doPrivileged(Native Method)
>> >>> at
>> >>>
>> com.sun.enterprise.connectors.ActiveInboundResourceAdapter.startResourceAdapter(ActiveInboundResourceAdapter.java:174)
>> >>> at
>> >>>
>> com.sun.enterprise.connectors.ActiveInboundResourceAdapter.<init>(ActiveInboundResourceAdapter.java:132)
>> >>> at
>> >>>
>> com.sun.enterprise.connectors.system.ActiveJmsResourceAdapter.<init>(ActiveJmsResourceAdapter.java:234)
>> >>> at
>> >>>
>> com.sun.enterprise.connectors.ActiveRAFactory.createActiveResourceAdapter(ActiveRAFactory.java:107)
>> >>> at
>> >>>
>> com.sun.enterprise.connectors.ResourceAdapterAdminServiceImpl.createActiveResourceAdapter(ResourceAdapterAdminServiceImpl.java:300)
>> >>> at
>> >>>
>> com.sun.enterprise.connectors.ConnectorRuntime.createActiveResourceAdapter(ConnectorRuntime.java:212)
>> >>> at
>> >>>
>> com.sun.enterprise.naming.factory.ConnectorObjectFactory.getObjectInstance(ConnectorObjectFactory.java:101)
>> >>> at
>> >>>
>> javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
>> >>> at
>> >>> com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:414)
>> >>> at javax.naming.InitialContext.lookup(InitialContext.java:351)
>> >>> at JMSMessageProducer.main(JMSMessageProducer.java:35)
>> >>> Caused by: java.net.ConnectException: Connection refused : Failed
>> >>> to receive response
>> >>> at
>> >>>
>> com.sun.messaging.jmq.transport.httptunnel.client.HttpTunnelClientDriver.doConnect(HttpTunnelClientDriver.java:222)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.transport.httptunnel.HttpTunnelSocket.<init>(HttpTunnelSocket.java:64)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.jmsclient.protocol.http.HTTPConnectionHandler.<init>(HTTPConnectionHandler.java:91)
>> >>> ... 28 more
>> >>> Caused by: java.io.IOException: Failed to receive response
>> >>> at
>> >>>
>> com.sun.messaging.jmq.transport.httptunnel.client.HttpTunnelPush.sendPacketDirect(HttpTunnelPush.java:156)
>> >>> at
>> >>>
>> com.sun.messaging.jmq.transport.httptunnel.client.HttpTunnelClientDriver.doConnect(HttpTunnelClientDriver.java:163)
>> >>> ... 30 more
>> >>>
>> >>> Thanks in advance!
>> >>> ---
>> >>>
>> >>>
>> >>>
>> >>>
>> >>
>> >>
>> >
>> >---------------------------------------------------------------------
>> >To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> >For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>> >
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>