1

please i have this error when trying to create a customer. Can some one help me? May be i am missing some thing. I have even try to change the @PostMapping to @RequestMapping till yet. Thks

My Controller code

`@PostMapping("CREATE_CUSTOMER_ENDPOINT") @ResponseStatus(value = HttpStatus.OK) @ApiResponses(value = { @ApiResponse(code = 201, message = "The Customer was Created", response = CustomerDto.class), @ApiResponse(code = 400, message = "Bad Request", response = ResponseError.class), @ApiResponse(code = 500, message = "Unexpected error") }) 
 public ResponseEntity createCustomer(final HttpServletRequest request, @RequestBody CustomerDto customerDto) { if (log.isDebugEnabled()){ log.debug("[CustomerResource] POST {} : Creating customer ", CREATE_CUSTOMER_ENDPOINT); } if(customerDto.getUidpk()!=null) { ResponseError error = new ResponseError(HttpStatus.BAD_REQUEST.getReasonPhrase(), "A customer Already exist with an Uidpk"); log.error("[CustomerResource] The customer Already exist ({}) with an Uidpk", customerDto.getUidpk()); return new ResponseEntity<>(error, null, HttpStatus.BAD_REQUEST); } CustomerDto result = customerService.createCustomer(customerDto); log.debug("[CustomerResource] Customer created ({})", result.getUidpk()); return new ResponseEntity<>(result, HeaderUtil.putLocationHeader(request.getRequestURL().toString() + "/" + result.getUidpk()), HttpStatus.CREATED); } ` 

My endpoints

private static final String CUSTOMER_SEARCH_USER_ID_ENDPOINT = "/customers/{userId:.+}"; private static final String CREATE_CUSTOMER_ENDPOINT= "/customer"; private static final String UPDATE_CUSTOMER_ENDPOINT= "/customer"; private static final String DELETE_CUSTOMER_ENDPOINT = CREATE_CUSTOMER_ENDPOINT + "/{uidpk}";

This is the response of Postman Postman sample

3
  • does it have to do with you annotation , @PostMapping("CREATE_CUSTOMER_ENDPOINT") , i think you want this --> @PostMapping(CREATE_CUSTOMER_ENDPOINT) Commented Jan 15, 2018 at 10:22
  • mistake sorry. i corrected it and i ha a new error in Postman : "error": "Internal Server Error", "error_description": [ "Content type 'text/plain;charset=UTF-8' not supported" ] } Commented Jan 15, 2018 at 10:28
  • add the headers in your request , and it will solve it , do validate your JSON value using any online validator Commented Jan 15, 2018 at 10:38

1 Answer 1

2

When you send JSON payloads in HTTP request, you need to specify Content-Type HTTP header with value application/json.

Sign up to request clarification or add additional context in comments.

2 Comments

He should also be using the consumes and produces members of @PostMapping to that effect.
My request is working well. But when i got into my createCustomer method as mention recently, it goes into this condition if(customerDto.getUidpk()!=null) and replies "A customer Already exist with an Uidpk". Am using the H2 DATABASE. My database is empty. Please i am really confused. Any Proposition Thk you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.