Shireesh,
just tried this:
@Path("/helloworld")
public class HelloWorldResource {
private final GraphDatabaseService database;
public HelloWorldResource(@Context GraphDatabaseService database) {
this.database = database;
}
@GET
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
@Path("/{nodeId}")
public Response hello(@PathParam("nodeId") long nodeId) {
// Do stuff with the database
return Response.status(Status.OK)
.entity(("Hello World, nodeId=" + nodeId).getBytes()).build();
}
}
And the server complains rightfully for application/json, and not for
text/plain:
➜ server-examples git:(working) ✗ curl -H
"Content-Type:application/json" -v
http://localhost:7474/test/helloworld/1
* About to connect() to localhost port 7474 (#0)
* Trying ::1...
* Connection refused
* Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 7474 (#0)
> GET /test/helloworld/1 HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:7474
> Accept: */*
> Content-Type:application/json
>
< HTTP/1.1 415 Unsupported Media Type
< Access-Control-Allow-Origin: *
< Content-Type: text/html; charset=iso-8859-1
< Cache-Control: must-revalidate,no-cache,no-store
< Content-Length: 1408
< Server: Jetty(6.1.25)
<
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 415 Unsupported Media Type</title>
</head>
<body><h2>HTTP ERROR 415</h2>
<p>Problem accessing /test/helloworld/1. Reason:
<pre> Unsupported Media Type</pre></p><hr /><i><small>Powered by
Jetty://</small></i><br/>
➜ server-examples git:(working) ✗ curl -H "Content-Type:text/plain"
-v
http://localhost:7474/test/helloworld/1
* About to connect() to localhost port 7474 (#0)
* Trying ::1...
* Connection refused
* Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 7474 (#0)
> GET /test/helloworld/1 HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:7474
> Accept: */*
> Content-Type:text/plain
>
< HTTP/1.1 200 OK
< Content-Length: 21
< Content-Type: text/plain
< Access-Control-Allow-Origin: *
< Server: Jetty(6.1.25)
<
* Connection #0 to host localhost left intact
Hello World, nodeId=1* Closing connection #0
------------
Cheers,
/peter neubauer
G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L:
http://www.linkedin.com/in/neubauer
T: @peterneubauer
Wanna learn something new? Come to
http://graphconnect.com
> --
>
>