2015-03-04 15 views
7

máy chủ phần còn lại của tôi là tạo ra phản ứng khi tôi gọi nó với phần mềm khách hàng còn lại. Khi tôi gọi nó với mã số resttemplate được đề cập ở trên, thì máy chủ tạo phản hồi (bản ghi in) nhưng resttemplate không làm gì (không có dòng tiếp theo nào thực hiện sau cuộc gọi) và in lỗi nội bộ.Spring restTemplate vấn đề trong việc phản ứng

Đây là phương pháp trong máy chủ của tôi

@ResponseBody 
public ResponseEntity<Map<String, Object>> name(){...... 
... 
return new ResponseEntity<Map<String, Object>>(messagebody, HttpStatus.OK); 
} 

Đây là cách tôi gọi đó là thông qua restTemplate

ResponseEntity<Map> response1 = restTemplate.getForEntity(finalUrl.toString(), Map.class); 
+0

Bạn có bất kỳ chi tiết bổ sung về lỗi nội bộ? –

Trả lời

14

Cố gắng sử dụng ParameterizedTypeReference thay vì wildcarded Bản đồ. Nó sẽ trông như thế này.

ParameterizedTypeReference<Map<String, Object>> typeRef = new ParameterizedTypeReference<Map<String, Object>>() {}; 

ResponseEntity<Map<String, Object>> response = restTemplate.exchange(finalUrl.toString(), HttpMethod.GET, null, typeRef); 
0

đây là một ví dụ mà làm việc cho tôi

@RequestMapping(value = "/getParametros/{instancia}", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) 
public ResponseEntity<String> getParametros(@PathVariable String instancia) 
{ 
    LOG.debug("REST. Obteniendo parametros del servidor " + instancia); 
    Map<String, String> mapa = parametrosService.getProperties(instancia); 
    HttpHeaders headers = new HttpHeaders(); 
    headers.add("Content-Type", "application/json; charset=UTF-8"); 
    headers.add("X-Fsl-Location", "/"); 
    headers.add("X-Fsl-Response-Code", "302"); 
    ObjectMapper mapper = new ObjectMapper(); 

    String s = ""; 
    try 
    { 
     s = mapper.writeValueAsString(mapa); 
    } catch (JsonProcessingException e) 
    { 
     LOG.error("NO SE PUEDE MAPEAR A JSON"); 
    } 

    if (mapa == null) 
     return new ResponseEntity<String>(HttpStatus.BAD_REQUEST); 

    return new ResponseEntity<String>(s, headers, HttpStatus.OK); 
} 
Các vấn đề liên quan