On Thu, Oct 4, 2012 at 9:51 AM, Shireesh <ashirees
...@gmail.com> wrote:
> Thankz Peter.
> On Wednesday, 3 October 2012 02:38:36 UTC+5:30, Peter Neubauer wrote:
>> 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
>> On Tue, Oct 2, 2012 at 6:07 AM, Shireesh <ashir...@gmail.com> wrote:
>> > Thanks for the reply Tero,
>> > I already tried with @Consumes annotation, but got the same exception.
>> > And as per the documentation,
>> > If we do not mention any MIME Type
>> > "By default, a resource class can respond to and produce all MIME media
>> > types of representations specified in the HTTP request and response
>> > headers."
>> > So does it mean it will very well accept Json ?
>> > Any inputs are most welcomed.
>> > Thanks,
>> > Shireesh.
>> > On Monday, 1 October 2012 21:01:48 UTC+5:30, Tero Paananen wrote:
>> >> > @javax.ws.rs.Path("/process-json")
>> >> > public class Process{
>> >> > @POST
>> >> > public final Response processJson(final List<String> listOfJson){
>> >> > for(String json : listOfJson)
>> >> > {
>> >> > processJsonString(json);
>> >> > }
>> >> > }
>> >> > }
>> >> Annotate processJson with:
>> >> @Consumes(MediaType.APPLICATION_JSON)
>> >> import javax.ws.rs.Consumes;
>> >> import javax.ws.rs.core.MediaType; // "application/json"
>> >> -TPP
>> > --
> --