Skip to content
Advertisement

Request validation doesn’t happen in camel rest

I am trying to experiment by building some simple API’s with apache camel. The request body for a post request is empty but camel doesn’t return bad request instead it returns 201.

Here is what I do;

  1. Generate classes from studentreg-api.yaml [This is a valid openapi 3 yaml document]
  2. Using camel, spring boot to build REST endpoints Step
  3. Configured camel rest endpoint with clientRequestValidation(true)
  4. Start the server
  5. Open /api-docs and validated if the mandatory attributes are marked appropriately
  6. From postman made request to the POST endpoint with blank request body

Expected: 400 – Bad request Actual: 201

I couldn’t figure out what is that I am missing.

BaseRouteConfig.java

JavaScript

RegisterStudentRoute.java

JavaScript

pom.xml

JavaScript

Advertisement

Answer

ok! I have figured out a simpler way to handle validation. Adding a route to bean-validator solved the problem! If we need to build custom error messages or if you need to build error model based on failures, you can use camel processor and javax.validator.

RegisterStudentRoute.java

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement