0

I have a simple Spring Boot application which accepts various event types. I have put a validation on the controller to check against those Event types. If Event Type does not match the Enum from the calling Client App, i throw an exception. However if the Value matches one of the event i want to retrieve that value and do a custom logic from Controller to Service Class. Any idea on how it can be done. Here is the Rest Controller and Enum Class.

public enum EventTypes {
ADDONE("AddOne"),
DELETEONE("DeleteOne"),
ADDTWO("AddTwo"),
DELETETWO("DeleteTwo");

private String event;

private EventTypes(String event){
    this.event = event;
}

}

Rest Controller:

@PostMapping(value = "/eventProcess", consumes = MediaType.APPLICATION_JSON_VALUE, 
             produces = MediaType.APPLICATION_JSON_VALUE)

    public GenericResponse produceEventMessage(
        @Parameter(in = ParameterIn.QUERY, description = "", required = true)
        @RequestParam(value = "eventType", required = true) EventTypes eventType,
        @Valid @RequestBody MessageRequest messageEventRequest) {

    LOG.info("Event Type ::::" + eventType); // I need to retrieve this value
    
    ... Remaining Business Logic to be executed

}

Client Application URL : http://localhost:8080/eventProcess?eventType=AddOne

Tarun Pande
  • 371
  • 1
  • 6
  • 18
  • Hi, I see that you use a HTTP POST (`@PostMapping`) along with a Request Parameter (`@RequestParam`). Usually request parameters are used with HTTP GET. So what you get in your `LOG.info("Event Type ::::" + eventType); ` does it print anything? – pleft Aug 25 '21 at 14:01
  • It prints Null. This is how the client is currently sending the request and do not want us to change the implementation. – Tarun Pande Aug 25 '21 at 14:03
  • What about if you try: `http://localhost:8080/eventProcess?eventType=ADDONE` ? – pleft Aug 25 '21 at 14:08
  • It still says Null. I followed this article and it works fine for me. https://stackoverflow.com/questions/59422883/spring-boot-custom-validation-in-request-params – Tarun Pande Aug 25 '21 at 14:41

0 Answers0