login button

WSO2 ESB 1.7 - Proxy with JMS destination type topic throws ClassCastException

Forums :

Hi,

we are trying to use a Proxy with a JMS with destination type topic. The esb throws a class cast exception.

CONFIG

<syn:proxy name="naturalClientProxy" transports="http" startOnLoad="true" trace="enable">
  <syn:target>
            <syn:endpoint>
                <syn:address uri="jms:/NaturalClient?transport.jms.ConnectionFactoryJNDIName=TopicConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616&amp;transport.jms.DestinationType=topic"/>
            </syn:endpoint>
            <syn:inSequence>
                <syn:property name="OUT_ONLY" value="true"/>
            </syn:inSequence>
            <syn:outSequence>
                <syn:send/>
            </syn:outSequence>
        </syn:target>
        <syn:publishWSDL uri="file:///config/wsdl/Test.wsdl"/>
</syn:proxy>

EXCEPTION

java.lang.ClassCastException: org.apache.activemq.ActiveMQQueueSession
 at org.apache.synapse.transport.jms.JMSUtils.createDestination(JMSUtils.java:766)
 at org.apache.synapse.transport.jms.JMSUtils.createDestinationIfRequired(JMSUtils.java:408)
 at org.apache.synapse.transport.jms.JMSSender.sendMessage(JMSSender.java:215)
 at org.apache.synapse.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:120)
 at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:448)
 at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:272)
 at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
 at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:288)
 at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:57)
 at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:222)
 at org.apache.synapse.endpoints.AddressEndpoint.send(AddressEndpoint.java:195)
 at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:179)
 at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:176)
 at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
 at org.apache.synapse.transport.nhttp.ServerWorker.processPost(ServerWorker.java:253)
 at org.apache.synapse.transport.nhttp.ServerWorker.run(ServerWorker.java:194)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
 at java.lang.Thread.run(Thread.java:595)
org.apache.synapse.SynapseException: Unexpected error during sending message out
 at org.apache.synapse.core.axis2.Axis2Sender.handleException(Axis2Sender.java:147)
 at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:64)
 at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:222)
 at org.apache.synapse.endpoints.AddressEndpoint.send(AddressEndpoint.java:195)
 at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:179)
 at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:176)
 at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
 at org.apache.synapse.transport.nhttp.ServerWorker.processPost(ServerWorker.java:253)
 at org.apache.synapse.transport.nhttp.ServerWorker.run(ServerWorker.java:194)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
 at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.ClassCastException: org.apache.activemq.ActiveMQQueueSession
 at org.apache.synapse.transport.jms.JMSUtils.createDestination(JMSUtils.java:766)
 at org.apache.synapse.transport.jms.JMSUtils.createDestinationIfRequired(JMSUtils.java:408)
 at org.apache.synapse.transport.jms.JMSSender.sendMessage(JMSSender.java:215)
 at org.apache.synapse.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:120)
 at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:448)
 at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:272)
 at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
 at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:288)
 at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:57)
 ... 10 more

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Can you check whether you

Can you check whether you have copied the right versions of the libraries from the activeMQ distribution (i.e. ActiveMQ client jar files)

This should be working without a problem because we have some samples which does exactly the same with ActiveMQ and they are working fine.

Ruwan Linton

Hi, thanks for the quick

Hi,

thanks for the quick answer.

I replaced the activemq-core-4.1.1.jar with activemq-core-5.1.0.jar. Still the same ClassCastException.

java.lang.ClassCastException: org.apache.activemq.ActiveMQQueueSession
 at org.apache.synapse.transport.jms.JMSUtils.createDestination(JMSUtils.java:766)
 ...

The queue examples works fine with both jars.

Thanks

UweTe

 

What is the version of the

What is the version of the WSO2-ESB that you are using?

Thanks,
Ruwan Linton

Hi we are using v1.7 UweTe

Hi

we are using v1.7

UweTe

Uwe Problem is you have

Uwe



