Log http request body , if exception has occured

Viewed 1650

I have been developing rest api service using spring boot. This is my rest controller

@RequestMapping(value = "owner/login", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public ResponseEntity<String> login(@RequestBody Owner owner) throws TimeoutException, SocketTimeoutException, SocketException {
        controller.login(owner);
        return ResponseEntity.ok("\"error\": 0");
    }

This is controller

 public JsonObject login(Owner loginOwner){
        Map<String,String> params = new HashMap<String,String>();
        params.put("email", loginOwner.getEmail());
        params.put("password", loginOwner.getPassword());
        if(GMoikaStringUtils.isEmpty(loginOwner.getEmail()) || !GMoikaStringUtils.isValidEmail(loginOwner.getEmail())){
            throw new InvalidUserInputException("Wrong email format", CLASS_NAME, "login", params, "owners/owner/login POST");
        }
        else{
            someLogic...
        }
    }

The question is, using this structure i should to create map with params inside each method.How to avoid creation of map inside each method and put all params into this map? I need "MAP" to show params in logs in case if exception is occured. Maybe spring boot can do it , but i can't find my case in official docs. Thanks in advance

2 Answers
Related