This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Stuck using AJAX & WebService Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Stuck using AJAX & WebService" Watch "Stuck using AJAX & WebService" New topic
Author

Stuck using AJAX & WebService

Subhadip Chatterjee
Ranch Hand

Joined: Dec 12, 2006
Posts: 93
Hi,
This is my first post here, in this forum. I would like to know more about how to call a webservice by passing a serializable Java object/VO(as paramater), using the XMLHttpRequest?


Refreshing life every moment...
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Subhadip Chatterjee:
Hi,
This is my first post here, in this forum. I would like to know more about how to call a webservice by passing a serializable Java object/VO(as paramater), using the XMLHttpRequest?


How would you pass java objects / VO using XMLHttpRequest ?
XMLHttpRequest objects acts as a http client and sends http reuqest to the server , so how can you pass objects using this to the server.
And for server to server communication you probably would not need to use AJAX.


Rahul Bhattacharjee
LinkedIn - Blog
Jez Nicholson
Ranch Hand

Joined: Oct 01, 2002
Posts: 39
Seemed like a reasonable enough question to me. If you are using jsp, velocity or groovy on the front-end and a web service on the back-end to supply the data you would want to send/receive data via Ajax as objects. This is what things like JSON are for isn't it? To do the serialization/deserialization of the XMLHttpRequest data for you?
Subhadip Chatterjee
Ranch Hand

Joined: Dec 12, 2006
Posts: 93
Hi Jez,
yeah your sounds quite appropriate...'cauz right now, i am trying to devlop a module in my application, where i am already using Webservices in SOA style. But from the front-end i want to make some pages which are gonna send async request to webservices & fetch the response. But,most of my webservices are written in POJOs, taking a serializable java bean(VO) as input. So, to map & invoke those webservices, i need to pass a serializable object of the same structure from client-side script. Do ye have any stuff or URL which you have come across, like this???if yes, do pass it on to me...
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
A Java Object != A JavaScript Object.

It is like saying an apple is an Orange. When the XMLHttpRequest returns data it returns either plain text or XML. If your webservice accepted XML/SOAP/PLAIN TEXT, you would not have an issue.

It is better to use a legacy webservice from the server. Does it have validation?

Eric
Subhadip Chatterjee
Ranch Hand

Joined: Dec 12, 2006
Posts: 93
Hi Eric,
i understand your point...but lemme explain a bit more...I have designed two layers in my application. one is Presentation Layer, the other is Service layer.The presentation layer is done using Struts framework. Plus i have couple of core classes to create SOAP reaquest, out of my HttpRequest paramaters. with this soap request, i am calling the webservices...now, from the Service layer, each webservice either accepts a couple of primitives or String param Or, it accepts a serializable bean object (Value Objects; bean with getter-setter only)...The response is again captured in Presentation layer (precisely, in "Action" classes)and parsed through XSLs to render the UI.
I hope, i am clear now. So, can ye suggest me in this framework of the application, how can i build some AJAXified UIs? Precisely, how to call my existing webservices using XMLHttpRequest?
Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
Is it a feasibile solution to add a serialization/deserialization layer at your server side using castor/xstream etc. If it is, then you can expose the java bean methods that process XML as in/out as webservice methods. In those methods you serialize/deserialize the XML to objects and process them.
So that, the javascript just needs to create an XML request and pass to the AJAX object, and gets an XML response back.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
"samethemoose",

In order to win the book we have some rules. The first rule is to make sure you have a proper screen name.

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

Unfortunately, your screen name does not seem to conform with this policy. Please take a moment to change it.

Thanks,
Eric
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
One more thing , you can have something like below to meet your requirement.

As mentioned by Eric Pascarello
When the XMLHttpRequest returns data it returns either plain text or XML.


So from the client side ,if you want to send serialized java objects then again you have to have your own way of formatting the VO to xml (xml's are also now heavily used as VO's in many projects) and then send to your web services.
Subhadip Chatterjee
Ranch Hand

Joined: Dec 12, 2006
Posts: 93
Hi guys,
That's quite a insight you all have posted for my requirement.But i want some thing more, like a code sample or any URL to see code sample. So, mostly i am interested in seeing the code-sample, anyway.
I hope, you are gonna feed me something (fingers crossed!!!).
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Originally posted by samthemoose:
Hi guys,
That's quite a insight you all have posted for my requirement.But i want some thing more, like a code sample or any URL to see code sample. So, mostly i am interested in seeing the code-sample, anyway.
I hope, you are gonna feed me something (fingers crossed!!!).



Maybe when you change your name as you been told multiple times...

Eric
 
GeeCON Prague 2014
 
subject: Stuck using AJAX & WebService