简体   繁体   English

春季休息服务不归身体

[英]Spring rest service not returning body

I have one rest service with following implementation - 我有一项以下服务的休息服务-

    @RequestMapping(method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    @JsonSerialize
    public ResponseEntity<String> handleData(HttpMethod method, HttpServletRequest httpRequest)
            throws URISyntaxException, IOException {

        BackendRequest request = new BackendRequest();
        request.setHttpRequest(httpRequest);
        request.setMethod(method);

        BackendResponse backendResponse = service.getresponse(request);
        ResponseEntity<String> response = backendResponse.getResponse();
        return new ResponseEntity<String>(response.getBody(), response.getHeaders(), response.getStatusCode());
        // return response;

    }

I am getting all the headers and response status correctly but I am not getting the json response. 我正确地获取了所有标头和响应状态,但是没有得到json响应。 What is wrong here? 怎么了

I am trying to do following - https://stackoverflow.com/a/23736527/2197994 我正在尝试以下操作-https: //stackoverflow.com/a/23736527/2197994

Somewhere deep inside the nested calls, I am getting the response from some other backend using spring rest template. 在嵌套调用的某个深处,我正在使用spring rest模板从其他后端获取响应。

public BackendResponse callBackend(BackendRequest request) throws URISyntaxException, IOException {

        String body = null;
        ResponseEntity<String> responseEntity = null;
        URI uri = new URI("http", null, "localhost", 8080, request.getRequestURL(), request.getQueryString(), null);

        MultiValueMap<String, String> requestHeaders = getHeadersInfo(request.getHttpRequest());

        if (HttpMethod.POST.equals(request.getMethod())) {
            body = request.getHttpRequest().getReader().lines().collect(Collectors.joining(System.lineSeparator()));
            responseEntity = restTemplate.exchange(uri, request.getMethod(),
                    new HttpEntity<String>(body, requestHeaders), String.class);

        } else if (HttpMethod.GET.equals(request.getMethod())) {
            responseEntity = restTemplate.exchange(uri, request.getMethod(),
                    new HttpEntity<String>(body, requestHeaders), String.class);
        } else {
            LOG.warn("Method:{} not supported yet", request.getMethod());
        }

        BackendResponse response = new BackendResponse();
        response.setResponse(responseEntity);
        return response;

    }

BackendResponse backendResponse = service.getresponse(request) could be the problem. BackendResponse backendResponse = service.getresponse(request)可能是问题。 Could you post the content of the method ? 您可以发布方法的内容吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM