File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Passing Java objects between web apps?!?!?! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Passing Java objects between web apps?!?!?!" Watch "Passing Java objects between web apps?!?!?!" New topic
Author

Passing Java objects between web apps?!?!?!

Niraj Patel
Greenhorn

Joined: Sep 01, 2003
Posts: 4
I have several classes(basically just java beans) which implement a common interface class.

A user will populate the bean on one webapp, but may be sent to another web app based on their choices.

When this happens I would like to be able to pass the bean to the other web app so I can populate the second web app with data from the first web app.

Is there a way I can do this using a popular api? I would prefer to pass the bean as a whole instead of as a xml representation, which is converted to a bean instance at the other end.

I was thinking JMS, but it seems overkill for something so simple?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
You could use Java serialization over a TCP connection between the two web apps. That would also work if the two web apps do not run on the same server.


Ping & DNS - updated with new look and Ping home screen widget
Niraj Patel
Greenhorn

Joined: Sep 01, 2003
Posts: 4
Originally posted by Ulf Dittmer:
You could use Java serialization over a TCP connection between the two web apps. That would also work if the two web apps do not run on the same server.


I don't really want to go as low level as TCP, I would rather an API thats passes this along like JMS, but simpler.

The thing is currently we save the bean to xml in the database. We then redirect the user to the next web app and it takes that row out of the database and re-constructs the bean.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12676
    
    5
Instead of serializing to XML and then parsing back to the bean, why not serialize using ObjectOutputStream to a byte[] and storing that in the database. I suspect it will be considerably faster since there will be no character conversions.

Bill


Java Resources at www.wbrogden.com
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Apu,

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.
Nikhil Goel
Ranch Hand

Joined: Jul 11, 2003
Posts: 32
Converting a bean to XML format or object output stream and storing in DB for this is an overkill .
What happens to this XML or object stream once other app has worked on the data . Unneccesary data in DB .

Some effective solutions are :-
1)Write the object stream of the object to be transfered on some socket on the other app and work from there .
2)Open a HTTPURLConnection to any servlet in other app and post the bean to that servlet . Read the bean there from object stream and work .

As you are not comfortable with TCP/Sockets use 2 . Any existing Servlet in other app can be used for this purpose . Just put an in condition to handle this case.

-nikhil
Niraj Patel
Greenhorn

Joined: Sep 01, 2003
Posts: 4
2)Open a HTTPURLConnection to any servlet in other app and post the bean to that servlet . Read the bean there from object stream and work .


Thats the data bit ok, but how would I then redirect them, so the new session they get in the second app has the bean we just posted?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing Java objects between web apps?!?!?!
 
Similar Threads
Struts - Separation of Control and Model
session variables.
Using Beans in my classes... is it possible?
best practice for jpa, using @Entity as a VO?
data reflection using mvc with valueof object pattern