3 Replies Latest reply on Feb 10, 2009 7:01 AM by Gert Vanthienen

    Problem implementing MessageExchangeListener

    Paul DiSabito Newbie

      I'm trying to implement a MessageExchangeListener, and I keep running into the same EIPComponent ERROR:

       

      ERROR - EIPComponent                   - Error processing exchange InOnly[

      id: ID:172.16.115.229-11f14e871fc-10:0

      status: Active

      role: provider

      service: ceService

      endpoint: endpoint

      in: Unable to display: java.io.IOException: Stream closed

       

      ]

       

       

      My code (MessageDoublerBean.java) is based on the sample code from the apache site (the Message processing example):

       

      http://servicemix.apache.org/servicemix-bean.html

       

      My service assembly consists of a file service (a poller and a sender), a content-enricher service, and servicemix-bean (MessageDoublerBean.java).

       

      The basic sequence is:

       

      1)       I drop a file into the poller's directory

      2)       The file service passes it to the content-enricher service

      3)       The content-enricher service passes it to the MessageDoublerBean

      4)       The bean successfully reads the XML, doubles its content, and then tries to send the message containing the modified content to the file service (the sender)

       

      All of the code seems to successfully execute -- that is, I see all of the print statements in the console -- but then I get the EIPComponent error. Curiously, the original XML file never gets consumed, even though its content made it all the way to the bean.

       

      By the way, I'm running fuse-esb-3.3.1.11.

       

      Hopefully, I'm overlooking something small and easy to fix.

       

      I'm attaching the project for anyone willing to help.

       

      Thank you,

       

      --Paul DiSabito

       

      Edited by: pdisabit on Jan 28, 2009 6:53 PM

        • 1. Re: Problem implementing MessageExchangeListener
          Surajit Choudhury Newbie

          This is not a solution, but ..

          I had the same problem with this example where it complains of the stream being closed. The way I got around is not to use the toString() on the SourceTransformer, but parse the result, and create a new Source. All this taken from the deprecated JdbcComponent.java in the ServiceMix source tree. Please see below for code snippet:

          -


                            NormalizedMessage message = exchange.getMessage("in");

                            

                            SourceTransformer domTransform = new SourceTransformer();

                            Node domNode = domTransform.toDOMNode(message);

           

                           String query = getQuery(domNode);

           

                              // Execute query

                           Statement stmt = con.createStatement();

           

                              ResultSet result = stmt.executeQuery(query);

           

                              // Convert result to an XML doc and send it off

                              Source outMsg = toXmlSource(result);

                            

                           message.setContent(outMsg);

                            

                             exchange.setMessage(message, "out");

                           channel.send(exchange);

          -


           

          • 2. Re: Problem implementing MessageExchangeListener
            Gert Vanthienen Novice

            L.S.,

             

            When I run the example on my machine with DEBUG logging enabled, I get this in the ouput:

             

            exchange: InOut[

            id: ID:127.0.0.1-11f4afca333-21:505

            status: Active

            role: consumer

            service: beanService

            endpoint: beanEndpoint

            in: Unable to display: org.xml.sax.SAXParseException: Element type "eipEnvelope" must be followed by either attribute specifications, ">" or "/>".

            out: Unable to display: java.io.IOException: Stream closed

            ]

             

            This shows the two problems: a StreamSource not being handled properly and invalid XML content being generated.   In order to fix those issues:

            • add a call to MessageUtil.enableContentRereadability at the beginning of the bean method to ensure caching the content's stream

            • correct the opening tag (should be <eipEnvelope> instead of <eipEnvelope/>

            • make a new NormalizedMessage for the out instead of copying the old one to avoid reusing the old stream

             

            Attaching the java source file with all the fixes in it.

             

            Regards,

             

            Gert

             

            Edited by: gertv on Feb 6, 2009 1:15 PM

            • 3. Re: Problem implementing MessageExchangeListener
              Gert Vanthienen Novice

              Paul,

               

              There still was a problem when running this with DEBUG logging disabled.  It appears the content enricher wasn't handling StreamSources correctly.  I raised and fixed https://issues.apache.org/activemq/browse/SM-1796 for this, so a new local build of the component will make this work. 

               

              Regards,

               

              Gert