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-definition class-name="com.sun.genericra.outbound.ManagedQueueConnectionFactory" jndi-name="java:/XXXConnectionFactory" pool-name="XXXConnectionFactory">

                                  <config-property name="ProviderIntegrationMode">



                                  <config-property name="ConnectionFactoryJndiName">



                                  <config-property name="UserName">



                                  <config-property name="JndiProperties">



                                  <config-property name="Password">









      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(),


                  } else {

                      cfBuilder = obf.createUsingClassName(getActualConnectionFactoryClassName());





                  String setMethod = this.getCommonSetterMethodName();



                  if (!StringUtils.isNull(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


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


      <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"/>




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




        • 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):








          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:




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



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



            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.




              • 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">




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



                  <description>XAConnectionFactoryClassName </description>







                  <description>XAQueueConnectionFactoryClassName </description>







                  <description>XATopicConnectionFactoryClassName </description>










                Then it worked.