Search code examples
javaspring-mvcresttemplate

rest template returns 500 internal server error exception


I'm making an app and trying to get json written on the web page. So, I can see this page in browser: it contains only json.

But when I start a request with the RestTemplate it returns ma only 500 internal server error.

My caode is very simple:

    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders requestHeaders = new HttpHeaders();    
    requestHeaders.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders);
    ResponseEntity<MyClass[]> responseEntity =     restTemplate.exchange(url, HttpMethod.GET, requestEntity, MyClass[].class);

I cannot understand what is wrong: I have an access, it is simple, I'm not authentificated and I don't need id. Why an error?


Solution

  • The 500 Internal Server Error means something has gone wrong on the server side... You should check your URL, parameter, cookies, etc... (in firebug by example)

    I test your code and i got a 200 status on a valid URL.