users@jax-ws.java.net

Re[2]: Problem with string arrays containing nulls

From: Egor Samarkhanov <slash_at_actimind.com>
Date: Fri, 9 Feb 2007 20:18:18 +0300

Hello !

Thanks, Sekhar, I'll try to remove it.

But the main question here was about Java type converters.
I don't really understand why I get the array of wrapper beans
(wrapping String[]) in WSDL when the wrapper bean is specified using
the @XmlJavaTypeAdapter annotation?


Friday, February 9, 2007, 8:13:12 PM, you wrote:

SV> In your code,
SV> @XmlElement(nillable=true)
SV> private String[] array;
SV> The annnotation @XmlElement(nillable=true) is not required
SV> for a collection property. That is the default.

SV> Sekhar

SV> Egor Samarkhanov wrote:
  
SV> Hello !

SV> Thanks for the hint about wrapper bean. I've created the following
SV> wrapper:

SV> @XmlAccessorType(value=XmlAccessType.FIELD)
SV> public class StringArrayWrapper
SV> {
SV> @XmlElement(nillable=true)
SV> private String[] array;

SV> public StringArrayWrapper( String[] array ) {
SV> this.array = array;
SV> }

SV> public StringArrayWrapper() {
SV> }

SV> public String[] getArray() {
SV> return array;
SV> }

SV> public void setArray( String[] array ) {
SV> this.array = array;
SV> }
SV> }

SV> changed the services's method signature to

SV> @WebMethod()
SV> public StringArrayWrapper testStringArray( StringArrayWrapper w )

SV> and got the expected result. Moreover, the WCF's service method
SV> signature is still

SV> string[] testStringArray(string[] arg0)


SV> Great! But then I decided to implement the same using Java Type Adapters
SV> (to keep using String[] on Java side).
SV> I wrote the simple adapter:

SV> public class AdapterStringArrayToBean extends
SV> XmlAdapter<StringArrayWrapper, String[]>
SV> {
SV> public String[] unmarshal( StringArrayWrapper wrapper ) throws Exception
SV> {
SV> if( wrapper == null )
SV> return null;
SV> return wrapper.getArray();
SV> }

SV> public StringArrayWrapper marshal( String[] s ) throws Exception
SV> {
SV> return new StringArrayWrapper( s );
SV> }
SV> }

SV> and then changed the service's method signature like this:

SV> @WebMethod()
SV> public @XmlJavaTypeAdapter(type=String[].class,
SV> value=AdapterStringArrayToBean.class) String[] testStringArray(
SV> @XmlJavaTypeAdapter(type=String[].class,
SV> value=AdapterStringArrayToBean.class) String[] s )


SV> After the deployment I got the following method signature in WCF:

SV> public stringArrayWrapper[]
SV> testStringArray(stringArrayWrapper[] arg0)

SV> Well, I didn't expect array of wrappers. I thought it should be just the
SV> wrapper. I checked the WSDL and indeed, maxOccurs="unbounded" is set for
SV> the arg0 element (line 3):

SV> <xs:complexType name="testStringArray">
SV> <xs:sequence>
SV> <xs:element name="arg0" type="tns:stringArrayWrapper"
SV> maxOccurs="unbounded" minOccurs="0" />
SV> </xs:sequence>
SV> </xs:complexType>
SV> <xs:complexType name="stringArrayWrapper">
SV> <xs:sequence>
SV> <xs:element name="array" type="xs:string" nillable="true"
SV> maxOccurs="unbounded" minOccurs="0" />
SV> </xs:sequence>
SV> </xs:complexType>


SV> I guess my adapter is wrong. How can I write the adapter correctly for
SV> this case?


SV> Thanks for your help,

SV> Egor.


SV> Thursday, February 8, 2007, 2:52:10 AM, you wrote:

VP>> After talking to jaxb experts - there is no jaxb annotation that you can
VP>> put on method parameters to achieve such behaviour. This is something
VP>> that can be handled by JAXWS, where it can generate
VP>> @XmlElement(nillable="true") in the wrapper bean on the property.

VP>> However we would need to verify whether such change will be
VP>> non-compliant w.r.t. generated code from such schema by wsimport.

VP>> Please go ahead and report and issue at
VP>> http://jax-ws.dev.java.net/servlets/ProjectIssues.

VP>> -vivek.

VP>> Vivek Pandey wrote:
  
  
  
SV> The generated schema look ok to me. String[] is mapped to and it seems
SV> correct as per JAXB schema.

SV> <xs:element name="return" type="xs:string" maxOccurs="unbounded"
minOccurs="0"/>>

