Well, it's up to you as there not many differences between using a client facade and the delivery channel directly. When developping JBI components or endpoints, we tend to stick with the JBI API though... because the client api is only be available on ServiceMix 3 and is not part of the JBI spec.

Sent from my iPhone

On 2 nov. 08, at 19:43, "Ryan Moquin" <[EMAIL PROTECTED]> wrote:

Ok, that's interesting that it's different than the rest of the ways. So is it better to use the client created off the ComponentContext or just using
the deliverychannel directly?

On Sun, Nov 2, 2008 at 8:17 PM, Guillaume Nodet <[EMAIL PROTECTED]> wrote:

This is an expected behavior specified by the JBI specification when
using the DeliveryChannel directly.
The servicemix client has a slightly different behavior and pre- create
the in message for you.
So when using the delivery channel, you need to do the following:

        InOnly outExchange = client.createInOnlyExchange();
        NormalizedMessage inMessage = outExchange.createMessage();
        outExchange.setInMessage(inMessage);
        ...


On Sun, Nov 2, 2008 at 7:28 PM, Ryan Moquin <[EMAIL PROTECTED]>
wrote:
I decided to go back to trying the DeliveryChannel in my bean component rather than looking a servicemix client up directly from JNDI. When I do this, it appears getInMessage() from the newly created exchange, returns null. All the examples I see, call getInMessage() so I'm not sure what
I'm
doing wrong.  If I swap the 2 lines back so that they are using the
ServicemixClient, I don't have a problem with the NormalizedMessage being
null.  Here are the 2 relevant code snippets and their output:

Using ServicemixClient from JNDI lookup:

Code -------------------

        if (client == null) {
          ClientFactory factory = (ClientFactory) new
InitialContext().lookup(ClientFactory.DEFAULT_JNDI_NAME);
          client = factory.createClient();
        }
        InOnly outExchange = client.createInOnlyExchange();
        NormalizedMessage inMessage = outExchange.getInMessage();
        System.out.println("In message is: " + inMessage);
        System.out.println("In xml is: " + xml);
        inMessage.setContent(new StringSource(xml));
        outExchange.setService(destinationQname);
        client.send(outExchange);
System.out.println("Message sent to jms provider using client
");


Output ------------------
Received a message, sending to jms provider: <?xml version="1.0"
encoding="UTF-8"?><testMessage>0</testMessage>
INFO  - ComponentMBeanImpl             - Initializing component:
ID:192.168.1.4-11d5e52a421-0:0
INFO  - ComponentMBeanImpl             - Starting component:
ID:192.168.1.4-11d5e52a421-0:0
In message is:
[EMAIL PROTECTED]
{properties:
{}}
In xml is: <?xml version="1.0"
encoding="UTF-8"?><testMessage>0</testMessage>
Message sent to jms provider using client:
Received a message, sending to jms provider: <?xml version="1.0"
encoding="UTF-8"?><testMessage>1</testMessage>
In message is:
[EMAIL PROTECTED]
{properties:
{}}
In xml is: <?xml version="1.0"
encoding="UTF-8"?><testMessage>1</testMessage>
Message sent to jms provider using client


Using injected delivery channel:

Code -------------------

        MessageExchangeFactory exchangeFactory =
deliveryChannel.createExchangeFactory();
        InOnly outExchange = exchangeFactory.createInOnlyExchange();
        NormalizedMessage inMessage = outExchange.getInMessage();
        System.out.println("In message is: " + inMessage);
        System.out.println("In xml is: " + xml);
        inMessage.setContent(new StringSource(xml));
        outExchange.setService(destinationQname);
        deliveryChannel.send(outExchange);
System.out.println("Message sent to jms provider using delivery
channel: ");

Output ------------------

Received a message, sending to jms provider: <?xml version="1.0"
encoding="UTF-8"?><testMessage>0</testMessage>
In message is: null
In xml is: <?xml version="1.0"
encoding="UTF-8"?><testMessage>0</testMessage>
[Fatal Error] :-1:-1: Premature end of file.
ERROR - BeanComponent - Error processing exchange InOut[
id: ID:192.168.1.4-11d5e52a421-5:212
status: Active
role: provider
service: {http://servicemix.apache.org/samples/bridge}testbean<http://servicemix.apache.org/samples/bridge%7Dtestbean >
endpoint: test/bean
in: Unable to display: org.xml.sax.SAXParseException: Premature end of
file.
]
javax.jbi.messaging.MessagingException: Error sending message to jms
provider
      at test.BeanImpl.onMessageExchange(BeanImpl.java:106)
      at

org. apache. servicemix.bean.BeanEndpoint.onProviderExchange(BeanEndpoint.java: 226)
      at
org.apache.servicemix.bean.BeanEndpoint.process(BeanEndpoint.java: 212)
      at

org. apache. servicemix. common.AsyncBaseLifeCycle.doProcess(AsyncBaseLifeCycle.java:600)
      at

org. apache. servicemix. common.AsyncBaseLifeCycle.processExchange(AsyncBaseLifeCycle.java: 554)
      at

org. apache. servicemix. common.AsyncBaseLifeCycle.onMessageExchange(AsyncBaseLifeCycle.java: 510)
      at

org. apache. servicemix. common. SyncLifeCycleWrapper.onMessageExchange(SyncLifeCycleWrapper.java:60)
      at

org. apache. servicemix. jbi. messaging. DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:620)
      at

org. apache. servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:172)
      at

org. apache. servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:168)
      at

org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue $1.run(SedaQueue.java:134)
      at

