Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9020999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:09:12+00:00 2026-06-16T05:09:12+00:00

I am trying to intercept a message to skip the Http request and proceed

  • 0

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

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.test.junit4.CamelTestSupport;
import org.junit.Test;

/**
 * Created with IntelliJ IDEA.
 * User: lleclerc
 * Date: 12-11-28
 * Time: 16:34
 * To change this template use File | Settings | File Templates.
 */
public class IsUseAdviceWithJUnit4Test extends CamelTestSupport {

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

    @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 + "?throwExceptionOnFailure=false")
                        .to(mockEndPointURI);
            }
        };
    }

    @Test
    public void testIsUseAdviceWith() throws Exception {

        messageIntercepted = false;

        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 {
                                messageIntercepted = true;
                                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();

        assertEquals(true, messageIntercepted);

        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;
    }
}

Thank you for your help !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:09:14+00:00Added an answer on June 16, 2026 at 5:09 am

    There was bugs inside camel-http4.

    http://camel.465427.n5.nabble.com/Found-a-bug-with-camel-http4-td5723733.html

    http://camel.465427.n5.nabble.com/Test-Intercept-with-adviceWith-and-http-td5723473.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to intercept a http request to a website. I used the
i'm trying to intercept ajax requests with jquery, to display a waiting message like
I'm trying to intercept a method call (afterInsert() of a domain class) in a
I'm trying to programmatically intercept and cancel a user's attempt to check out a
I'm trying to intercept/hook the WM_PAINT message of the desktop in C++. I'm currently
I am trying to intercept the WM_NCPAINT message by first calling ::DefWindowProc, then paint
I am trying to intercept event_object_create and event_object_destroy events through following code: class NameChangeTracker
I'm trying to understand the meaning of the following message: irq N:nobody cared (try
I'm trying to compute the intercept of a slope but I can't all of
I am trying to figure out a clean way to intercept uncaught exceptions that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.