服务器在本地主机中运行时发生内部服务器错误

问题描述 投票:0回答:1

下面的代码仅在服务器中抛出 500 内部服务器错误,但在本地主机中有效。任何意见都将受到赞赏。

控制器端点:

@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);
    }

服务方式:

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);
    }

服务器日志:

enter image description here 谢谢

localhost production-environment internal-server-error spring-resttemplate
1个回答
0
投票

此问题是由于响应实体管道损坏造成的。解决方案是读取响应实体的内容并将其分配给响应实体的新实例,而不是按原样返回响应..

服务层的变化:

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()
    }
© www.soinside.com 2019 - 2024. All rights reserved.