Richard Berger | 9 Feb 20:32

Post problems when using Restlet Javascript Edition...

Working on a small project to learn REST/Restlet and ran into a problem where
I can successfully post from a Java client to my server or from an HTML form
to my server, but when I try to post from Javascript it fails.  I am
following the sample code that is now on
github
(https://github.com/restlet/restlet-framework-js/tree/master/tests/org.restlet.js.tests/src/browser/static/html).

On the client side...
For Java (working), I have:
    System.out.println("Adding a commitment");
		ClientResource client3 = new
ClientResource("http://localhost:8888/commitments/");
		client3.setRequestEntityBuffering(true);  // Per
http://stackoverflow.com/questions/6462142/length-required-411-length-required-in-a-restlet-client
		Commitment commitment3 = new Commitment();
		commitment3.setTitle("Added through post - Java client");
		commitment3.setDescription("This is a description of post Java client");
		Representation representation3 = client3.post(commitment3);

For Javascript (not working), I have: 		 
asyncTest("Post with resource Commitment (json)", function() {
  var clientResource = new ClientResource("/commitments/");
  var commitment = {
	title: "From automated test",
	description: "This is from our automated test"
  }
  var jsonRepresentation = new JsonRepresentation(commitment);
  alert(jsonRepresentation.getText());
  // Result is: {"title":"From automated test","description":"This is from
our automated test"}
(Continue reading)

Thierry Templier | 14 Feb 10:23

Re: Post problems when using Restlet Javascript Edition...

Hello Richard,

It seems that the missing EncodingWriter class is called in the 
restlet-browser.js. For information, the header management processing is 
still under development but your code should work!

Can you open an issue on GitHub and attachment your source code so we 
can fix the problem quickly?

Thanks very much!
Thierry

> Working on a small project to learn REST/Restlet and ran into a problem where
> I can successfully post from a Java client to my server or from an HTML form
> to my server, but when I try to post from Javascript it fails.  I am
> following the sample code that is now on github
> (https://github.com/restlet/restlet-framework-js/tree/master/tests/org.restlet.js.tests/src/browser/static/html).
>
> On the client side...
> For Java (working), I have:
>      System.out.println("Adding a commitment");
> 		ClientResource client3 = new
> ClientResource("http://localhost:8888/commitments/");
> 		client3.setRequestEntityBuffering(true);  // Per
> http://stackoverflow.com/questions/6462142/length-required-411-length-required-in-a-restlet-client
> 		Commitment commitment3 = new Commitment();
> 		commitment3.setTitle("Added through post - Java client");
> 		commitment3.setDescription("This is a description of post Java client");
> 		Representation representation3 = client3.post(commitment3);
>
(Continue reading)

Richard Berger | 15 Feb 01:07

Re: Post problems when using Restlet Javascript Edition...

First - thank you for your message and the work that you are doing.

I downloaded the latest .js files and the previously reported error is
indeed fixed.  But my post() is still not being received on the server side
when called from Javascript.  From Javascript, I am able to succesfully call
get and put.  From a Java client, I can successfully call post.  And a
standard HTML form post works too.

Details on the error... (from Chrome's Javascript console)
POST http://localhost:8888/commitments/ 415 (Unsupported Media Type)
Class.lowLevelSendRequestrestlet-browser.js:3681
Class.sendRequestrestlet-browser.js:3630
Class.commitrestlet-browser.js:3776
Class.handlerestlet-browser.js:3812
Class.handlerestlet-browser.js:3865
Class.handleNextrestlet-browser.js:4311
Class.handleRequestrestlet-browser.js:4301
Class.handlerestlet-browser.js:4293
Class.postrestlet-browser.js:4232
(anonymous function)oldTest.html:64
Test.runqunit.js:102
Test.queue.badqunit.js:232
processqunit.js:865
QUnit.start.config.blocking

Details of my client code....
asyncTest("Post with resource Commitment (json)", function() {
  var clientResource = new ClientResource("/commitments/");
  var commitment = {
       title: "From automated test",
(Continue reading)

Thierry Templier | 15 Feb 15:15

Re: Post problems when using Restlet Javascript Edition...

Hello Richard,

It could be either an HTTP header not correctly in the JS part or a problem on methods signatures within ServerResource class...

Can you give me the request content of both calls from Java and JS?

- For Java, simply active tracing mode on the ClientResource client (http://templth.wordpress.com/2011/05/17/activating-tracing-mode-in-restlet/):

String url = "(...)";
Context context = new Context();
ClientResource clientResource = new ClientResource(context, url);
Context context = clientResource.getContext();
context.getParameters().add("tracing", "true");

- For JS, you can have access to the content using for example Firebug...

Thanks!
Thierry

First - thank you for your message and the work that you are doing. I downloaded the latest .js files and the previously reported error is indeed fixed. But my post() is still not being received on the server side when called from Javascript. From Javascript, I am able to succesfully call get and put. From a Java client, I can successfully call post. And a standard HTML form post works too. Details on the error... (from Chrome's Javascript console) POST http://localhost:8888/commitments/ 415 (Unsupported Media Type) Class.lowLevelSendRequestrestlet-browser.js:3681 Class.sendRequestrestlet-browser.js:3630 Class.commitrestlet-browser.js:3776 Class.handlerestlet-browser.js:3812 Class.handlerestlet-browser.js:3865 Class.handleNextrestlet-browser.js:4311 Class.handleRequestrestlet-browser.js:4301 Class.handlerestlet-browser.js:4293 Class.postrestlet-browser.js:4232 (anonymous function)oldTest.html:64 Test.runqunit.js:102 Test.queue.badqunit.js:232 processqunit.js:865 QUnit.start.config.blocking Details of my client code.... asyncTest("Post with resource Commitment (json)", function() { var clientResource = new ClientResource("/commitments/"); var commitment = { title: "From automated test", description: "This is from our automated test" } var jsonRepresentation = new JsonRepresentation(commitment); alert(jsonRepresentation.getText()); // Result is: {"title":"From automated test","description":"This is from our automated test"} clientResource.post(jsonRepresentation, function(representation) { console.log("representation.getText() = "+representation.getText()); // Note: commenting or not commenting out all the lines below doesn't make a difference //var jsonRepresentation = new JsonRepresentation(representation); //var obj = jsonRepresentation.getObject(); //ok(obj.id, "1"); //ok(obj.title, "From automated test"); //ok(obj.description, "This is from our automated test"); start(); }, MediaType.APPLICATION_JSON); }); You had mentioned that you are still working on the header management processing - would that be a likely reason for the 415 error or am I not doing something required for Post in particular. Also, would you still like me to open an issue in GitHub for this problem or the previous one? Thanks so much! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Post-problems-when-using-Restlet-Javascript-Edition-tp7270413p7286087.html Sent from the Restlet Discuss mailing list archive at Nabble.com. ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2922490

Richard Berger | 15 Feb 23:34

Re: Post problems when using Restlet Javascript Edition...

Thanks again for your help.  I downloaded tcpmon and made the suggested changes to my Java client.  I then did a post through Java and below are the Request and the Response.


Request....
POST /commitments/ HTTP/1.1
Date: Wed, 15 Feb 2012 22:19:58 GMT
Content-Length: 109
Content-Type: application/json; charset=UTF-8
Accept: */*
Host: localhost:8880
User-Agent: Restlet-Framework/2.1rc2
Cache-Control: no-cache
Pragma: no-cache
Connection: keep-alive

{"id":0,"title":"Added through post - Java client","description":"This is a description of post Java client"}

Response...
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Date: Wed, 15 Feb 2012 22:19:59 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.1rc2
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Content-Length: 1

4

Then I moved to the Javascript side.  I didn't install Firebug, but instead I just changed the ClientResource creation from:
  var clientResource = new ClientResource("/commitments/");  /
To:
  var clientResource = new ClientResource("http://localhost:8880/commitments/");
where TCPmon was running on 8880 and forwarding to 8888, which is where my server was listening.  

Below are the Request and Response - and they are definitely different than the Java version...

Request...
OPTIONS /commitments/ HTTP/1.1
Host: localhost:8880
Connection: keep-alive
Access-Control-Request-Method: POST
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11
Access-Control-Request-Headers: Origin, Content-Type, accept
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Response...
HTTP/1.1 200 OK
Content-Type: application/vnd.sun.wadl+xml; charset=UTF-8
Date: Wed, 15 Feb 2012 22:22:22 GMT
Accept-Ranges: bytes
Allow: POST, GET
Server: Restlet-Framework/2.1rc2
Transfer-Encoding: chunked

5D2
<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="wadl2html.xslt"?>
<application xmlns="http://wadl.dev.java.net/2009/02">
   <doc title="Commitments resource"/>
   <representation id="commitment" mediaType="text/plain">
      <doc title="Commitment">Simple string containing the commitment ID</doc>
   </representation>
   <resources>
      <resource path="commitments/">
         <doc title="Commitments resource">The resource that contains the list of commitments in the system</doc>
         <method name="GET">
            <response>
               <representation href="#commitment"/>
               <representation href="#commitment"/>
               <representation href="#commitment"/>
               <representation href="#commitment"/></response>
         </method>
         <method name="POST">
            <request>
               <representation href="#commitment"/>
               <representation href="#commitment"/>
               <representation href="#commitment"/>
               <representation href="#commitment"/></request>
            <response>
               <representation href="#commitment"/>
               <representation href="#commitment"/>
               <representation href="#commitment"/>
               <representation href="#commitment"/>
               <representation href="#commitment"/>
               <representation href="#commitment"/></response>
         </method>
      </resource>
   </resources>
</application>

One small typo on the http://templth.wordpress.com/2011/05/17/activating-tracing-mode-in-restlet/ article, in the ClientResource section the line:
Context context = clientResource.getContext();
should be
context = clientResource.getContext();
(but this is minor - the ease of getting the trace using Restlet tracing was awesome).

Thanks again for all your assistance!  (And my apologies in advance if the problem turns out to be some silly mistake in my code - always a real possibility).

RB


On Wed, Feb 15, 2012 at 6:15 AM, Thierry Templier [via Restlet Discuss] <[hidden email]> wrote:
Hello Richard,

It could be either an HTTP header not correctly in the JS part or a problem on methods signatures within ServerResource class...

Can you give me the request content of both calls from Java and JS?

- For Java, simply active tracing mode on the ClientResource client (http://templth.wordpress.com/2011/05/17/activating-tracing-mode-in-restlet/):

String url = "(...)";
Context context = new Context();
ClientResource clientResource = new ClientResource(context, url);
Context context = clientResource.getContext();
context.getParameters().add("tracing", "true");

- For JS, you can have access to the content using for example Firebug...

Thanks!
Thierry

First - thank you for your message and the work that you are doing. I downloaded the latest .js files and the previously reported error is indeed fixed. But my post() is still not being received on the server side when called from Javascript. From Javascript, I am able to succesfully call get and put. From a Java client, I can successfully call post. And a standard HTML form post works too. Details on the error... (from Chrome's Javascript console) POST http://localhost:8888/commitments/ 415 (Unsupported Media Type) Class.lowLevelSendRequestrestlet-browser.js:3681 Class.sendRequestrestlet-browser.js:3630 Class.commitrestlet-browser.js:3776 Class.handlerestlet-browser.js:3812 Class.handlerestlet-browser.js:3865 Class.handleNextrestlet-browser.js:4311 Class.handleRequestrestlet-browser.js:4301 Class.handlerestlet-browser.js:4293 Class.postrestlet-browser.js:4232 (anonymous function)oldTest.html:64 Test.runqunit.js:102 Test.queue.badqunit.js:232 processqunit.js:865 QUnit.start.config.blocking Details of my client code.... asyncTest("Post with resource Commitment (json)", function() { var clientResource = new ClientResource("/commitments/"); var commitment = { title: "From automated test", description: "This is from our automated test" } var jsonRepresentation = new JsonRepresentation(commitment); alert(jsonRepresentation.getText()); // Result is: {"title":"From automated test","description":"This is from our automated test"} clientResource.post(jsonRepresentation, function(representation) { console.log("representation.getText() = "+representation.getText()); // Note: commenting or not commenting out all the lines below doesn't make a difference //var jsonRepresentation = new JsonRepresentation(representation); //var obj = jsonRepresentation.getObject(); //ok(obj.id
, "1"); //ok(obj.title, "From automated test"); //ok(obj.description, "This is from our automated test"); start(); }, MediaType.APPLICATION_JSON); }); You had mentioned that you are still working on the header management processing - would that be a likely reason for the 415 error or am I not doing something required for Post in particular. Also, would you still like me to open an issue in GitHub for this problem or the previous one? Thanks so much! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Post-problems-when-using-Restlet-Javascript-Edition-tp7270413p7286087.html
Sent from the Restlet Discuss mailing list archive at Nabble.com. ------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2922490



If you reply to this email, your message will be added to the discussion below:
http://restlet-discuss.1400322.n2.nabble.com/Post-problems-when-using-Restlet-Javascript-Edition-tp7270413p7287572.html
To unsubscribe from Post problems when using Restlet Javascript Edition..., click here.
NAML


View this message in context: Re: Post problems when using Restlet Javascript Edition...
Sent from the Restlet Discuss mailing list archive at Nabble.com.
Thierry Templier | 22 Feb 10:07

Re: Post problems when using Restlet Javascript Edition...

Hello Richard,

Regarding the post HTTP method and the annotated methods server 
resources, I updated the header management in the JavaScript edition. 
The routing to such methods is based on the Content-Type header. I 
committed all my updates in GitHub, so feel free to make some tests and 
give me a feedback.

Be aware that there is a bug in Restlet 2.1 regarding the routing to the 
right methods. If a media isn't specified for the first method, this 
method will be used and it's not correct...

@Put
(...)

@Put("json")
(...)

It works with the following:

@Put("json")
(...)

@Put
(...)

This problem is about to be fixed in the Java version of Restlet.

Thierry

> Thanks again for your help.  I downloaded tcpmon and made the 
> suggested changes to my Java client.  I then did a post through Java 
> and below are the Request and the Response.
>
> Request....
> POST /commitments/ HTTP/1.1
> Date: Wed, 15 Feb 2012 22:19:58 GMT
> Content-Length: 109
> Content-Type: application/json; charset=UTF-8
> Accept: */*
> Host: localhost:8880
> User-Agent: Restlet-Framework/2.1rc2
> Cache-Control: no-cache
> Pragma: no-cache
> Connection: keep-alive
>
> {"id":0,"title":"Added through post - Java client","description":"This 
> is a description of post Java client"}
>
> Response...
> HTTP/1.1 200 OK
> Content-Type: application/json; charset=UTF-8
> Date: Wed, 15 Feb 2012 22:19:59 GMT
> Accept-Ranges: bytes
> Server: Restlet-Framework/2.1rc2
> Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
> Content-Length: 1
>
> 4
>
> Then I moved to the Javascript side.  I didn't install Firebug, but 
> instead I just changed the ClientResource creation from:
>   var clientResource = new ClientResource("/commitments/");  /
> To:
>   var clientResource = new 
> ClientResource("http://localhost:8880/commitments/");
> where TCPmon was running on 8880 and forwarding to 8888, which is 
> where my server was listening.
>
> Below are the Request and Response - and they are definitely different 
> than the Java version...
>
> Request...
> OPTIONS /commitments/ HTTP/1.1
> Host: localhost:8880
> Connection: keep-alive
> Access-Control-Request-Method: POST
> Origin: http://localhost:8888
> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 
> (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11
> Access-Control-Request-Headers: Origin, Content-Type, accept
> Accept: */*
> Referer: http://localhost:8888/oldTest.html
> Accept-Encoding: gzip,deflate,sdch
> Accept-Language: en-US,en;q=0.8
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
>
> Response...
> HTTP/1.1 200 OK
> Content-Type: application/vnd.sun.wadl+xml; charset=UTF-8
> Date: Wed, 15 Feb 2012 22:22:22 GMT
> Accept-Ranges: bytes
> Allow: POST, GET
> Server: Restlet-Framework/2.1rc2
> Transfer-Encoding: chunked
>
> 5D2
> <?xml version="1.0" standalone="yes"?>
> <?xml-stylesheet type="text/xsl" href="wadl2html.xslt"?>
> <application xmlns="http://wadl.dev.java.net/2009/02">
> <doc title="Commitments resource"/>
> <representation id="commitment" mediaType="text/plain">
> <doc title="Commitment">Simple string containing the commitment ID</doc>
> </representation>
> <resources>
> <resource path="commitments/">
> <doc title="Commitments resource">The resource that contains the list 
> of commitments in the system</doc>
> <method name="GET">
> <response>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/></response>
> </method>
> <method name="POST">
> <request>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/></request>
> <response>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/></response>
> </method>
> </resource>
> </resources>
> </application>
>
> One small typo on the 
> http://templth.wordpress.com/2011/05/17/activating-tracing-mode-in-restlet/ 
> article, in the ClientResource section the line:
> Context context = clientResource.getContext();
> should be
> context = clientResource.getContext();
> (but this is minor - the ease of getting the trace using Restlet 
> tracing was awesome).
>
> Thanks again for all your assistance!  (And my apologies in advance if 
> the problem turns out to be some silly mistake in my code - always a 
> real possibility).
>
> RB

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

Richard Berger | 23 Feb 00:23

Re: Post problems when using Restlet Javascript Edition...

Thierry:

Thanks so much for your help.  The short version is that the latest Restlet JS code (plus one change in my code) fixes my problem with post().  There is one "strangeness" that I will describe below, but it isn't a big problem for me at this point, but I will describe it below in case you think it matters.  Again, thank you!!  And, please let me know if there is any testing that I can do for you.

Details...
I installed the new scripts.  Only part that confused me was that I initially took restlet-browser.js from:
* modules\org.restlet.js\src\dist\restlet-browser.js
But that was the wrong file, I had to use:
* tests\org.restlet.js.tests\src\browser\static\restlet\restlet-browser.js
if that is what was intended, all is fine.

Once I put in the right restlet-browser.js, I ran my test and got a 415 error.  So I ran the test through tcpmon - and when going through tcpmon - it worked!  But the mystery was that when going through tcpmon, the server side method "acceptJava()" was being called, not "acceptJson()".  I changed the ordering as per your email, but that still didn't fix my problem (but I did discover that the re-ordering is indeed necessary, but that is getting ahead of the story).

At this point I had:
public interface CommitmentsResource {
  <at> Post("json")
  public String acceptJson(String value);  // For JSON
  <at> Post("form")
  public Representation accept(Form form);  // For HTML form
  <at> Post()
  public Representation acceptJava(Commitment commitment); // For Java post
}

And...
public class CommitmentsServerResource extends WadlServerResource implements CommitmentsResource {
<at> Post
public Representation acceptJava(Commitment commitment) {
}
<at> Override
public String acceptJson(String value) {
}
<at> Override
// This is the code that actually handles posts that come from forms and http posts
public Representation accept(Form form) {
}
I had the thought that acceptJava was the one being called since it was the only one with the <at> Post annotation.  I changed the <at> Override annotations to <at> Post.  And then the Javascript post was handled by the acceptJson method (which I then fleshed out and changed to return a Represenation).

Everything would be perfect at this point, except for the "strangeness".  Now when I run the test through tcpmon, I get a 415 error there.  The call does make it to the server, since I get an error in the console along the lines of:
Feb 22, 2012 3:07:33 PM org.restlet.ext.jackson.JacksonRepresentation getObject
WARNING: Unable to parse the object with Jackson.
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of org.restlet.data.Form out of START_OBJECT token
 at [Source: org.restlet.engine.io.UnclosableInputStream <at> 41c7d56b; line: 1, column: 1]
 at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
  .....

And then to try and break my "non-tcpmon" client, I changed the ordering of the <at> Post methods, and that did indeed break things as you had predicted.

Thanks again!!
RB

On Wed, Feb 22, 2012 at 1:07 AM, Thierry Templier [via Restlet Discuss] <[hidden email]> wrote:
Hello Richard,

Regarding the post HTTP method and the annotated methods server
resources, I updated the header management in the JavaScript edition.
The routing to such methods is based on the Content-Type header. I
committed all my updates in GitHub, so feel free to make some tests and
give me a feedback.

Be aware that there is a bug in Restlet 2.1 regarding the routing to the
right methods. If a media isn't specified for the first method, this
method will be used and it's not correct...

<at> Put
(...)

<at> Put("json")
(...)

It works with the following:

<at> Put("json")
(...)

<at> Put
(...)

This problem is about to be fixed in the Java version of Restlet.

Thierry

> Thanks again for your help.  I downloaded tcpmon and made the
> suggested changes to my Java client.  I then did a post through Java
> and below are the Request and the Response.
>
> Request....
> POST /commitments/ HTTP/1.1
> Date: Wed, 15 Feb 2012 22:19:58 GMT
> Content-Length: 109
> Content-Type: application/json; charset=UTF-8
> Accept: */*
> Host: localhost:8880
> User-Agent: Restlet-Framework/2.1rc2
> Cache-Control: no-cache
> Pragma: no-cache
> Connection: keep-alive
>
> {"id":0,"title":"Added through post - Java client","description":"This
> is a description of post Java client"}
>
> Response...
> HTTP/1.1 200 OK
> Content-Type: application/json; charset=UTF-8
> Date: Wed, 15 Feb 2012 22:19:59 GMT
> Accept-Ranges: bytes
> Server: Restlet-Framework/2.1rc2
> Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
> Content-Length: 1
>
> 4
>
> Then I moved to the Javascript side.  I didn't install Firebug, but
> instead I just changed the ClientResource creation from:
>   var clientResource = new ClientResource("/commitments/");  /
> To:
>   var clientResource = new
> ClientResource("http://localhost:8880/commitments/");
> where TCPmon was running on 8880 and forwarding to 8888, which is
> where my server was listening.
>
> Below are the Request and Response - and they are definitely different
> than the Java version...
>
> Request...
> OPTIONS /commitments/ HTTP/1.1
> Host: localhost:8880
> Connection: keep-alive
> Access-Control-Request-Method: POST
> Origin: http://localhost:8888
> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11
> (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11
> Access-Control-Request-Headers: Origin, Content-Type, accept
> Accept: */*
> Referer: http://localhost:8888/oldTest.html
> Accept-Encoding: gzip,deflate,sdch
> Accept-Language: en-US,en;q=0.8
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
>
> Response...
> HTTP/1.1 200 OK
> Content-Type: application/vnd.sun.wadl+xml; charset=UTF-8
> Date: Wed, 15 Feb 2012 22:22:22 GMT
> Accept-Ranges: bytes
> Allow: POST, GET
> Server: Restlet-Framework/2.1rc2
> Transfer-Encoding: chunked
>
> 5D2
> <?xml version="1.0" standalone="yes"?>
> <?xml-stylesheet type="text/xsl" href="wadl2html.xslt"?>
> <application xmlns="http://wadl.dev.java.net/2009/02">
> <doc title="Commitments resource"/>
> <representation id="commitment" mediaType="text/plain">
> <doc title="Commitment">Simple string containing the commitment ID</doc>
> </representation>
> <resources>
> <resource path="commitments/">
> <doc title="Commitments resource">The resource that contains the list
> of commitments in the system</doc>
> <method name="GET">
> <response>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/></response>
> </method>
> <method name="POST">
> <request>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/></request>
> <response>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/>
> <representation href="#commitment"/></response>
> </method>
> </resource>
> </resources>
> </application>
>
> One small typo on the
> http://templth.wordpress.com/2011/05/17/activating-tracing-mode-in-restlet/ 
> article, in the ClientResource section the line:
> Context context = clientResource.getContext();
> should be
> context = clientResource.getContext();
> (but this is minor - the ease of getting the trace using Restlet
> tracing was awesome).
>
> Thanks again for all your assistance!  (And my apologies in advance if
> the problem turns out to be some silly mistake in my code - always a
> real possibility).
>
> RB
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2925370


If you reply to this email, your message will be added to the discussion below:
http://restlet-discuss.1400322.n2.nabble.com/Post-problems-when-using-Restlet-Javascript-Edition-tp7270413p7307702.html
To unsubscribe from Post problems when using Restlet Javascript Edition..., click here.
NAML


View this message in context: Re: Post problems when using Restlet Javascript Edition...
Sent from the Restlet Discuss mailing list archive at Nabble.com.
Thierry Templier | 23 Feb 09:59

Re: Post problems when using Restlet Javascript Edition...

Hello Richard,

I answer in the message content.
Thierry:

Thanks so much for your help.  The short version is that the latest Restlet JS code (plus one change in my code) fixes my problem with post().  There is one "strangeness" that I will describe below, but it isn't a big problem for me at this point, but I will describe it below in case you think it matters.  Again, thank you!!  And, please let me know if there is any testing that I can do for you.
You're welcome! Thanks very much for your proposal!
Details...
I installed the new scripts.  Only part that confused me was that I initially took restlet-browser.js from:
* modules\org.restlet.js\src\dist\restlet-browser.js
But that was the wrong file, I had to use:
* tests\org.restlet.js.tests\src\browser\static\restlet\restlet-browser.js
if that is what was intended, all is fine.
The restlet-browser.js in the modules/org.restlet.js/src/dist folder is the assembly file that selects which files to include in the Restlet JS edition for browser. After having run Ant with build.browser task, the js file for the edition can be found in the modules/org.restlet.js/target/browser directory.
Once I put in the right restlet-browser.js, I ran my test and got a 415 error.  So I ran the test through tcpmon - and when going through tcpmon - it worked!  But the mystery was that when going through tcpmon, the server side method "acceptJava()" was being called, not "acceptJson()".  I changed the ordering as per your email, but that still didn't fix my problem (but I did discover that the re-ordering is indeed necessary, but that is getting ahead of the story).
Do you know if tcpmon updates the request by adding or removing some HTTP headers?

At this point I had:
public interface CommitmentsResource {
  <at> Post("json")
  public String acceptJson(String value);  // For JSON
  <at> Post("form")
  public Representation accept(Form form);  // For HTML form
  <at> Post()
  public Representation acceptJava(Commitment commitment); // For Java post
}

And...
public class CommitmentsServerResource extends WadlServerResource implements CommitmentsResource {
<at> Post
public Representation acceptJava(Commitment commitment) {
}
<at> Override
public String acceptJson(String value) {
}
<at> Override
// This is the code that actually handles posts that come from forms and http posts
public Representation accept(Form form) {
}
I had the thought that acceptJava was the one being called since it was the only one with the <at> Post annotation.  I changed the <at> Override annotations to <at> Post.  And then the Javascript post was handled by the acceptJson method (which I then fleshed out and changed to return a Represenation).

Everything would be perfect at this point, except for the "strangeness".  Now when I run the test through tcpmon, I get a 415 error there.  The call does make it to the server, since I get an error in the console along the lines of:
Feb 22, 2012 3:07:33 PM org.restlet.ext.jackson.JacksonRepresentation getObject
WARNING: Unable to parse the object with Jackson.
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of org.restlet.data.Form out of START_OBJECT token
 at [Source: org.restlet.engine.io.UnclosableInputStream <at> 41c7d56b; line: 1, column: 1]
 at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
  .....

And then to try and break my "non-tcpmon" client, I changed the ordering of the <at> Post methods, and that did indeed break things as you had predicted.
I discussed this issue with Restlet team and the problem comes from the Jackson extension. In fact, there is a problem when computing scores to route to the right method. They're working on this issue...

Thanks again!!
RB
Thierry
Richard Berger | 24 Feb 00:11

Re: Post problems when using Restlet Javascript Edition...

Quick update - I put in explicit media types for the <at> Post() annotations on my implementing classes, e.g.:

<at> Post("json")
public Representation acceptJson(String jsonString) {

And that has fixed the problem both when going through tcpmon and without tcpmon involved.  I wasn't able to figure out if tcpmon changes the headers.

All is good now - thanks again for your help!!
RB


On Thu, Feb 23, 2012 at 1:00 AM, Thierry Templier [via Restlet Discuss] <[hidden email]> wrote:
Hello Richard,

I answer in the message content.
Thierry:

Thanks so much for your help.  The short version is that the latest Restlet JS code (plus one change in my code) fixes my problem with post().  There is one "strangeness" that I will describe below, but it isn't a big problem for me at this point, but I will describe it below in case you think it matters.  Again, thank you!!  And, please let me know if there is any testing that I can do for you.
You're welcome! Thanks very much for your proposal!
Details...
I installed the new scripts.  Only part that confused me was that I initially took restlet-browser.js from:
* modules\org.restlet.js\src\dist\restlet-browser.js
But that was the wrong file, I had to use:
* tests\org.restlet.js.tests\src\browser\static\restlet\restlet-browser.js
if that is what was intended, all is fine.
The restlet-browser.js in the modules/org.restlet.js/src/dist folder is the assembly file that selects which files to include in the Restlet JS edition for browser. After having run Ant with build.browser task, the js file for the edition can be found in the modules/org.restlet.js/target/browser directory.
Once I put in the right restlet-browser.js, I ran my test and got a 415 error.  So I ran the test through tcpmon - and when going through tcpmon - it worked!  But the mystery was that when going through tcpmon, the server side method "acceptJava()" was being called, not "acceptJson()".  I changed the ordering as per your email, but that still didn't fix my problem (but I did discover that the re-ordering is indeed necessary, but that is getting ahead of the story).
Do you know if tcpmon updates the request by adding or removing some HTTP headers?

At this point I had:
public interface CommitmentsResource {
  <at> Post("json")
  public String acceptJson(String value);  // For JSON
  <at> Post("form")
  public Representation accept(Form form);  // For HTML form
  <at> Post()
  public Representation acceptJava(Commitment commitment); // For Java post
}

And...
public class CommitmentsServerResource extends WadlServerResource implements CommitmentsResource {
<at> Post
public Representation acceptJava(Commitment commitment) {
}
<at> Override
public String acceptJson(String value) {
}
<at> Override
// This is the code that actually handles posts that come from forms and http posts
public Representation accept(Form form) {
}
I had the thought that acceptJava was the one being called since it was the only one with the <at> Post annotation.  I changed the <at> Override annotations to <at> Post.  And then the Javascript post was handled by the acceptJson method (which I then fleshed out and changed to return a Represenation).

Everything would be perfect at this point, except for the "strangeness".  Now when I run the test through tcpmon, I get a 415 error there.  The call does make it to the server, since I get an error in the console along the lines of:
Feb 22, 2012 3:07:33 PM org.restlet.ext.jackson.JacksonRepresentation getObject
WARNING: Unable to parse the object with Jackson.
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of org.restlet.data.Form out of START_OBJECT token
 at [Source: org.restlet.engine.io.UnclosableInputStream <at> 41c7d56b; line: 1, column: 1]
 at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
  .....

And then to try and break my "non-tcpmon" client, I changed the ordering of the <at> Post methods, and that did indeed break things as you had predicted.
I discussed this issue with Restlet team and the problem comes from the Jackson extension. In fact, there is a problem when computing scores to route to the right method. They're working on this issue...

Thanks again!!
RB
Thierry


If you reply to this email, your message will be added to the discussion below:
http://restlet-discuss.1400322.n2.nabble.com/Post-problems-when-using-Restlet-Javascript-Edition-tp7270413p7311238.html
To unsubscribe from Post problems when using Restlet Javascript Edition..., click here.
NAML


View this message in context: Re: Post problems when using Restlet Javascript Edition...
Sent from the Restlet Discuss mailing list archive at Nabble.com.

Gmane