Restlets in gwt with json

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Restlets in gwt with json

Xavier Méhaut
Hello,

I usually transmit objects between client and server, but today I want to transmet json data :)
I've no problem with a GET, but I've the following  error
  (org.restlet.client.data.Status) Unsupported Media Type (415) - Unsupported Media Type
when I try to do a PUT (or a POST)...

Here is the client-side code :
                   
                    ClientResource clientResource =
                        new ClientResource("a uri");

                    clientResource.setOnResponse(new Uniform() {
                       
                        @Override
                        public void handle(org.restlet.client.Request request,
                                org.restlet.client.Response response) {
                           System.out.println(response.getStatus());
                           
                        }
                    });
                JSONObject sentObject = new JSONObject();
                sentObject.put("identifiant", new JSONString(identifiantItem.getValueAsString()));
                sentObject.put("pwd", new JSONString(pwdItem.getValueAsString()));
                JsonRepresentation rep = new JsonRepresentation(MediaType.APPLICATION_JSON);
                rep.setValue(sentObject);
                clientResource.put(rep,MediaType.APPLICATION_JSON);
               
Any idea?
regards
Xavier

ps : generally, the examples given on the wiki or even in the book are Get request... some examples with put and post would be good too...
Reply | Threaded
Open this post in threaded view
|

RE: Restlets in gwt with json

Thierry Boileau-3
Hello Xavier,

I guess the issue is located on server side. I send you a sample project in order to help you.

Best regards,
Thierry Boileau

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3023650

testXavier.zip (8M) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Restlets in gwt with json

Xavier Méhaut
Hi Thierry
I looked at your example, and actually the code differs from mine. Here is my code to mimic the client code :

    @Put("json")
    public void put(JsonRepresentation loginRep) throws JSONException {
        JSONObject loginElt = loginRep.getJsonObject();

        System.out.println("identifiant: " + loginElt.getString("identifiant"));
        System.out.println("mot de passe: " + loginElt.getString("pwd"));
        System.out.println("entreprise: " + loginElt.getString("entreprise"));

    }

regards
Xavier

2012/10/26 Thierry Boileau <[hidden email]>
Hello Xavier,

I guess the issue is located on server side. I send you a sample project in order to help you.

Best regards,
Thierry Boileau

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3023650

Reply | Threaded
Open this post in threaded view
|

Re: Restlets in gwt with json

Xavier Méhaut
and the current code is like this one :

@Post()
    public void post(StringRepresentation loginRep) throws JSONException {
        Utilisateur user =
                (new Gson()).fromJson(loginRep.getText(), Utilisateur.class);   
    }

2012/10/26 [hidden email] <[hidden email]>
Hi Thierry
I looked at your example, and actually the code differs from mine. Here is my code to mimic the client code :

    @Put("json")
    public void put(JsonRepresentation loginRep) throws JSONException {
        JSONObject loginElt = loginRep.getJsonObject();

        System.out.println("identifiant: " + loginElt.getString("identifiant"));
        System.out.println("mot de passe: " + loginElt.getString("pwd"));
        System.out.println("entreprise: " + loginElt.getString("entreprise"));

    }

regards
Xavier


2012/10/26 Thierry Boileau <[hidden email]>
Hello Xavier,

I guess the issue is located on server side. I send you a sample project in order to help you.

Best regards,
Thierry Boileau

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3023650


Reply | Threaded
Open this post in threaded view
|

RE: Re: Restlets in gwt with json

Thierry Boileau-3
Hello Xavier,

your code works for me also using the RC6 or 2.1.0 release. I've updated my sample project, with several ways to do the same thing.

I hope this will help you.

Best regards,
Thierry Boileau

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3023749