SV> Which look ok as per JAXB spec and expectedly at runtime the null
SV> element is ignored. So your analysis is correct.
SV> I am wondering if there is any jaxb annotation or some mechanism to
SV> generate such schema. Ccing it to users_at_jaxb alias.

SV> -vivek.





SV> Egor Samarkhanov wrote:
  
  
SV> Hi!

SV> I have a problem with string arrays containing nulls (WSIT):

SV> Here is my simple service:

SV> @WebService
SV> public class MyServiceImpl
SV> {
SV> @WebMethod()
SV> public String[] testStringArray( String[] s )
SV> {
SV> return new String[] {"s","",null};
SV> }
SV> }

SV> WSIT generates the following WSDL types for it:

SV> <xs:schema xmlns:tns="http://wsitproto/"
SV> xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
SV> targetNamespace="http://wsitproto/">
SV> <xs:element name="testStringArray" type="tns:testStringArray"/>
SV> <xs:element name="testStringArrayResponse"
SV> type="tns:testStringArrayResponse"/>
SV> <xs:complexType name="testStringArray">
SV> <xs:sequence>
SV> <xs:element name="arg0" type="xs:string"
SV> maxOccurs="unbounded" minOccurs="0"/>
SV> </xs:sequence>
SV> </xs:complexType>
SV> <xs:complexType name="testStringArrayResponse">
SV> <xs:sequence>
SV> <xs:element name="return" type="xs:string"
SV> maxOccurs="unbounded" minOccurs="0"/>
SV> </xs:sequence>
SV> </xs:complexType>
SV> </xs:schema>

SV> I created WCF client and tried to invoke the service with the new
SV> String[] {"s","",null} parameter,
SV> but my service received only two first values (only {"s",""}). The
SV> last null string is missed.

SV> I examined SOAP envelopes and they look accordingly:

SV> Inbound message:

SV> <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
SV> <s:Header/>
SV> <s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema"
SV> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
SV> <testStringArray xmlns="http://wsitproto/">
SV> <arg0 xmlns="">s</arg0>
SV> <arg0 xmlns=""/>
SV> </testStringArray>
SV> </s:Body>
SV> </s:Envelope>

SV> Outbound message:

SV> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
SV> <S:Body>
SV> <ns2:testStringArrayResponse xmlns:ns2="http://wsitproto/">
SV> <return>s</return>
SV> <return></return>
SV> </ns2:testStringArrayResponse>
SV> </S:Body>
SV> </S:Envelope>

SV> As I understand that's because elements are not marked as
SV> nillable="true" in WSDL.
SV> I think the correct WSDL types would be as follows:

SV> <xs:schema xmlns:tns="http://wsitproto/"
SV> xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
SV> targetNamespace="http://wsitproto/">
SV> <xs:element name="testStringArray" type="tns:testStringArray"/>
SV> <xs:element name="testStringArrayResponse"
SV> type="tns:testStringArrayResponse"/>
SV> <xs:complexType name="testStringArray">
SV> <xs:sequence>
SV> <xs:element name="arg0" type="xs:string"
SV> maxOccurs="unbounded" minOccurs="0" nillable="true"/>
SV> </xs:sequence>
SV> </xs:complexType>
SV> <xs:complexType name="testStringArrayResponse">
SV> <xs:sequence>
SV> <xs:element name="return" type="xs:string"
SV> maxOccurs="unbounded" minOccurs="0" nillable="true"/>
SV> </xs:sequence>
SV> </xs:complexType>
SV> </xs:schema>

SV> (note the nillable attributes)

SV> And the question is how can I make WSIT generate and correctly handle
SV> nillable types in WSDL?

 
SV> ----
SV> Egor


SV> ---------------------------------------------------------------------
SV> To unsubscribe, e-mail:
SV> users-unsubscribe_at_jax-ws.dev.java.netFor additional commands,
SV> e-mail: users-help_at_jax-ws.dev.java.net
  
  
SV> ---------------------------------------------------------------------
SV> To unsubscribe, e-mail:
SV> users-unsubscribe_at_jax-ws.dev.java.netFor additional commands,
SV> e-mail: users-help_at_jax-ws.dev.java.net
  
  
  
VP>> ---------------------------------------------------------------------
VP>> To unsubscribe, e-mail:
VP>> users-unsubscribe_at_jax-ws.dev.java.netVP> For additional commands,
VP>> e-mail:
VP>> users-help_at_jax-ws.dev.java.net---------------------------------------------------------------------
SV> To unsubscribe, e-mail:
SV> users-unsubscribe_at_jax-ws.dev.java.netFor additional commands,
SV> e-mail: users-help_at_jax-ws.dev.java.net



  



------------------------------------
Best regards,
Egor Samarkhanov (slash_at_actimind.com)
Actimind, Inc.