4 Replies Latest reply on Feb 16, 2017 1:45 PM by Steve Warsa

    ClassCastException javax.naming.Reference cannot be cast to javax.jms.ConnectionFactory

    Steve Warsa Newbie

      When looking up a WebMethods connection factory in LDAP via the following connection definition, I get a classcastexception javax.naming.Reference cannot be cast to javax.jms.ConnectionFactory at com.sun.genericra.outbound.AbstractManagedConnectionFactory.initializeConnectionFactory(AbstractManagedConnectionFactory.java:187):

       

                          <connection-definitions>

                              <connection-definition class-name="com.sun.genericra.outbound.ManagedQueueConnectionFactory" jndi-name="java:/XXXConnectionFactory" pool-name="XXXConnectionFactory">

                                  <config-property name="ProviderIntegrationMode">

                                      jndi

                                  </config-property>

                                  <config-property name="ConnectionFactoryJndiName">

                                      cn=ClusterXXXConnectionFactory,ou=xxxxxxx,ou=xxxxxxxxx,ou=xxxx,dc=xxxx,dc=xxx

                                  </config-property>

                                  <config-property name="UserName">

                                      cn=xxx,ou=xxxxxx,ou=xxxxx,dc=xxxxxx,dc=xxxxx

                                  </config-property>

                                  <config-property name="JndiProperties">

                                      java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory,java.naming.provider.url=ldap://xxxxxxxxxxxxx:nnn

                                  </config-property>

                                  <config-property name="Password">

                                      xxxxxxx

                                  </config-property>

                                  <pool>

                                      <initial-pool-size>0</initial-pool-size>

                                  </pool>

                              </connection-definition>

                          </connection-definitions>

       

      The great thing is I'm getting the exact same xml object that I can see under that LDAP address in an LDAP browser, so I know that the connection to LDAP is working.

       

      The problem is that The code that is trying to cast the response (com.sun.genericra.outbound.AbstractManagedConnectionFactory.initializeConnectionFactory) looks like this:

       

          private void initializeConnectionFactory() throws ResourceException {

              if (this.connectionFactory == null) {

                  ObjectBuilder cfBuilder = null;

                  ObjectBuilderFactory obf = new ObjectBuilderFactory();

       

       

                  if (this.getProviderIntegrationMode().equalsIgnoreCase(Constants.JNDI_BASED)) {

                      cfBuilder = obf.createUsingJndiName(this.getConnectionFactoryJndiName(),

                              this.getJndiProperties());

                  } else {

                      cfBuilder = obf.createUsingClassName(getActualConnectionFactoryClassName());

                      cfBuilder.setProperties(this.getConnectionFactoryProperties());

                  }

       

       

                  String setMethod = this.getCommonSetterMethodName();

       

       

                  if (!StringUtils.isNull(setMethod)) {

                      cfBuilder.setCommonSetterMethodName(setMethod);

                  }

       

       

                  this.connectionFactory = (ConnectionFactory) cfBuilder.build();

              }

          }

       

      Notice the lines in bold.  The code is blowing up on that line, when it tries to cast the result of cfBuilder.build() to a javax.jms.ConnectionFactory.  Here is the actual queue connection factory meta data that is stored on LDAP that the remote call is retrieving:

       

      Reference Class Name: com.webmethods.jms.impl.WmQueueConnectionFactoryImpl

      Type: com.webmethods.jms.impl.WmQueueConnectionFactoryImpl

      Content:

      <?xml version="1.0" encoding="UTF-8"?><queue-connection-factory version="3.0">

      <properties>

      <entry key="clusterName" value="XXXXXXXX"/>

      <entry key="application" value="JMS"/>

      <entry key="brokerListOrder" value="RANDOM"/>

      <entry key="sslTruststoreType" value="XXXX"/>

      <entry key="brokerCluster" value="XXXXXXXXXXXXXX"/>

      <entry key="clusterPolicyName" value="ROUND_ROBIN"/>

      <entry key="includeAllBrokers" value="true"/>

      <entry key="clientGroup" value="JMSClient"/>

      <entry key="clusterCreatedTime" value="1310162227362"/>

      <entry key="brokerHost" value="XXXXXXXXXXXXXXXX"/>

      <entry key="multisendcount" value="0"/>

      <entry key="brokerName" value="XXXXXXXXXXXXXX"/>

      <entry key="sslEncrypted" value="false"/>

      <entry key="sslKeystoreType" value="XXXXXXX"/>

      <entry key="clusterPolicyOverride" value="false"/>

      <entry key="clusterRefreshInterval" value="86400000"/>

      </properties>

      </queue-connection-factory>

       

      So, I'm just wondering, am I missing something in the connection definition or have I mis-configured something?

       

      Thanks,

      Steve

        • 1. Re: ClassCastException javax.naming.Reference cannot be cast to javax.jms.ConnectionFactory
          Steve Warsa Newbie

          Interestingly enough, if I add the following jars (which are already in the deployed webMethods RAR file) to my EAR file (and my WAR's manifest file - note - we keep all our 3rd party jars at the EAR level so that they can be used in multiple modules if needed):

           

          wm-brokerclient.jar

          wm-g11nutils.jar

          wm-jmsclient.jar

          wm-jmsnaming.jar

          genericra.jar

           

          Then I get a different error (without making any other configuration changes:

           

          Caused by: java.lang.ClassCastException: com.webmethods.jms.impl.WmQueueConnectionFactoryImpl cannot be cast to javax.jms.XAQueueConnectionFactory and this error occurs at:

           

          com.sun.genericra.outbound.ManagedQueueConnectionFactory.createXAConnection(ManagedQueueConnectionFactory.java:50)

           

          I'm not sure what that is telling me...

           

          Steve

          • 2. Re: ClassCastException javax.naming.Reference cannot be cast to javax.jms.ConnectionFactory
            Anup Dey Apprentice

            Hi,

             

            You are missing some JARs of MQ Client to get this working. Make sure you have the required MQ jars in your classpath.

             

            Well, WebSphere JMS is an IBM product and, to be honest, the question which JARs need to be included to use is really a question for IBM.

             

            I believe that it would be success by including all the following JARs from IBM:

             

            - com.ibm.mq.jmqi.jar

            - com.ibm.mqjms.jar

            - dhbcore.jar

            - fscontext.jar

            - providerutil.jar

            - com.ibm.mq.headers.jar

             

            Later versions of WebSphere MQ are provided with all the driver classes packaged. However, I don't believe IBM has provided this support before version 7.0, so you'll probably need to bundle the JARs into your application.

            • 3. Re: ClassCastException javax.naming.Reference cannot be cast to javax.jms.ConnectionFactory
              Steve Warsa Newbie

              Hi Anup,

               

              Thanks for the response, however, I'm not using WebSphere MQ, so I don't think adding those jars would be relevant in my case.  I'm using webMethods broker via LDAP from JBoss.

               

              Thanks,

              Steve

              • 4. Re: ClassCastException javax.naming.Reference cannot be cast to javax.jms.ConnectionFactory
                Steve Warsa Newbie

                OK, well, I have good news - I got past the problem.  The key was to set SupportsXA to false

                 

                                    <config-property name="SupportsXA">

                                        false

                                    </config-property>

                 

                and then to remove everything XA related (except for SupportsXA=false) from the ra.xml that was in the webMethods RAR file.  For example:

                 

                <config-property>

                  <description>XAConnectionFactoryClassName </description>

                  <config-property-name>XAConnectionFactoryClassName</config-property-name>

                  <config-property-type>java.lang.String</config-property-type>

                  <config-property-value>com.webmethods.jms.impl.WmXAConnectionFactoryImpl</config-property-value>

                  </config-property>

                 

                <config-property>

                  <description>XAQueueConnectionFactoryClassName </description>

                  <config-property-name>XAQueueConnectionFactoryClassName</config-property-name>

                  <config-property-type>java.lang.String</config-property-type>

                  <config-property-value>com.webmethods.jms.impl.WmXAQueueConnectionFactoryImpl</config-property-value>

                  </config-property>

                 

                  <config-property>

                  <description>XATopicConnectionFactoryClassName </description>

                  <config-property-name>XATopicConnectionFactoryClassName</config-property-name>

                  <config-property-type>java.lang.String</config-property-type>

                  <config-property-value>com.webmethods.jms.impl.WmXATopicConnectionFactoryImpl</config-property-value>

                  </config-property>

                 

                            <transaction-support>

                                XATransaction

                            </transaction-support>

                 

                Then it worked.

                 

                FYI,

                Steve