12 Replies Latest reply on Jan 31, 2012 10:48 AM by dward

    Access JMS Headers

    cvasilak

      Hi there,

       

      I am trying to access the JMS headers on a TextMessage send by a client but I am unable to do so. My route is

       

           from("switchyard://RegistrationRoute").routeId("RegistrationRoute")

          .process(new Processor() {

                  public void process(Exchange exchange) throws Exception {

       

                            Map<String, Object> headers = exchange.getIn().getHeaders();

       

                            for (Map.Entry<String, Object> e : headers.entrySet())

                                System.out.println(e.getKey() + ": " + e.getValue());

       

                            } })

            .choice()

            .when(header("type").isEqualTo("register"))

               .unmarshal().json(JsonLibrary.Jackson, RegistrationCommandMessage.class)

               .to("bean:Routing?method=addRouteFromRegistrationCommandMsg")

               .log("registration completed")

            .otherwise()

              .to("can't process it");

       

       

      I use the Processor just to dump the message headers. On the console I am getting only one header

       

      breadcrumbId: ID-casper-rd-forthnet-gr-54172-1326374328862-15-6

       

      On the client side I set the property with

      msg.setStringProperty("type", "register");

       

      Also I can't access the standard JMS properties e.g. JMSDestination, JMSMessageID, etc.

       

      Any help?

       

      Regards


       



        • 1. Re: Access JMS Headers
          kcbabo

          This is a bug for sure.  The headers which come in on the Camel gateway (JMS component in this case) are not being mapped back into the Camel exchange that's used in the route.  It's likely that you can define a message composer to make this happen.  Can you create a JIRA and attach a stripped down sample application which is just the JMS gateway binding and the Camel route which attempts to access a header?

           

          ~ keith

          • 2. Re: Access JMS Headers
            cvasilak

            Hi Keith,

             

            I have opened a JIRA for this together with steps to reproduce it

             

            https://issues.jboss.org/browse/SWITCHYARD-614

             

            Let me know if you need more information

             

            Regards,

            Christos

            • 3. Re: Access JMS Headers
              dward

              Hi Christos,

               

              I will be looking at this soon for you. I assigned the jira to me and will make sure things are working as expected for the 0.4 release. I do appreciate that you have provided a test case and steps to reproduce. That helps a lot, so thank you.

               

              David

              • 4. Re: Access JMS Headers
                dward

                Christos,

                 

                Your test doesn't build because of a missing parent that can't be found.  Please see: http://goo.gl/YKRpj

                 

                Thanks,

                David

                • 5. Re: Access JMS Headers
                  cvasilak

                  Oops I missed that, I have already replied on JIRA

                   

                  Regards

                  • 6. Re: Access JMS Headers
                    dward

                    Christos,

                     

                    Finally getting back to this...

                     

                    One thing I noticed right away is that you haven't specified a context mapper in your binding model.  If you don't do that, no headers or properties will get propagated.  You need to add the <contextMapper/> element, like so:

                     

                    <switchyard ...>

                        <composite ...>

                            <service ...>

                                <binding.camel ...>

                                    <contextMapper xmlns="urn:switchyard-config:switchyard:1.0" includes=".*" />

                    ...

                     

                    Can you try this while I get my environment set up?

                     

                    You can read more about it message composers and context mappers here:

                    https://docs.jboss.org/author/display/SWITCHYARD/Message+Composition

                     

                    Thanks,

                    David

                    • 7. Re: Access JMS Headers
                      dward

                      David Ward wrote:

                       

                      Can you try this while I get my environment set up?

                       

                      Hmmm... Having issues getting your test case to run properly. I'm pretty sure what I suggested above should fix your issue, so if you could just validate that before I spend unecessary time on getting the test environment correct, I'd appreciate it.

                       

                      Thanks,

                      David

                      • 8. Re: Access JMS Headers
                        cvasilak

                        Hi David,

                         

                        I am currently looking at your suggestion, will reply back soon

                         

                        Regards

                        • 9. Re: Access JMS Headers
                          cvasilak

                          Hi David,

                           

                          unfortunately it didn't work .

                           

                          My switchyard.xml:

                          <?xml version="1.0" encoding="UTF-8"?>

                          <switchyard xmlns="urn:switchyard-config:switchyard:1.0"

                                      xmlns:trfm="urn:switchyard-config:transform:1.0"

                                      xmlns:soap="urn:switchyard-component-soap:config:1.0"

                                      xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"

                                      name="svcrrd">

                           

                           

                              <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"

                                         name="svcrrd" targetNamespace="urn:svcrrd:transform-json:0.1.0">

                                  <service name="RegistrationRouteBuilder" promote="RegistrationRouteBuilder">

                                      <binding.camel xmlns="urn:switchyard-component-camel:config:1.0"

                                                     configURI="jms:topic:svc_rrd_ctrl_bus?connectionFactory=#ConnectionFactory">

                                          <contextMapper xmlns="urn:switchyard-config:switchyard:1.0" includes=".*" />

                                      </binding.camel>

                                  </service>

                              </composite>

                           

                           

                          </switchyard>

                           

                          In the console only one property is printed

                          23:28:07,041 INFO  [stdout] (Camel (camel-10) thread #4 - JmsConsumer[svc_rrd_ctrl_bus) breadcrumbId: ID-casper-49846-1327353880613-7-4
                          

                           

                           

                          What problem are you facing with my test-case?

                           

                           

                          Regards

                          • 10. Re: Access JMS Headers
                            dward

                            Christos,

                             

                            A fix is queued up for https://issues.jboss.org/browse/SWITCHYARD-614.

                             

                            You will still need to add the <contextMapper/>, but I've run your tests with the fix and they now work as expected (the json one as well as the pure jms one).

                             

                            Note: You were using SwitchYard 0.3.0.Final.  I did the above fix with 0.4.0-SNAPSHOT.  It was localized to one class (as you can see in the associated pull request), but I did not try to back-port it to 0.3.0 and test there.

                             

                            David

                            • 11. Re: Access JMS Headers
                              cvasilak

                              That's fantastic! Thanks a lot David!

                               

                              Regards

                              • 12. Re: Access JMS Headers
                                dward

                                NP. Thanks for bringing it to our attention.