Hi,

I am trying to intercept a message to skip the Http request and proceed with
my route.
Here is the class you can copy/paste to try it out.

Return false in isUseAdviceWith() : The test is success but the message is
never intercepted.

Return true in isUseAdviceWith() : I get this exception :
org.apache.camel.FailedToCreateRouteException: Failed to create route route1
at: >>> To[http4://stackoverflow.com] <<< in route:
Route[[From[direct:myDirect]] -> [To[http4://stackoverflow.c... because of
Failed to resolve endpoint: http4://stackoverflow.com due to: null

Using camel-test, camel-core, camel-http4 2.10.2 and httpclient-osgi,
httpcore-osgi 4.2.2

Here is the code :

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.http4.HttpComponent;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class IsUseAdviceWithJUnit4Test extends CamelTestSupport {

    private String providerEndPointURI = "http4://stackoverflow.com";
    private String timerEndPointURI = "timer://myTimer";
    private String mockEndPointURI = "mock:myMock";
    private String directEndPointURI = "direct:myDirect";


    @Test
    public void testIsUseAdviceWith() throws Exception {

        context.getRouteDefinitions().get(0).adviceWith(context, new
AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {

                replaceFromWith(directEndPointURI);

                mockEndpoints();

                interceptSendToEndpoint(providerEndPointURI)
                        .skipSendToOriginalEndpoint()
                        .process(new Processor() {
                            @Override
                            public void process(Exchange exchange) throws
Exception {
                                System.out.println("INTERCEPTED");
                            }
                        });
            }
        });

        // we must manually start when we are done with all the advice with
        context.start();

        getMockEndpoint(mockEndPointURI).expectedMessageCount(1);

        template.sendBody(directEndPointURI, "a trigger");

        assertMockEndpointsSatisfied();

        assertNotNull(context.hasEndpoint(directEndPointURI));
        assertNotNull(context.hasEndpoint("mock:" + directEndPointURI));

        assertNotNull(context.hasEndpoint(mockEndPointURI));
    }

    @Override
    public boolean isUseAdviceWith() {
        return true;
    }

    @Override
    public boolean isUseRouteBuilder() {
        return true;
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {

        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {

                from(timerEndPointURI +
"?fixedRate=true&delay=1000&period=1000")
                    .to(providerEndPointURI)
                    .to(mockEndPointURI);
            }
        };
    }
}

Thanks !




--
View this message in context: 
http://camel.465427.n5.nabble.com/Problem-with-isUseAdviceWith-and-Intercept-tp5723410.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to