Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3643

@NotNull @NotBlank @Valid is not working in spring boot rest api validation

$
0
0

@NotNull, @NotEmpty, @NotBlank annotations are not working in my rest controller. My requirement is to restrict the flow at controller and get 400 error when i hit the controller without required parameters. But when i pass null or empty headers to my controller, i am not getting 400 error. my controller hits my handler class which is not the expected behaviour

Below is my controller

@RestController@RequestMapping("/intelligent-banking")public class CrossSellOffersRetrievalController {    @Autowired    private CrossSellOffersRetrievalHandler crossSellOffersRetrievalHandler;    @Autowired    Environment env;    @GetMapping(value = "/cross-sell-offers/{interactionPoint}", produces = { MediaType.APPLICATION_JSON_VALUE })    public ResponseEntity<CrossSellOffersRetrievalResponse> getApplicableOffers(            @RequestHeader(value = "channelId", required = true) @Valid String channelId,            @RequestHeader(value = "clientId", required = false) String clientId,            @RequestHeader(value = "actionId", required = true) @NotNull @NotEmpty String actionId,            @RequestHeader(value = "customerId", required = true) @NotNull @NotBlank String customerId,            @RequestHeader(value = "cinSuffix", required = true) @NotNull @NotBlank String cinSuffix,            @RequestHeader(value = "sessionId", required = true) @NotNull @NotBlank String sessionId,            @RequestHeader(value = "countryCode", required = true) @NotNull @NotBlank String countryCode,            @PathVariable(value = "interactionPoint", required = true) @NotNull @NotBlank String interactionPoint,            @RequestParam(value = "numberOfOffers", required = false) Integer numberOfOffers)            throws CrossSellOffersException {       try {                CrossSellOffersRetrievalResponse crossSellOffersResponse = crossSellOffersRetrievalHandler.getCrossSellOffersRetrievalResponse(channelId,                        customerId, cinSuffix, countryCode, interactionPoint, sessionId, numberOfOffers);                HttpHeaders httpHeaders = new HttpHeaders();                httpHeaders.set("CustomerId", customerId);                return new ResponseEntity<>(crossSellOffersResponse, httpHeaders, HttpStatus.OK);        }         catch (Exception e) {            LOGGER.error("Inside CrossSellOffersRetrievalController::getApplicableOffers::Exception - Exception occurred at getApplicableOffers: {} ",e.getMessage());            throw new CrossSellOffersException(Constants.ERROR_CODE, e.getMessage());        }    }}

Viewing all articles
Browse latest Browse all 3643

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>