Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stuck using AJAX & WebService

 
Subhadip Chatterjee
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jez Nicholson
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic