2
votes

I have a Rest API, created with Camel Rest-DSL. There is a rest, that consumes GET with a list of params, some of which are mandatory.

Route config:

    rest().get("/{{camel.rest.version}}/myget")
            .param()
                .name("accountNumber")
                .dataType("string")
                .type(RestParamType.query)
                .required(true)
            .endParam()
            .param()
                .name("someId")
                .dataType("string")
                .type(RestParamType.query)
                .required(false)
            .endParam()
            .produces(REST_PR_CN_TYPE)
            .responseMessage().code("200").message("OK").endResponseMessage()
            .responseMessage().code("500").endResponseMessage()
            .route().routeId("rst_cardsInfo")
            .log(LoggingLevel.INFO, "ApiRq Recieved http request")
            .log(LoggingLevel.DEBUG, "AccountNumber: ${header.accountNumber}, SomeId: ${header.someId}")
            .id("rst_rst_info_recieved")
            .to("direct:drt_rst_info")
            .endRest();

When I open swagger-ui generated page, my API is looks fine. Param accountNumber is marked as required, someId - as not required.

Using any other tool I can send a request without any params and receive HTTP.200 as a response. I expected, that if a param is required, but not present in request, the request would fail. Spring Rest for example makes sure that all mandatory params are present.

Is there any mandatory params presence validation in Camel? May be I misconfigured something?

2
What version of Camel do you use, and have you tried with a newer version - Claus Ibsen
@Claus Ibsen, version is 2.21.0.000033-fuse-000001-redhat-1. Unfortunatly, I can't change it, my project requires using redhat repo. - Ermintar

2 Answers

4
votes

Ah okay. There is no / only a little bit of validation today in the rest-dsl. It relies on the chosen HTTP component (servlet, restlet, undertow etc.) to do that.

But frankly we can improve thise and let camel-core do some pre-validation if the options has been specified as in your example.

I have logged a ticket: https://issues.apache.org/jira/browse/CAMEL-12533

2
votes

Thank you, @Claus Ibsen.

From Camel 2.22 version onwards, now we can validate incoming client request.

The validation is turned off by default. In order to configure it, we need to use clientRequestValidation as follow :

restConfiguration()
    .component("restlet").host("localhost").port("port")
    .clientRequestValidation(true);

For more details visit : Client Request Validation - Apache Camel Manual