I'm experimenting with the new Spring 4.0 @RestController to return a simple text response from a controller:
@RestController
@RequestMapping(value = "/heartbeat")
public class HeartbeatController {
private static final Logger logger = LoggerFactory.getLogger(HeartbeatController.class);
@RequestMapping
public String heartbeat() {
logger.info("Received heartbeat!");
return "I'm Alive!";
}
@RequestMapping(value = "/test", produces = MediaType.TEXT_PLAIN_VALUE)
public String heartbeat2() {
logger.info("Received heartbeat!");
return "I'm Alive!";
}
}
When I access /heartbeat then I get back:
"I'm Alive!"
The result includes the double quotes, what I did not expect.
When I access /heartbeat/test then I get a empty response back, but I expect the I'm Alive! text.
UPDATE
curl -i http://myserver.com/rest/heartbeat
HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 Server: Development/1.0 Date: Tue, 17 Dec 2013 18:59:08 GMT Cache-Control: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Content-Length: 12
"I'm Alive!"
curl -i -H "Accept: application/json" http://myserver.com/rest/heartbeat HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 Server: Development/1.0 Date: Tue, 17 Dec 2013 19:01:12 GMT Cache-Control: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Content-Length: 12
"I'm Alive!"
curl -i http://myserver.com/rest/heartbeat/test
HTTP/1.1 406 Not Acceptable Server: Development/1.0 Date: Tue, 17 Dec 2013 19:00:13 GMT Cache-Control: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Content-Length: 0
curl -i -H "Accept: text/plain" http://myserver.com/rest/heartbeat/test
HTTP/1.1 406 Not Acceptable Server: Development/1.0 Date: Tue, 17 Dec 2013 19:02:06 GMT Cache-Control: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Content-Length: 0