wood burning stoves 2.0*
The moose likes Java in General and the fly likes Transfering 3rd party (unserialized) objects through web server. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Transfering 3rd party (unserialized) objects through web server." Watch "Transfering 3rd party (unserialized) objects through web server." New topic
Author

Transfering 3rd party (unserialized) objects through web server.

A Thakur
Greenhorn

Joined: Apr 06, 2010
Posts: 20
I have client-server application where client calls server through web server and servlets. The servlet invoke methods deployed on web server and they query SQL database to retrieve the results. Results are populated in a instance of serialized class (DAO.java) and all the instance of dao.java are added to the List and transferred back to client. No issues.

Beside that I have some additional processing to be done along with SQL query. For such processing, I am using 3rd party software and it returns the instance of 3rd part API. Now I also need to transfer the 3rd party instance, which apparently is not serialized, as well along with list.

I am getting the error that the instance I am sending over the web server is not serialized. I tried to add 3rd party instance to instance of dao.java which is serialized but it does not work either.

Is there any workaround I can do to transfer this un-serialized object.

I will really appreciate any suggestions.

Thanks a bunch.


SCJP 5.0
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

Art Thak wrote:I tried to add 3rd party instance to instance of dao.java which is serialized but it does not work either.


if you add a non-serializable member object to a serializable object, it won't work. The member object has to be serializable as well (or declared transient).

I think you need to extend that 3rd party class and implement serializable in the subclass. then, you need to write your own implementations of the readObject and writeObject methods.



You are working with someone else's object. If you use this way to serialize it and then it changes, it could cause problems.
Also, this only works if the superclass ( 3rdPartyObject ) has a no-arg constructor (as your custom code will have to call it to deserialize)
the solution to this, then, is to use Externalizable interface.
This is discussed previously on javaranch:
http://www.coderanch.com/t/475650/Programmer-Certification-SCJP/certification/serializing-when-subclass-implements-Serializable
A Thakur
Greenhorn

Joined: Apr 06, 2010
Posts: 20
Tim: Thanks for suggestion and url.

My problem is little complicated, Here's my problem:

3rd party class: (unserialized)





Subclass:



Another Class: Gateway.java




I want to capture all the properties of QueryResult class, plus additional properties for SubclassDAO set by Gateway.java and pass to the client.

I understand above readExtrenal() and writeExternal() method implementation is not correct here.

Few things I tried:

- Client is able to get projectName but not the queryResult object. out.writeObject(queryResult); in subclass implementation throws error compianing the queryResult is not serialized.
- I cannot do SubclassDAO dao = (SubClassDAO)result; in Gateway,java as this throws me type cast exception.

Please suggest. How can I make this work by proper implementation of readExternal or writeExternal


How can I do that.


A Thakur
Greenhorn

Joined: Apr 06, 2010
Posts: 20
One way is to read all properties of QueryResult in Gateway.java and assign it to SubClassDao instance and then send it client.

I should mention there is a strict need transfer the QueryResult object to the client. Reading all the properties in Gateway.java (server side) is very time consuming. Reason I want to transfer it to client, so then client receives response from server it can run background thread to get all properties of QueryResult and use it where necessary. So that server side resources can be saved.

Please help.

Thanks a million.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

These restrictions make it not likely you can do this. You will never be able to send QueryResult itself to the server in a java.io stream because it isn't serializable.
You also can't, per your restrictions, read the data out of QueryResult into another class and send that.

I may have led you astray with externalizable because I didn't realize the requirement to actually send QueryResult over the stream.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transfering 3rd party (unserialized) objects through web server.
 
Similar Threads
transfer unserilaized objects as SOAP response
Facade design pattern in web services
Get java.util.List from webservice
open socket to unix (port 23) and display a shell script result in web page by applet
Transfer Excel Sheet information to database