Prashant
Prashant

Reputation: 152

Apache Camel REST DSL sending some data along with each response

I am new to Camel and want to implement the following scenario:

I am developing REST services using camel REST-DSL and with each response, I have to send some data(an integer count representing the number of new notifications).

Following is the code how I am using REST DSL:

        rest("/rest1").description("Rest1 service")                           
        .consumes("application/json").produces("application/json")

        .post("/addMultiple").typeList(Map.class).to("bean:somebean1?method=someMethod1(${body})")
        .post("/add").to("bean:somebean1?method=someMethod2(${body})")

        .get("/status").description("Find all request by status").outTypeList(Request.class)
        .to("bean:somebean1?method=someMethod3(${header.status})") ; 

         rest("/rest2").description("Rest2 service")
            .consumes("application/json").produces("application/json")

            .post("/add").type(FileBean.class).to("bean:someBean2?method=someMethod1(${body})")

            .get("/categories")
            .description("get all categories")
            .to("bean:someBean2?method=someMethod2()");

Here with each JSON response I am sending, I have to send some integer count for continuous update at client side.

What if I can have header and with each response I update it by setting new value.

Please advise on how to achieve this.

Upvotes: 0

Views: 1182

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55540

You can add the header in your bean, and use bean parameter binding to bind the Map headers so you can add the counter.

public String doSomething(String data, @Headers Map headers) {
   ...
}

See more details at

Another approach could be to use an on completion to add the header at the end of the routing (requires Camel 2.15 and use the before consumer mode)

Upvotes: 1

Related Questions