Web Services Marshalling and Unmarshalling

Using Servoy to administrate the content of your website? Discuss all webrelated Servoy topics on this forum!

Web Services Marshalling and Unmarshalling

Postby erikd » Tue Feb 08, 2011 7:53 am

Hi,

I am new to Servoy Web Services. I have just deployed a solution with ws_create method as a web service. I just noticed that when i return an object with sub objects in ws_create method it only returns a truncated xml file and does not continue with the xml response.

1. Should I implement marshalling and unmarshalling of objects through JaxB in this method?
2. Or did I miss out any Servoy's feature that does this automatically?

Thanks!
erikd
 
Posts: 445
Joined: Wed Aug 11, 2010 2:32 am

Re: Web Services Marshalling and Unmarshalling

Postby erikd » Tue Feb 08, 2011 8:45 am

I am just looking for a way to convert Javascript objects to XML data and vice versa. Any input is appreciated.
erikd
 
Posts: 445
Joined: Wed Aug 11, 2010 2:32 am

Re: Web Services Marshalling and Unmarshalling

Postby jgarfield » Tue Feb 08, 2011 6:55 pm

I haven't tried this, but if you run your object thru either

uneval(jsobj)

or

plugins.serialize.toJSON(jsobj)

you should get back a string representation of it, and that should pass through XML fairly cleanly (as long as you don't have any unsupported characters in your object)
Programmer.
adBlocks
http://www.adblocks.com
jgarfield
 
Posts: 223
Joined: Wed Sep 28, 2005 9:02 pm
Location: Boston, US

Re: Web Services Marshalling and Unmarshalling

Postby pbakker » Tue Feb 08, 2011 8:06 pm

The restful webservice plugin should automatically convert the JavaScript object to XML if the content-type of the request is XML.

If you say something goes wrong, please show what is happening.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Web Services Marshalling and Unmarshalling

Postby erikd » Wed Feb 09, 2011 12:44 am

pbakker wrote:The restful webservice plugin should automatically convert the JavaScript object to XML if the content-type of the request is XML.

If you say something goes wrong, please show what is happening.

Paul


Hi Paul, I included the summary of the error in my post. Here are the details:
I have message object with requestobject and other sub objects. When I return these objects in ws_create method, it generates a truncated xml response.
Code: Select all
function ws_create()
{
   var messageObject = new Object("message");
   messageObject.message = "Successfully retrieved";
   messageObject.responseObject = new Object("responseObject");
   messageObject.responseObject.name = "Servoy" ;
   return messageObject;
}


The responseXML is:
Code: Select all
<?xml version="1.0" encoding='UTF-8'?> ""message""
erikd
 
Posts: 445
Joined: Wed Aug 11, 2010 2:32 am

Re: Web Services Marshalling and Unmarshalling

Postby pbakker » Wed Feb 09, 2011 10:54 am

You are using the new Object constructor wrong.

This way your code works as expected:
Code: Select all
function ws_create()
{
   var messageObject = new Object();
   messageObject.message = "Successfully retrieved";
   messageObject.responseObject = new Object();
   messageObject.responseObject.name = "Servoy" ;
   return messageObject;
}


You can also write the same thing even shorter:
Code: Select all
function ws_create()
{
   return {message: "Successfully retrieved", responseObject: {name: "Servoy"}};
}


The way you used the Object constructor creates a new String object: https://developer.mozilla.org/en/JavaSc ... t#Examples

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Web Services Marshalling and Unmarshalling

Postby erikd » Thu Feb 10, 2011 6:58 am

Thanks very much. I will rewrite my code and test it.
erikd
 
Posts: 445
Joined: Wed Aug 11, 2010 2:32 am

Re: Web Services Marshalling and Unmarshalling

Postby erikd » Mon Feb 14, 2011 7:25 am

Thanks, Paul. It worked.

I have another question on the client-side application regarding unmarshalling. I try to call my web service host through the following codes:
Code: Select all
   plugins.http.createHttpClient('mybrowser');
   var poster = plugins.http.getPoster('http://x.x.x.x:1234/servoy-service/rest_ws/something_ws/ws_getsomethingdetails');
   var xmlData = "<xmldata></xmldata>";
   var didAddParam = poster.addParameter(null,xmlData);
   var httpCode = poster.doPost(); //httpCode 200 is ok
   var pageData = poster.getPageData();
   plugins.http.deleteHttpClient('mybrowser');

How do I convert the pageData from xml to javascript object? Does Servoy have automatic conversion?

Edit:
Is this how we call web service in Servoy?
erikd
 
Posts: 445
Joined: Wed Aug 11, 2010 2:32 am

Re: Web Services Marshalling and Unmarshalling

Postby rgansevles » Mon Feb 14, 2011 10:23 am

Erik,

The plugin handles the formatting to/from http responses and body contents.
The currently supported content types are xml and json.
For both formats, the plugin handles the conversion, the js methods in your solution receive/return js objects.

You can control which content type to be used in the Content-Type and Accept http headers of your request.
By default the content type is derived from the content and the default response content type is the same as the request content type or json for GET.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Web Services Marshalling and Unmarshalling

Postby erikd » Tue Feb 15, 2011 12:59 am

rgansevles wrote:The plugin handles the formatting to/from http responses and body contents.

Are you referring to http plugin?

rgansevles wrote:The currently supported content types are xml and json.

Currently, I am using XML.

rgansevles wrote:For both formats, the plugin handles the conversion, the js methods in your solution receive/return js objects.

The variable, pageDate, from "var pageData = poster.getPageData();" returns an xml data and not js objects. Should this method be returning js object?

The source code in my previous post is all I execute to call my web service. Did I miss out an API call?
erikd
 
Posts: 445
Joined: Wed Aug 11, 2010 2:32 am

Re: Web Services Marshalling and Unmarshalling

Postby rgansevles » Tue Feb 15, 2011 9:26 am

Erik,

I am talking about the server-side, for which you can use the rest_ws plugin.
In this plugin you deal with js objects, on the client side you deal with json or xml.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL


Return to Web Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron