*
The moose likes EJB and other Java EE Technologies and the fly likes Serializing XML Dom Document Object and returning it from an EJB method... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Serializing XML Dom Document Object and returning it from an EJB method..." Watch "Serializing XML Dom Document Object and returning it from an EJB method..." New topic
Author

Serializing XML Dom Document Object and returning it from an EJB method...

sailaja parepalli
Ranch Hand

Joined: Jan 23, 2003
Posts: 33
Hi,
Is it possible to serialize the XML Document object and return it from a session bean method?
If it is not possible, then how to send output stream (to some servlet running on some other application server) from ejb session bean?
Can anybody help me with this?
Thanks.
Sailu


Sailu<br />IBM 486, SCJP, Brainbench CJP
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Actually neither of these is possible since neither Input Streams nor DOM Elements are serializable. Your only option is to send a string containing the XML text.
However, let me advise you that even this is a LOUSY idea. You should parse your XML into real value objects (DTOs) in the Servlet client and then have a more object-oriented interface into your EJB's. IMHO EJBs should not have to concern themselves with XML.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
sailaja parepalli
Ranch Hand

Joined: Jan 23, 2003
Posts: 33
Thanks for the response Kyle.
I am using the xerces API and there is one class named 'XMLSerializer' in the package org.apache.xml.serialize that allows the serialization of Document object. That is what they say, but I can't see the phrase 'implements java.io.Serializable' phrase anywhere in the Document or its super interfaces.
When I try to serialize the Document object with the XMLSerializer and send the Document object from EJB it gives the error 'org.w3c.dom.Document' not found while generating the deployment code itself. I think it is not being serialized.
If it is being serialized do you know how to make this org.w3c.dom.Document available to the runtime environment? I am adding all the required jar files to the Java Build Path. It doesn't give any error if I just use the xml api in the session bean methods to display some xml (not for returning from the method).
Thanks again.
Sailu
sailaja parepalli
Ranch Hand

Joined: Jan 23, 2003
Posts: 33
I forgot to mention one more thing in the above reply...
I am trying to transfer xml Document object (that has been created in ejb from the database result set data) from ejb to servlet but not from servlet to ejb.
Sailu
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
The XML Serializer serializes (translates) objects into XML. It doesn't make documetns Serializable. I stand by my previous statement -- the only way to do this with XML is to return this to your servlet as a String, and not as a document. However, that's not the best approach -- the best approach is to build value objects (Data Transfer Objects) and return those instead.
Kyle
[ January 07, 2004: Message edited by: Kyle Brown ]
sailaja parepalli
Ranch Hand

Joined: Jan 23, 2003
Posts: 33
Yes. You're right. XMLSerializer doesn't serialize the Document object for transfering out of RMI system. But it serializes the Document object content using an Output format to make it available for an output stream or writer.
I never worked with DTOs before. Can you pls give me some urls/samples or related info to explore. I could not find much on the net. Is it the 'java.awt.datatransfer' package that can be used to create DTOs?
ThanQ.
Sailu
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Read the Sun J2EE blueprints and the book Core J2EE Patterns to learn about DTO's and better architectures for EJB's.
Kyle
sailaja parepalli
Ranch Hand

Joined: Jan 23, 2003
Posts: 33
ThanQ. I will go through them.
--
Sailu
 
wood burning stoves
 
subject: Serializing XML Dom Document Object and returning it from an EJB method...