Some updates from more investigation:

1. If I do not set the body in the output message, I get my input message
back (regardless of the header properties that were set).
2. My header assertions are not tested.  I tried to assert it purposely to
the wrong value and it does not check.

Is this right?  Seems kind of odd--if I want an empty message I have to set
the empty string for it to work (null yields the input message).
On Thu, Apr 17, 2008 at 12:12 PM, David Siefert <
[EMAIL PROTECTED]> wrote:

> Hello,
>
> I could use some explanation of how MEPs are used within Camel.  I
> understand the various Message Exchange Patterns (in, out, inout), but I am
> having some trouble with how I design my processor.  I need to take an XML
> document and move some of the information from the body to header
> properties.  To do this I took the input message, parsed the body to get the
> information I needed.  Then I set that data on the output message, and set a
> body for the output message.  I created a test to verify the work was done,
> but it fails.  I end up getting what looks like the input message.
>
> Here is the test code snippet:
>   MockEndpoint result = // get mock...
>   result.expectedMessageCount(1);
>   result.expectedBodiesReceived("");
>   result.message(0).header("sample.name").equals("sample.value");
>   template.sendBody("direct:start",
> "<sample><name>value</name></sample>");
>   result.assertIsSatisfied();
> My route is configured as follows:
>   from("direct:start").process(new MyProcessor()).to("mock:result");
>
> MyProcessor works like so:
>   public void process(Exchange exchange) throws Exception {
>    Document document = // read exchange.getIn().getBody(String.class)
>
>    String value = // parse for the text of <name> element.
>
>    Message output = exchange.getOut();
>    output.setHeader("sample.name", value);
>    output.setBody(/* XML of new body */);
>  }
> When I run the test, it will say:
>   INFO: Asserting: Endpoint[mock:result] is satisfied
>
> But the test fails:
>   java.lang.AssertionError: mock:result Body of message: 0. Expected: <>
> but was: <...(body of input message here)...>
>
> It doesn't really appear that it is even making assertions about the
> header properties either.  What I am trying to understand is why the input
> message gets sent to mock:result and not the output message.  Should I
> modify the input message only and forget about the output message?  Please
> help.
>
> I looked at some of the test code for various processors, and it looks
> like you have to specify a Processor parameter that will receive an endpoint
> specification from to().  Then it calls that processor's process() method
> with the output message.  I don't really understand the point of this if you
> have an output message in the Exchange.  Wouldn't Camel automagically take
> the output of the exchange and send it to its next destination?
>
> Thanks,
>
> David
>

Reply via email to