You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Daniel Kulp <dk...@apache.org> on 2007/11/30 22:37:54 UTC

Re: WrapperHelper not inserting data into array response MessageWrapper

Nathan,

This has already been fixed on trunk and on the 2.0.4-SNAPSHOT branch.

That said, there is a workaround:  if you add the asm (versions 2.x or 
3.x) jar to the classpath, the WrapperHelper will compile a custom class 
to handle the wrappers and that version doesn't suffer from the bug.

Dan


On Friday 30 November 2007, Silberman, Nathan wrote:
> I have an operation that is returning a messagePart whose element is
> an array (wsdl listed below). I have observed that the wsdl2java
> operation created the following wrapper object (comments removed):
>
> import java.util.ArrayList;
> import java.util.List;
> import javax.xml.bind.annotation.XmlAccessType;
> import javax.xml.bind.annotation.XmlAccessorType;
> import javax.xml.bind.annotation.XmlElement;
> import javax.xml.bind.annotation.XmlRootElement;
> import javax.xml.bind.annotation.XmlType;
>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
>     "getAllUsersReturn"
> })
> @XmlRootElement(name = "getAllUsersResponse")
> public class GetAllUsersResponse {
>
>     @XmlElement(namespace = "https://test.com", required = true)
>     protected List<User> getAllUsersReturn;
>
>     public List<User> getGetAllUsersReturn() {
>         if (getAllUsersReturn == null) {
>             getAllUsersReturn = new ArrayList<User>();
>         }
>         return this.getAllUsersReturn;
>     }
> }
>
>
> The problem I am observing is that even though I can see my actual
> service method implementation returning multiple objects, none are
> actually added to the SOAP message. Debugging the application has led
> me to find the following code block inside the WrapperHelper class:
>
> public Object createWrapperObject(List<?> lst)
>             throws Fault {
>
>             try {
>                 Object ret = wrapperType.newInstance();
>
>                 for (int x = 0; x < setMethods.length; x++) {
>                     if (setMethods[x] == null && fields[x] == null) {
>                         continue;
>                     }
>                     Object o = lst.get(x);
>                     if (jaxbObjectMethods[x] != null) {
>                         o = jaxbObjectMethods[x].invoke(objectFactory,
> o);
>                     }
>                     if (o instanceof List) {
>                         List<Object> col =
> CastUtils.cast((List)getMethods[x].invoke(ret));
>                         if (col == null) {
>                             //broken generated java wrappers
>                             if (setMethods[x] != null) {
>                                 setMethods[x].invoke(ret, o);
>                             } else {
>                                 fields[x].set(ret, lst.get(x));
>                             }
>                         } else {
>                             List<Object> olst =
> CastUtils.cast((List)o); col.addAll(olst);
>                         }
>                     } else if (setMethods[x] != null) {
>                         setMethods[x].invoke(ret, o);
>                     } else if (fields[x] != null) {
>                         fields[x].set(ret, lst.get(x));
>                     }
>                 }
>                 return ret;
>             } catch (Exception ex) {
>                 throw new Fault(ex);
>             }
>         }
>
> As one can see, WrapperHelper uses set*** methods to add data to the
> wrapper java classes which are in turn marshalled into SOAP. However,
> since the getAllUsersResponse wrapper has no set*** method, only a get
> message generated from wsdl2java, nothing is returned. Is this an
> issue or due to misconfiguration on my part?
>
> my wsdl:
>
>
>  ...
>
>       <element name="getAllUsersResponse">
>         <complexType>
>           <sequence>
>             <element name="getAllUsersReturn" maxOccurs="unbounded"
> type="impl:User"/>
>           </sequence>
>         </complexType>
>       </element>
>
>  ...
>
>   <wsdl:message name="getAllUsersResponse">
>     <wsdl:part element="impl:getAllUsersResponse" name="parameters"/>
>   </wsdl:message>
>
>  ...
>
>     <wsdl:operation name="getAllUsers">
>       <wsdl:input message="impl:getAllUsersRequest"
> name="getAllUsersRequest"/>
>       <wsdl:output message="impl:getAllUsersResponse"
> name="getAllUsersResponse"/>
>       <wsdl:fault message="impl:ApiException" name="ApiException"/>
>     </wsdl:operation>
>
>  ...
>
>   <wsdl:binding name="UserServiceSoapBinding"
> type="impl:UserInterface"> <wsdlsoap:binding style="document"
> transport="http://schemas.xmlsoap.org/soap/http"/>
>
>     <wsdl:operation name="getAllUsers">
>       <wsdlsoap:operation soapAction=""/>
>       <wsdl:input name="getAllUsersRequest">
>         <wsdlsoap:body use="literal"/>
>       </wsdl:input>
>       <wsdl:output name="getAllUsersResponse">
>         <wsdlsoap:body use="literal"/>
>       </wsdl:output>
>       <wsdl:fault name="ApiException">
>         <wsdlsoap:fault name="ApiException" use="literal"/>
>       </wsdl:fault>
>     </wsdl:operation>
>
>  ...



-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog