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"}
  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);
});

The error, as seen in the Javascript console, is:
ReferenceError at restlet-browser.js: 3175
	arguments: Array[1]
	0: "EncodingWriter"
	length: 1
	__proto__: Array[0]
	get message: function getter() { [native code] }
	get stack: function getter() { [native code] }
	set message: function setter() { [native code] }
	set stack: function setter() { [native code] }
	type: "not_defined"
	__proto__: Error

On the server side, I have methods to handle the different clients:
  @Post()
  public String add(Commitment commitment); // For Java post
  @Post("json")
  public String acceptJson(String value);  // For JSON
  @Post("form")
  public Representation accept(Form form);  // For HTML form

But the Javascript client does not appear to be even making the call to the
server.  

Has anyone used the Restlet Edition for Javascript to do a post?  

Thanks so much!
RB 

--
View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Post-problems-when-using-Restlet-Javascript-Edition-tp7270413p7270413.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Gmane