Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring @RestController not returning plain text response
    primarykey
    data
    text
    <p>I'm experimenting with the new Spring 4.0 @RestController to return a simple text response from a controller:</p> <pre><code>@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!"; } } </code></pre> <p>When I access /heartbeat then I get back:</p> <pre><code>"I'm Alive!" </code></pre> <p>The result includes the double quotes, what I did not expect.</p> <p>When I access /heartbeat/test then I get a empty response back, but I expect the I'm Alive! text.</p> <p><strong>UPDATE</strong></p> <p>curl -i <a href="http://myserver.com/rest/heartbeat">http://myserver.com/rest/heartbeat</a></p> <p>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</p> <p>"I'm Alive!"</p> <p>curl -i -H "Accept: application/json" <a href="http://myserver.com/rest/heartbeat">http://myserver.com/rest/heartbeat</a> 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</p> <p>"I'm Alive!"</p> <p>curl -i <a href="http://myserver.com/rest/heartbeat/test">http://myserver.com/rest/heartbeat/test</a></p> <p>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</p> <p>curl -i -H "Accept: text/plain" <a href="http://myserver.com/rest/heartbeat/test">http://myserver.com/rest/heartbeat/test</a></p> <p>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</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload