Apache Camel Karaf Mandatory header ignored

173 Views Asked by At

I have a route with a rest put call. And I need to declare a mandatory header in this call. But I'm not getting it from blueprint.xml. Even without the declared header, the answer is 200. Here's my route xml:

<restConfiguration bindingMode="json"
   clientRequestValidation="true" component="jetty"
   enableCORS="true" host="{{rest.endpoint.host}}" port="{{rest.endpoint.port}}">
   <dataFormatProperty key="prettyPrint" value="true"/>

enter code here

What am I forgetting or putting wrong? Thanks for listening.

1

There are 1 best solutions below

0
Pasi Österman On

You're missing your route from your question, what you have there is rest configuration.

You can use filter to check if header is missing then set proper response body and headers and use stop to early out when the header is missing from the request.

Heres how in Java-DSL

from("direct:needsHeader")
    .filter(header("requiredHeader").isNull())
        .setHeader("CamelHttpResponseCode", constant(400))
        .setHeader("Content-Type", constant("text/plain"))
        .setBody().constant("Missing requiredHeader!")
        .log("${body}")
        .stop()
    .end()
    .setHeader("CamelHttpResponseCode", constant(200))
    .setHeader("Content-Type", constant("text/plain"))
    .setBody().simple("requiredHeader value: ${headers.requiredHeader}")
    .log("${body}");

Haven't used blueprints myself much but above is probably fairly easy to implement with blueprints as well.