Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sailaja parepalli
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sailaja parepalli
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ThanQ. I will go through them.
--
Sailu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic