wood burning stoves 2.0*
The moose likes Web Services and the fly likes Can't return an Element in an RPC (despite having read the documentation) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Can Watch "Can New topic
Author

Can't return an Element in an RPC (despite having read the documentation)

Chris Garrison
Ranch Hand

Joined: Jun 13, 2002
Posts: 44
Let me thank you for your help in advance.
I'm trying to call an RPC which sends a bean and returns an Element. I'm writing both client and server.
Let me say that I am able to return a String in this scenario just fine.
Per instructions on the Apache SOAP FAQ site, I've made the following code changes (so I will be able to return an Element):
Call call = new Call();
call.setTargetObjectURI("urn:XXXXXXX");
call.setMethodName("buildXxxxx");
//call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// the above is for returning Strings
// use this encoding below to be able to return an Element
call.setEncodingStyleURI( Constants.NS_URI_LITERAL_XML );
when I invoke, I get the following:
Caught SOAPException (SOAP-ENV:Client): I only know how to serialize an 'org.w3c.dom.Element&apos
What am I missing? Is there something in the deployment descriptor I'm supposed to change? Is there something else I need to do in the deployment descriptor.
Oh yeah, and why do I appear to have a "DeployedServices.ds" instead of a "DeploymentDescriptor.xml".
Thanks again. Sometimes I marvel at what I don't know and/or understand.
[ August 05, 2003: Message edited by: Chris Garrison11 ]

May the force be with you, always.
Chris Garrison
Ranch Hand

Joined: Jun 13, 2002
Posts: 44
Or - if I remove the code I inserted (per Apache SOAP FAQ - http://ws.apache.org/soap/faq/index.html -) and leave the section like this (as it was when it was returning a String correctly):

Call call = new Call();
call.setTargetObjectURI("urn:XXXXXXX");
call.setMethodName("buildXxxxxx");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// use this encoding below to receive an Element
// call.setEncodingStyleURI( Constants.NS_URI_LITERAL_XML );
I get the following error:
Generated Fault:
Fault Code = SOAP-ENV:Server
Fault String = java.lang.IllegalArgumentException: No serializer found to serialize a org.w3c.dom.Element' using encoding style 'http://schemas/.xmlsoap.org/soap/encoding/'.
[ August 05, 2003: Message edited by: Chris Garrison11 ]
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
Hi Chris
In your first example, you specify you are going to use RPC_LITERAL as communication model.
So Apache SOAP try to serialize your bean using an "Element serializer" before sending the request. This explains the error message you obtain.
In you second example, you use RPC encoded. So the Bean you sent is serialized using a "bean serializer" (even if I don't see where you specify the parameter in your code ), and is received on the server side.
When the server tries to serialize the return parameter, it needs a serializer, and a specific one because it has to serialize an org.w3c.dom.Element. So you will have to register a serializer on the server side for the "Element"
I'm not sutre to fully understand your problem so I hope I'm not totally way out here...


/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="http://www.epfwiki.net/wikis/openup/" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
Chris Garrison
Ranch Hand

Joined: Jun 13, 2002
Posts: 44
First of all - a thousand thanks for replying, Jean-Louis. You can probably skip to the comments on the 3rd paragraph (at the bottom in bold). I don't want to waste any more of your time. I included the other info just in case.
First paragraph. Yes, I agree it doesn't make sense, but that is what the Apache SOAP FAQ states. See below.
From the Apache SOAP FAQ:

How do you return a DOM Element from an RPC Call?
The encoding style of a Call return is determined by the encoding style of the Request. DOM Elements use Literal XML encoding. For example, if a service accepts one String Parameter and returns an Element, just set the encoding style for the call to "http://xml.apache.org/xml-soap/literalxml" and the encoding style for the parameter to "http://schemas.xmlsoap.org/soap/encoding". Thus, part of your client code would look like:
...
Call call = new Call();
call.setTargetObjectURI("urn:someservice");
call.setMethodName("callmethod");
call.setEncodingStyleURI( Constants.NS_URI_LITERAL_XML );
String strparam = "joebob";
Vector params = new Vector();
params.addElement( new Parameter( "strparam", String.class,
strparam, Constants.NS_URI_SOAP_ENC ) );

It doesn't make any sense to me. Let's forget this for the time being.
-------------------------
Second paragraph: Yes, I am sending a bean. Sorry - I left that out of my code snip. Sending the bean works fine. I have had no trouble with that. I am able to send a bean and return strings without any problem which brings us to ...
-------------------------
Third Paragraph comments(now we're getting somewhere)
I think the answer lies in "you need to register a serializer on the server side for the Element." I don't how one does this. Also, if I need to "register" a serializer, should I assume I also need to "create" the serializer? Is this an XML setting or is it code I should include in the method before returning my Element? I'm kind of lost here.
Here's some of the code from the server:

... server does it's thing (runs a query) and produces results
Document doc = (Document)q.asXML();
// q.asXML() returns my results "q" as a Document
Element root = doc.getDocumentElement();
return root;
Am I supposed to be doing the "Call" and "setEncoding" etc in my service, too (like I do in the client)?

Thanks again for your assistance.
[ August 06, 2003: Message edited by: Chris Garrison11 ]
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
Quick answer here 'cause I do not have a lot af time
I think I fully agree with SOAP FAQ.
To send an OBJECT and receive an ELEMENT, you have to specify you send an OBEJECT :
Vector params = new Vector();
params.addElement( new Parameter( "muObject", MyClass.class,
objparam, Constants.NS_URI_SOAP_ENC ) );
and you have to specify the encoding style is RPC_LITERAL to be able to serialize an org.w3c.dom.Element :
call.setEncodingStyleURI( Constants.NS_URI_LITERAL_XML );
In your code, it sounds like you've tried 2 encoding styles, but never used them both.
You have to specify the parameter use NS_URI_SOAP_ENC
AND
the call is NS_URI_LITERAL_XML

HTH
Chris Garrison
Ranch Hand

Joined: Jun 13, 2002
Posts: 44
Thanks again for your help. I'll report with my findings.
So far so good.
Best Regards
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can't return an Element in an RPC (despite having read the documentation)