Problem is you have specified the destination type as a Topic, but have supplied/configured a Queue session. Thus the problem seems to be in your axis2.xml. Can you check / attach it here?



Check if your "TopicConnectionFactory" of the form:



<parameter name="TopicConnectionFactory">

       <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>

       <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>

       <parameter name="transport.jms.ConnectionFactoryJNDIName">TopicConnectionFactory</parameter>

       <parameter name="transport.jms.ConnectionFactoryType" locked="false">topic</parameter>

</parameter>

Note that the JNDI name of the connection factory, and the logical name you use in an EPR are two different things, although you could use the same..

 

asankha

Hi, here is the axis2

Hi,

here is the axis2 configuration:

<transportSender name="jms" class="org.apache.synapse.transport.jms.JMSSender">
  <!-- uncomment this and configure to use connection pools for sending messages-->
  <parameter name="myTopicConnectionFactory">
    <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
    <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
    <parameter name="transport.jms.ConnectionFactoryJNDIName">TopicConnectionFactory</parameter>
    <parameter name="transport.jms.ConnectionFactoryType" locked="false">topic</parameter>
  </parameter>
  <parameter name="myQueueConnectionFactory">
    <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
    <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
    <parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter>
    <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
  </parameter>
  <parameter name="default">
    <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
    <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
    <parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter>
    <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
  </parameter>
</transportSender>

We changed <parameter name="myTopicConnectionFactory"> to <parameter name="TopicConnectionFactory">. But the same error.

We try to debug this problem.

Take a look at the class JMSConnectionFactory in the package org.apache.synapse.transport.jms.

We think that the method getPhysicalDestination(String destinationJndi) is returning the wrong destination for a topic.
 

Source code of the method.

    private Destination getPhysicalDestination(String destinationJndi) {
        Destination destination = null;

        try {
            destination = (Destination) context.lookup(destinationJndi);
        } catch (NamingException e) {

            // if we are using ActiveMQ, check for dynamic Queues and Topics
            String provider = (String) jndiProperties.get(Context.INITIAL_CONTEXT_FACTORY);
            if (provider.indexOf("activemq") != -1) {
                try {
                    destination = (Destination) context.lookup(
                        JMSConstants.ACTIVEMQ_DYNAMIC_QUEUE + destinationJndi);
                } catch (NamingException ne) {
                    try {
                        destination = (Destination) context.lookup(
                            JMSConstants.ACTIVEMQ_DYNAMIC_TOPIC + destinationJndi);
                    } catch (NamingException e1) {
                        log.warn("Error looking up destination for JNDI name : " + destinationJndi);
                    }
                }
            }
        }
        return destination;
    }

The method run into the catch block and the context.lookup method find a dynamic queue destination. But this is the wrong destination for this case.

 

 

help please

Hi asankha,

when you change the synapse (v1.2) example 251 from queue to topic you will see the same classcast exception.

We are evaluating the wso2 ESB for our project and this is an problem for us. Can you help us ?

Thanks
UweTe

Hi,I have attached the

Hi,
I have attached the working configuration files for the modified sample 251 to work with topics instead of queues. You need a JMS Cosumer that listen to a topic (SimpleStockQuoteService) to capture the messages because the existing SimpleStockQuoteService listens to a JMS queue.
Asanka A.

AttachmentSize
synapse_sample_251.xml1.65 KB
axis2.xml25.88 KB

Hi Asanka, thanks for your

Hi Asanka,
thanks for your support.

Your synapse_sample_251.xml looks exactly like my one.

But your axis2.xml have a lot of differences to the “out of the box” v1.2 synapse.xml . There is no JMS Transport Receiver configured and the class org.apache.synapse.core.axis2.CustomURIBasedDispatcher is not part of synapse v1.2 (Class not found Exception). Is this the configuration for the synapse server or the sample axis server?

I have attached my configuration files.

Thanks for your help.
UweTe

AttachmentSize
synapse_axis2.xml22.63 KB
sample_251.xml1.65 KB
example_server_axis2.xml18.52 KB

