You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by pratibhaG <pr...@in2m.com> on 2008/05/27 07:31:03 UTC

Retrieve inMessage from MessageExchange

Hi,
How can I retrieve the in message from message exchange?

I have following code
public class ExceptionListenerService implements ExchangeListener {

    public void exchangeAccepted(ExchangeEvent event) {
        // TODO Auto-generated method stub
    }
    public void exchangeSent(ExchangeEvent event) {
    	MessageExchange me = event.getExchange();
    	 System.out.println("in listener: message is=  " + me);  
    }  
}

The output is as follows:
in listener: message is=  InOnly[
  id: ID:192.168.2.64-11a28d65e8f-4:0
  status: Error
  role: provider
  endpoint: providerEndpoint
  in: <?xml version="1.0" encoding="UTF-8"?><Request>
        <service name="updatepassword">
                <parameter name="username">sandeep37</parameter>
                <parameter name="password">password</parameter>
        </service>
</Request>
  error: java.net.ConnectException: Connection refused
]


I want to retrieve the message in message '<?xml version="1.0"
encoding="UTF-8"?><Request>
        <service name="updatepassword">
                <parameter name="username">sandeep37</parameter>
                <parameter name="password">password</parameter>
        </service>
</Request>'

How can I retrieve it?
I tried me.getMessage("in") and me.getMessage("in").getContent(), but it
does not serve the purpose.

Please help!

-Pratibha
-- 
View this message in context: http://www.nabble.com/Retrieve-inMessage-from-MessageExchange-tp17483341p17483341.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Retrieve inMessage from MessageExchange

Posted by Guillaume Nodet <gn...@gmail.com>.
The in normalized message can be retrieved using the following code:
   NormalizedMessage in = exchange.getMessage("in");
   Source source = in.getContent();
You can then access the content (as a Source), the properties and
other informations of the in message.
But if you want to retrieve the string representation of the
underlying xml, what you do is the way to go.

On Tue, May 27, 2008 at 8:31 AM, pratibhaG <pr...@in2m.com> wrote:
>
> Currently I am doing it like this is there a better approach?
> private String getMyMessage(NormalizedMessage normalizedMessage) throws
> MessagingException {
>           SourceTransformer sourceTransformer = new SourceTransformer();
>           String inMessage = "";
>
>           try {
>               inMessage =
> sourceTransformer.contentToString(normalizedMessage);
>           } catch (Exception e) {
>               throw new MessagingException(e);
>           }
>           return inMessage
> }
>
> -Pratibha
> --
> View this message in context: http://www.nabble.com/Retrieve-inMessage-from-MessageExchange-tp17483341p17483965.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Retrieve inMessage from MessageExchange

Posted by pratibhaG <pr...@in2m.com>.
Currently I am doing it like this is there a better approach?
private String getMyMessage(NormalizedMessage normalizedMessage) throws
MessagingException {
    	   SourceTransformer sourceTransformer = new SourceTransformer();
    	   String inMessage = "";

    	   try {
    	       inMessage =
sourceTransformer.contentToString(normalizedMessage);
    	   } catch (Exception e) {
    	       throw new MessagingException(e);
    	   }
           return inMessage
}

-Pratibha
-- 
View this message in context: http://www.nabble.com/Retrieve-inMessage-from-MessageExchange-tp17483341p17483965.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.