[SoapRMI] Re:_[SoapRMI]_writing_a_(de)serializer
Aleksander Slominski
aslom_at_cs.indiana.edu
Mon, 02 Dec 2002 10:50:49 -0500
nodep_at_libero.it wrote:
>Hi,
>your code runs wery well thanks! Now I'm beginning to
>understand... ;)
>
hi,
good to hear it.
>Well, now I've another problem: I would to use a package
>called JSX to serialize generic java-object in XML, and
>I've modified my so that the handler takes object and,
>with JSX, it sends XML. The problem araise with deserialization
>because it seems the parser reads the XML generated by JSX
>and it generates this error:
>
>Client executing remote method sayHello on server
>Exception in thread "main" soaprmi.ServerException: SOAP-ENV:Client:
>soaprmi.soa
>p.DeserializeException: expected element content at line 5 and column
>27 seen ..
>
>
>remote exception is: soaprmi.soap.DeserializeException: expected
>element content
> at line 5 and column 27 seen ...<stefano.Mex alias-ID="0">... (parser
>state STA
>RT_TAG)
> at stefano.MexHandler.readObject(MexHandler.java:36)
> at soaprmi.soapenc.SoapEnc.readObject(SoapEnc.java:488)
>
>
>Why doesn't the parser reads the content (that is XML) as
>a simple string?
>
XML is not represented as string but as stream of XML events
>I attach my code so you can to see it.
>Can you help me?
>
i am not familiar with JSX but even if you have String for XML fragment
it will still not work as it will be missing XML namespace prefixes
declarations.
you have to options
1) construct XML with added XML declarations for first start tag
2) use converter/driver that takes XPP2 events and generates SAX2 events
this allows to keep streaming events and converter takes care of
declaring
necessary namespace prefixes
option 1) would require buffering of events into XML tree
(this can be done with XmlPullParserFactory.newNode(pp) and
then adding to node all declared namespaces and converting node
into string using XmlRecorder.setOutput(StringWriter), writeNode(node)
for more details see:
http://www.extreme.indiana.edu/xgws/xsoap/xpp/download/PullParser2/doc/api/)
option 2) is much better if JSX can work with SAX2callbacks,
first make sure to obtain SAX2 driver that is part of XPP2
(currently
http://www.extreme.indiana.edu/xgws/xsoap/xpp/download/PullParser2_1_8.zip)
and then look on src/java/drivers/sax2/ as you can see
org.gjt.xpp.sax2.Driver implements SAX2 XMLReader
and can be easily used directly: new Driver(),
register your content handler setContentHandler
(see SAX2 and JSX documentation for details)
make sure to get all namespaces declarations from parser and
call contentHandler.startPrefixMapping()
(use pp.readNamespacesPrefixes/Uris to get them for each depth
and you must be careful to make sure that correctly namespace
prefix stack is walked from bottom to top)
and then call parseSubTree(XmlPullParser pp)
>PS-How to send literal XML so that to stay compatible
> with other soap engine? (ApacheSoap)
>
>
currently XSOAP does not support literal encoding however it allows to
send and receive any XML (without any deserialzier or serializer)
by using XmlNode as parameter.
take a look on samples/ogsa and in particular Client.java nad how it
uses XmlNode to send any valid XML fragment (string).
thanks,
alek
--
The ancestor of every action is a thought. - Ralph Waldo Emerson