0

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. What is wrong here?

I am trying to do following - 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.

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;

    }
Popeye
  • 1,548
  • 3
  • 25
  • 39

1 Answers1

0

BackendResponse backendResponse = service.getresponse(request) could be the problem. Could you post the content of the method ?

RoadEx
  • 543
  • 2
  • 12
  • It is getting the data from deep inside nested calls. Deep inside there is this spring rest client call which is calling some other backend for the data. – Popeye Jan 10 '18 at 11:35