I ran into this problem too using Flex. Here's what I did to solve it:
I created a class which extends ApplicationXMLFormatter and overrode the
writeTo method. In that method, I reset the name of the "return"
element to be the class name. Here's my change with a little context:
if (omElement != null) {
* for (Iterator children = omElement.getChildElements();
children.hasNext(); ) {
OMElement child = (OMElement)children.next();
String returnType = null;
for (Iterator it = child.getAllAttributes();
it.hasNext(); ) {
OMAttribute attr = (OMAttribute)it.next();
if ("type".equals(attr.getLocalName())) {
returnType = attr.getAttributeValue();
int dot = returnType.lastIndexOf('.');
if (dot > 0)
returnType = returnType.substring(dot+1);
break;
}
}
if (returnType != null)
child.setLocalName(returnType);
}*
try {
if (preserve) {
omElement.serialize(outputStream, format);
} else {
omElement.serializeAndConsume(outputStream, format);
}
} catch (XMLStreamException e) {
throw AxisFault.makeFault(e);
}
}
Then I added this to my axis2.xml since I only want to do this for Flex:
<messageFormatter contentType="application/flex-xml"
class="com.company.api.webservice.MyApplicationXMLFormatter"/>
I have configured the dynamic response module described at
http://wso2.org/forum/thread/2883 in my services.xml. So now when I do
something like this:
http://localhost:8004/services/community/getFeaturedBlogEntries?response=application/flex-xml
I get something like this:
<ns:getFeaturedBlogEntriesResponse
xmlns:ns="http://service.webservice.api.company.com">
<*BlogEntryList* type="com.company.api.webservice.BlogEntryList">
<blogEntries type="com.company.api.webservice.BlogEntry">
<body>test blog entry</body>
<creationDate>Sep 3, 2008 4:19 PM PDT</creationDate>
...
</blogEntries>
<start>0</start>
<totalItemCount>1</totalItemCount>
</*BlogEntryList*>
</ns:getFeaturedBlogEntriesResponse>
I hope this helps someone else.
Kimberly Nicholls
Chris Hyzer wrote:
Hey,
Im using Axis2 (latest) and all defaults for inputs to Java2WSDL. I
have a simple service, and each operation has a "return" element in
it. e.g.
<xs:element name="addMemberSimpleResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true"
type="ns:WsAddMemberResult"/>
</xs:sequence>
</xs:complexType>
</xs:element>
This means the XML that comes back looks like this:
<soapenv:Body>
<ns:addMemberSimpleResponse xmlns:ns="http://webservices.whatever/xsd">
<ns:return type="whatever.webservices.WsAddMemberResult">
<ns:resultCode
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
I have someone connecting to the web service using flash or flex, and
there is an XML -> object converter, which converts the XML into a
hierarchy of objects and fields. But since "return" is a keyword, it
barfs. So, I was wondering if there is a way (besides hand-editing
the WSDL or using XSLT) to customize java2wsdl to get that element to
be generated as "the_return" or something else besides "return".
Thanks!
Chris
Here is the email from the user:
Notice that the element name on line two of the response is named
"return" (forget about the "ns" namespace for now). This is perfectly
legal XML but "return" is a reserved word in most languages and
attempts to access the element directly cause problems when compiling
the code. e.g.
--- BEGIN EXAMPLE FLASH CODE---
var test : XML = XML("<top><body>hello world</body><return>good
bye</return></top>"); // casts string to xml
debugit.text = test.body;
debugit.text = test.child( "return" );
--- END EXAMPLE FLASH CODE---
All of the above code works fine. Notice that I access the "body"
element directly but accessed the "return" element using a child
method. The compiler complains if I attempt to use the syntax
"test.return" or any variation of it: "test.return.toString()".
Naming an element "return" is valid; I'm suggesting that it is
probably not good practice to use common reserve words as element
names (or attribute names for that matter).
----
------------------------------------------------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try
it now.
<http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ%20>