0

Below code is throwing 500 Internal server error only in server but works in local host. Any input is appreciated.

Controller endpoint:

@ApiOperation(value = "This API gets info from external service")
    @PostMapping(value = "/ref-data/info", headers= "Accept=application/json")
    public ResponseEntity<String> getMasterMaterialInfo(@RequestBody RequestDTO requestDTO) {
        return service.getInfo(requestDTO);
    }

Service method:

public ResponseEntity<String> getInfo(RequestDTO requestDTO) {
        HttpEntity<RequestDTO> request = new HttpEntity<>(requestDTO);
        String requestUrl =  refDataUrl+"?apikey="+apikey;
        return restTemplate.exchange(requestUrl, HttpMethod.POST, request, String.class);
    }

Server Log:

enter image description here Thanks

1 Answer 1

0

This issue is because of the broken response entity pipeline. Solution is to read the content of the response entity and assign it to the new instance of the response entity that instead of returning the response as it is..

Change in service layer:

public String getInfo(RequestDTO requestDTO) {
        HttpEntity<RequestDTO> request = new HttpEntity<>(requestDTO);
        String requestUrl =  refDataUrl+"?apikey="+apikey;
        ResponseEntity<String> responseEntity =  restTemplate.exchange(requestUrl, HttpMethod.POST, request, String.class);
        return responseEntity.getBody()
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.