<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    JBoss with Websphere MQ connection issue: DetailedIllegalStateException
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/harshildesai">Harshil Desai</a> in <i>Beginner's Corner</i> - <a href="https://community.jboss.org/message/716864#716864">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>We connect to WebspehereMQ for sending and receiving the JMS messages in our JBoss EAP 4.2 app server - this was all working fine. Now there has been an upgrade of the WMQ series from version 5.2 to 7. We have been provided with the new libraries and new hostName for making this change at our end.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have made the following changes:</p><p>- updated the hostName in custom datasource file <em>ful-jms-ds.xml&#160; </em>which looks like this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag">&lt;connection-factories&gt;</span>

&#160; <span class="jive-xml-tag">&lt;tx-connection-factory&gt;</span> 
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;jndi-name&gt;</span>MyTestQueueConnectionFactory<span class="jive-xml-tag">&lt;/jndi-name&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;xa-transaction /&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;rar-name&gt;</span>wmq.jmsra.rar<span class="jive-xml-tag">&lt;/rar-name&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;connection-definition&gt;</span>javax.jms.ConnectionFactory<span class="jive-xml-tag">&lt;/connection-definition&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;config-property name="channel" type="java.lang.String"&gt;</span>JAVA.CHANNEL<span class="jive-xml-tag">&lt;/config-property&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;config-property name="hostName" type="java.lang.String"&gt;</span>myserver<span class="jive-xml-tag">&lt;/config-property&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;config-property name="port" type="java.lang.String"&gt;</span>myport<span class="jive-xml-tag">&lt;/config-property&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;config-property name="queueManager" type="java.lang.String"&gt;</span>MYTEST.MW<span class="jive-xml-tag">&lt;/config-property&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;config-property name="transportType" type="java.lang.String"&gt;</span>CLIENT<span class="jive-xml-tag">&lt;/config-property&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;security-domain-and-application&gt;</span>JmsXARealm<span class="jive-xml-tag">&lt;/security-domain-and-application&gt;</span>
&#160; <span class="jive-xml-tag">&lt;/tx-connection-factory&gt;</span>

&#160; <span class="jive-xml-comment">&lt;!-- admin object definition Queue Setting --&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;mbean code="org.jboss.resource.deployment.AdminObject" name="jca.wmq:name=myTestQueue"&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;attribute name="JNDIName"&gt;</span>TestQueue<span class="jive-xml-tag">&lt;/attribute&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;depends optional-attribute-name="RARName"&gt;</span>jboss.jca:service=RARDeployment,name='wmq.jmsra.rar'<span class="jive-xml-tag">&lt;/depends&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;attribute name="Type"&gt;</span>javax.jms.Queue<span class="jive-xml-tag">&lt;/attribute&gt;</span> 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;attribute name="Properties"&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; baseQueueManagerName=MYTEST.MW
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; baseQueueName=MYTESTSQL.ECOMMERCEORDERS
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/attribute&gt;</span>
 <span class="jive-xml-tag">&lt;/mbean&gt;</span>
<span class="jive-xml-tag">&lt;/connection-factories&gt;</span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>- Replaced the deployer file <em>wmq.jmsra.rar </em>with the new one at <em>JBOSS_HOME/server/server_name/deploy/ </em>directory</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The JNDI lookup and connection creation is done from the Java class in the ear. There are no WMQ specific classes used in the java class hence no libraries need to be changed in the ear. Here is the method</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> sendMessage(String textMessage, String jndiQueueConnFactory , String jndiQueue) <font color="navy"><b>throws</b></font> JMSException , SystemException
&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Connection tempConnection = <font color="navy"><b>null</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>private</b></font> ConnectionFactory queueConnectionFactory_OFS;
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Context&#160; ctx = <font color="navy"><b>new</b></font> InitialContext();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font>(<font color="navy"><b>null</b></font> == queueConnectionFactory_OFS)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; queueConnectionFactory_OFS = (ConnectionFactory)ctx.lookup(jndiQueueConnFactory);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font>(<font color="navy"><b>null</b></font> == queue_OFS)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; queue_OFS = (Queue) ctx.lookup(jndiQueue);&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; tempConnection = queueConnectionFactory_OFS.createConnection();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; tempConnection.start();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Session session = tempConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MessageProducer producer = session.createProducer(queue_OFS);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TextMessage message = session.createTextMessage();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; message.setText(textMessage);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; producer.send(message);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font>(<font color="navy"><b>null</b></font> != tempConnection)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; tempConnection.stop();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; tempConnection.close();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>catch</b></font> (JMSException e) 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> <font color="navy"><b>new</b></font> SystemException(<font color="red">"JMSException while connecting to Queue"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>catch</b></font>(NamingException ne)&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> <font color="navy"><b>new</b></font> SystemException(<font color="red">"NamingException while connecting to Queue"</font>); 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160; <font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>When i send the JMS messages, the message do reach the new queues, however, there are exception in the logs which i suspect is coming while closing the connection:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">2012-02-13 07:47:35,302 ERROR [STDERR] com.ibm.msg.client.jms.DetailedIllegalStateException: MQJCA1031: The method can only be called in the application client container. 
The application was not running in the application client container when this method was called.&#160; Ensure that the application runs in the application client container, 
or modify the application to avoid this method call.
2012-02-13 07:47:35,303 ERROR [STDERR]&#160; at com.ibm.mq.connector.services.JCAExceptionBuilder.buildException(JCAExceptionBuilder.java:149)
2012-02-13 07:47:35,303 ERROR [STDERR]&#160; at com.ibm.mq.connector.services.JCAExceptionBuilder.buildException(JCAExceptionBuilder.java:86)
2012-02-13 07:47:35,303 ERROR [STDERR]&#160; at com.ibm.mq.connector.outbound.ConnectionWrapper.stop(ConnectionWrapper.java:221)
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Can you please help me. Let me know if you need any other information.</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/716864#716864">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Beginner's Corner at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>