java.util.concurrent.ThreadPoolExecutor $Worker.runTask(ThreadPoolExecutor.java:885)
      at

java.util.concurrent.ThreadPoolExecutor $Worker.run(ThreadPoolExecutor.java:907)
      at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
      at test.BeanImpl.onMessageExchange(BeanImpl.java:100)
      ... 13 more
[Fatal Error] :-1:-1: Premature end of file.
ERROR - JmsComponent - Error processing exchange InOut[
id: ID:192.168.1.4-11d5e52a421-5:212
status: Error
role: consumer
service: {http://servicemix.apache.org/samples/bridge}testbean<http://servicemix.apache.org/samples/bridge%7Dtestbean >
endpoint: test/bean
in: Unable to display: org.xml.sax.SAXParseException: Premature end of
file.
error: javax.jbi.messaging.MessagingException: Error sending message to
jms provider
]
java.lang.UnsupportedOperationException: A destination must be specified.
      at

org. apache. activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java: 195)
      at

org. apache. activemq. ActiveMQMessageProducerSupport. send(ActiveMQMessageProducerSupport.java:241)
      at

org. apache. servicemix. jms. multiplexing. MultiplexingConsumerProcessor. process(MultiplexingConsumerProcessor.ja
a:126)
      at
org.apache.servicemix.soap.SoapEndpoint.process(SoapEndpoint.java: 367)
      at

org. apache. servicemix. common.AsyncBaseLifeCycle.doProcess(AsyncBaseLifeCycle.java:600)
      at

org. apache. servicemix. common.AsyncBaseLifeCycle.processExchange(AsyncBaseLifeCycle.java: 571)
      at

org. apache. servicemix. common.AsyncBaseLifeCycle.onMessageExchange(AsyncBaseLifeCycle.java: 510)
      at

org. apache. servicemix. common. SyncLifeCycleWrapper.onMessageExchange(SyncLifeCycleWrapper.java:60)
      at

org. apache. servicemix. jbi. messaging. DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:620)
      at

org. apache. servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:172)
      at

org. apache. servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:168)
      at

org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue $1.run(SedaQueue.java:134)
      at

java.util.concurrent.ThreadPoolExecutor $Worker.runTask(ThreadPoolExecutor.java:885)
      at

java.util.concurrent.ThreadPoolExecutor $Worker.run(ThreadPoolExecutor.java:907)
      at java.lang.Thread.run(Thread.java:619)
ERROR - JmsComponent - Error setting exchange status to
ERROR
javax.jbi.messaging.MessagingException: illegal call to send / sendSync
      at

org. apache. servicemix. jbi. messaging.MessageExchangeImpl.handleSend(MessageExchangeImpl.java: 614)
      at

org. apache. servicemix. jbi.messaging.DeliveryChannelImpl.doSend(DeliveryChannelImpl.java: 385)
      at

org. apache. servicemix. jbi.messaging.DeliveryChannelImpl.send(DeliveryChannelImpl.java:431)
      at

org. apache. servicemix. common.AsyncBaseLifeCycle.onMessageExchange(AsyncBaseLifeCycle.java: 525)
      at

org. apache. servicemix. common. SyncLifeCycleWrapper.onMessageExchange(SyncLifeCycleWrapper.java:60)
      at

org. apache. servicemix. jbi. messaging. DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:620)
      at

org. apache. servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:172)
      at

org. apache. servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:168)
      at

org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue $1.run(SedaQueue.java:134)
      at

java.util.concurrent.ThreadPoolExecutor $Worker.runTask(ThreadPoolExecutor.java:885)
      at

java.util.concurrent.ThreadPoolExecutor $Worker.run(ThreadPoolExecutor.java:907)
      at java.lang.Thread.run(Thread.java:619)
Received a message, sending to jms provider: <?xml version="1.0"
encoding="UTF-8"?><testMessage>1</testMessage>
In message is: null
In xml is: <?xml version="1.0"
encoding="UTF-8"?><testMessage>1</testMessage>
[Fatal Error] :-1:-1: Premature end of file.
ERROR - BeanComponent - Error processing exchange InOut[
id: ID:192.168.1.4-11d5e52a421-5:213
status: Active
role: provider
...

Using ComponentContext from ServiceMixClient

Code ------------

if (client == null) {
          client = new ServiceMixClientFacade(componentContext);
        }

        InOnly outExchange = client.createInOnlyExchange();
        NormalizedMessage inMessage = outExchange.getInMessage();
        System.out.println("In message is: " + inMessage);
        System.out.println("In xml is: " + xml);
        inMessage.setContent(new StringSource(xml));
        outExchange.setService(destinationQname);
        client.send(outExchange);
System.out.println("Message sent to jms provider using component
context: ");

Output --------------

Received a message, sending to jms provider: <?xml version="1.0"
encoding="UTF-8"?><testMessage>0</testMessage>
In message is:
[EMAIL PROTECTED]
{properties:
{}}
In xml is: <?xml version="1.0"
encoding="UTF-8"?><testMessage>0</testMessage>
Message sent to jms provider using delivery channel:
Exchange was marked done, not doing anything else.
Received a message, sending to jms provider: <?xml version="1.0"
encoding="UTF-8"?><testMessage>1</testMessage>
In message is:
[EMAIL PROTECTED]
{properties:
{}}
In xml is: <?xml version="1.0"
encoding="UTF-8"?><testMessage>1</testMessage>
Message sent to jms provider using delivery channel:
Exchange was marked done, not doing anything else.




Why doesn't the DeliveryChannel used by itself work? Should I always
just
do it the third way?

Thanks,
Ryan




--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com

Reply via email to