I think the problem is the leading slash / so your root element has to be
<authorizationCheck>.

Because I think this is not the case (but you havent shown that xml) other
xpaths will work


Jan



import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class XPathHeaderTest extends CamelTestSupport {
    
    @Test
    public void authEnabled() throws InterruptedException {
 
getMockEndpoint("mock:end").expectedHeaderReceived("WITH_AUTHENTIFICATION",
true);
        String xml =
"<order><authorizationCheck>enabled</authorizationCheck><id>123</id></order>
";
        template.sendBody("direct:in", xml);
        assertMockEndpointsSatisfied();
    }
    
    @Test
    public void authDisabled() throws InterruptedException {
 
getMockEndpoint("mock:end").expectedHeaderReceived("NO_AUTHENTIFICATION",
true);
        String xml =
"<order><authorizationCheck>disabled</authorizationCheck><id>123</id></order
>";
        template.sendBody("direct:in", xml);
        assertMockEndpointsSatisfied();
    }
    
    @Test
    public void authUnknown1() throws InterruptedException {
 
getMockEndpoint("mock:end").expectedHeaderReceived("NO_AUTHENTIFICATION",
true);
        String xml =
"<order><authorizationCheck>unknown</authorizationCheck><id>123</id></order>
";
        template.sendBody("direct:in", xml);
        assertMockEndpointsSatisfied();
    }
    
    @Test
    public void authUnknown2() throws InterruptedException {
 
getMockEndpoint("mock:end").expectedHeaderReceived("NO_AUTHENTIFICATION",
true);
        String xml = "<order><id>123</id></order>";
        template.sendBody("direct:in", xml);
        assertMockEndpointsSatisfied();
    }
    
    
    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:in")
                    .choice()
                        .when().xpath("/order/authorizationCheck='enabled'")
                            .setHeader("WITH_AUTHENTIFICATION",
constant(true))
                        .otherwise()
                            .setHeader("NO_AUTHENTIFICATION",
constant(true))
                    .end()
                    .to("mock:end");
            }
        };
    }
}


> -----Ursprüngliche Nachricht-----
> Von: Lydie [mailto:lprev...@completegenomics.com]
> Gesendet: Donnerstag, 10. April 2014 06:29
> An: users@camel.apache.org
> Betreff: Re: camel xpath
> 
> So I still have an error:
> 
> I never go to my first choice: 'enabled':
> 
> 
> <choice>
>       <when>
>        <xpath
> headerName="ROUTE_CONFIGURATION_HEADER">/authorizationCheck='enabled'</
> xpath>
>               <log message="**** Authorization enabled" />
>               <process ref="authorizationProcessor" />
>       </when>
>       <otherwise>
>               <log message="**** Authorization disabled" />
>       </otherwise>
> </choice>
> 
> 
> 
> This what I get when I print my ROUTE_CONFIGURATION_HEADER:
> 
> 
> 21:17:30,030 INFO  [proxy] (qtp1338864318-153)
> +++++{RouteConfiguration=<authorizationCheck>enabled</authorizationChec
> k
> +++++>Accept-Encoding=gzip,deflate,sdch,
> Host=localhost:8888, breadcrumbId=ID-dt-lprevost-61655-1397103421574-0-
> 2,
> CamelHttpServletResponse=HTTP/1.1 200
> 
> ****
> 21:17:30,103 INFO  [proxy] (qtp1338864318-153) **** Authorization
> disabled
> 
> 
> Message History
> -----------------------------------------------------------------------
> ----------------------------------------------------------------
> RouteId              ProcessorId          Processor
> Elapsed (ms)
> [proxy             ] [proxy             ] [http://0.0.0.0:8888
> ] [     23187]
> [proxy             ] [convertBodyTo1    ]
> [convertBodyTo[java.lang.String]
> ] [         2]
> [proxy             ] [log1              ] [log
> ] [         1]
> [proxy             ] [process1          ]
> [ref:routeConfiguratorProcessor
> ] [     22078]
> [proxy             ] [log2              ] [log
> ] [         4]
> [proxy             ] [log3              ] [log
> ] [         1]
> [proxy             ] [doTry1            ] [doTry
> ] [        70]
> [proxy             ] [choice1           ] [when[xpath{XPath:
> /authorizationCheck="enabled"}]choice[]                     ] [
> 69]
> [proxy             ] [log5              ] [log
> ] [         1]
> [proxy             ] [log6              ] [log
> ] [         0]
> [proxy             ] [process4          ] [ref:inputProcessor
> ] [      1028]
> 
> 
> 
> why do I have :
> [when[xpath{XPath: /authorizationCheck="enabled"}]choice[] not
> validated as true??????
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-
> xpath-tp5749754p5750025.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to