2016-04-22 36 views
5

ho scritto un REST chiamata che restituirà lo stato di salute quando viene chiamatoprimavera Resto servizio di chiamata di ritorno errore sulla linea 1 alla colonna 1: Il documento è vuoto

@RestController 
@RequestMapping(value = "/account") 
public class HealthCheckController { 

    protected final Logger log = LoggerFactory.getLogger(this.getClass()); 

    @RequestMapping(value = "/health", method = RequestMethod.GET, produces = { "application/json" }) 
    @ResponseStatus(HttpStatus.OK) 
    @ApiOperation(value = "Returns the health status of the application", notes = "Load balancer user this to confirm the health of the node") 
    public @ResponseBody String getHealth(HttpServletRequest request, HttpServletResponse response) throws Exception { 

     log.info("***" + RequestCorrelation.getId() + "***" + "HealthCheckController - getHealth() Called"); 

     return "{\"health\":{\"SERVICES\":\"OK\"}}"; 
    } 

} 

Quando ho aperto questo spavalderia o al postino restituisce risposta adeguata . Ma quando ho colpito questo URL nel browser Chrome sto vedendo

This page contains the following errors: 

error on line 1 at column 1: Document is empty 
Below is a rendering of the page up to the first error. 

Perché così? e come risolvere questo?

risposta

0

cercare di tornare, non una stringa, ma

return new ResponseEntity<>(yourString, HttpStatus.OK); 

e anche cambiare questo

public @ResponseBody String getHealth(HttpServletRequest request, HttpServletResponse response) throws Exception { 

a questo

public @ResponseBody ResponseEntity<String> getHealth(HttpServletRequest request, HttpServletResponse response) throws Exception { 

E se non funziona, tenta di aggiungere. xml o .json alla fine del tuo URL, quando accedici nel browser.