Hi, Please use the attached

Hi,

Please use the attached axis2.xml file this is from the synapse-1.2 distribution, what I have sent before is from a synapse-SNAPSHOT from the svn trunk.

Thx

Asanka

AttachmentSize
axis2.xml22.33 KB

/* Style Definitions

Hi Asanka,

I tried you configuration and the Axis Sample Server is getting no Request.  If the Server gets a request he is writing the following text to the console. Please check.

Mon Sep 08 10:40:38 CEST 2008 samples.services.SimpleStockQuoteService  :: Accepted order for : 8168 stocks of MSFT at $ 75.84473334961882

 In your configuration is no JMS configuration enabled. The doc says:

To enable the JMS transport, you need to uncomment the JMS transport listener configuration. 

This could not work. Please try my configuration and you will see the class cast exception.

Hi, Please refer the

Hi,

Please refer the response that I posted on Auguest 07, current Axis2 service is listening to a 'Queue' so the message you seng to the SimpleStockQuoteService 'Topic' will not reach there, so you will not receive a response. Yes to receive responses you have to uncomment the JMS Reciver block in the axis2 configuration.

But with the configuration that I have posted if you examine the JMS topics using JMX you can see the topic Simple...Service Topic and the message(s) you have sent to that.

As I explained in the Aug-7 response, you have to have a JMS consumer that listen to the relevant topic and response for the relevant reply queue to see a response, or configure the axis2 service to listen to topics, I will talk to the axis2 devs and send you the instructions about this, mean time you can examine the topics and use a simple topic consumer ship with ActiveMQ samples.

Asanka A.

Hi Uwe Since Asanka A is

Hi Uwe

Since Asanka A is travelling this week, let me answer this question..

First of all, to make your sample service listen on a topic, you need to add the following parameters to your services.xml

myTopicConnectionFactory
something.TestTopic
topic

What this basically means is that this service should use the JMS connection factory definitions logically named as "myTopicConnectionFactory" on the sample Axis2 servers' JMS listner config should be used, and the service should listen on a 'topic' with the name 'something.TestTopic'. When your sample service starts up.. look for log messages like the following, which will confirm this:

2008-09-08 16:11:01,364 [-] [main] INFO JMSListener Starting to listen on destination : something.TestTopic of type topic for service SimpleStockQuoteService
2008-09-08 16:11:01,366 [-] [main] INFO JMSConnectionFactory Mapped JNDI name : something.TestTopic and JMS Destination name : something.TestTopic against service : SimpleStockQuoteService

Now there is a problem with ActiveMQ (at least with 4.1.x) where a JNDI lookup for a Destination could give confusing results.. this happens especially with the "dynamic" destinations (topics and queues) supported by AMQ. Usually JMS destinations are managed objects, and an administrator will create these, and the developers simply use them.. however, AMQ creates any destination on-demand with these dynamic destinations. The bug really is when we look you look for an existing destination - which is not created as a managed object, we try to detect these dynamic destinations as well, and AMQ creates an unwanted Queue destination, when we just check if there is a dynamic Queue or Topic with our given name..

So, I have workaround for you - Just comment your synapse instances' axis2.xml to read as follows. However, this will create a new JMS connection to send each message.

If you want pre-create your destinations (i.e. as managed objects), then I can suggest a better workaround, but you need to tell me more about the overall problem you are solving - you can email me privately if you do not want to share this information publicly.

Please report this issue on a JIRA and we will fix it for the next release. If you need a binary patch for an already released versions of Synapse or the WSO2 ESB, WSO2 could provide you with commercial support too.

I have attached the full config required against Synapse 1.2, to try this out now..

asankha

AttachmentSize
services.xml1.6 KB
sample-axis2-server-axis2.xml18.55 KB
synapse_sample_251.xml1.64 KB
axis2.xml22.44 KB

Thanks Asankha und Asanka A

Thanks Asankha und Asanka A for your help.

UweTe

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.