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.
My problem is little complicated, Here's my problem:
3rd party class: (unserialized)
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.
Joined: Apr 06, 2010
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.
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.