users@jaxb.java.net

Re[2]: Problem with string arrays containing nulls

From: Egor Samarkhanov <slash_at_actimind.com>
Date: Fri, 9 Feb 2007 15:13:40 +0300

Hi, Kohsuke

I'll post and issue about this as Vivek asked.
BTW, he suggested to use wrapper bean instead
of String[]. And this works. But the other issue
I came across is about Java types adapters. I've
read your blog about using of the adapters, so
could you please comment on this issue (which
I sent to JAX-WS list recently):

================

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

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

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

    public StringArrayWrapper() {
    }

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

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

changed the services's method signature to

@WebMethod()
public StringArrayWrapper testStringArray( StringArrayWrapper w )

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

string[] testStringArray(string[] arg0)


Great! But then I decided to implement the same using Java Type Adapters
(to keep using String[] in Java method signature).
I wrote the simple adapter:

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

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

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

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


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

public stringArrayWrapper[] testStringArray(stringArrayWrapper[] arg0)

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

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


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

================


Thanks in advance,

Egor.



Friday, February 9, 2007, 2:29:49 AM, you wrote:


KK> I think this is really a JAXB/JAX-WS integration issue. There's really
KK> nothing users can do. We'll just have to fix this on our side.

KK> Egor Samarkhanov wrote:
>> Hi !
>>
>> Thanks for the answer, Vivek.
>>
>> However, I'm a bit confused as I thought WSIT is intended to
>> enable interoperability with WCF. I know that the interoperability
>> implies implementation of some complex features like reliable
>> messaging and security features, but it might be useless if
>> I can't even pass arrays between WCF client and WSIT service.
>>
>> Probably I'm missing something sine I'm new to WSIT. I will look
>> further for any possible solution, but I haven't experienced
>> such problems with WCF<->XFire integration, for example. I just
>> hope you can point me to some resources/documentation describing
>> how to customize schema types of generated WSDL documents in
>> code-first web services development.
>>
>> Thanks again,
>>
>> Egor.
>>
>> Wednesday, February 7, 2007, 10:09:05 PM, you wrote:
>>
>> VP> The generated schema look ok to me. String[] is mapped to and it seems
>> VP> correct as per JAXB schema.
>>
>> VP> <xs:element name="return" type="xs:string"
>> VP> maxOccurs="unbounded" minOccurs="0"/>
>>
>> VP> Which look ok as per JAXB spec and expectedly at runtime the
>> VP> null element is ignored. So your analysis is correct.
>>
>> VP> I am wondering if there is any jaxb annotation or some
>> VP> mechanism to generate such schema. Ccing it to users_at_jaxb alias.
>>
>> VP> -vivek.
>>
>>
>>
>>
>>
>> VP> Egor Samarkhanov wrote:
>>>> Hi!
>>>>
>>>> I have a problem with string arrays containing nulls (WSIT):
>>>>
>>>> Here is my simple service:
>>>>
>>>> @WebService
>>>> public class MyServiceImpl
>>>> {
>>>> @WebMethod()
>>>> public String[] testStringArray( String[] s )
>>>> {
>>>> return new String[] {"s","",null};
>>>> }
>>>> }
>>>>
>>>> WSIT generates the following WSDL types for it:
>>>>
>>>> <xs:schema xmlns:tns="http://wsitproto/"
>>>> xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
>>>> targetNamespace="http://wsitproto/">
>>>> <xs:element name="testStringArray" type="tns:testStringArray"/>
>>>> <xs:element name="testStringArrayResponse"
>>>> type="tns:testStringArrayResponse"/>
>>>> <xs:complexType name="testStringArray">
>>>> <xs:sequence>
>>>> <xs:element name="arg0" type="xs:string"
>>>> maxOccurs="unbounded" minOccurs="0"/>
>>>> </xs:sequence>
>>>> </xs:complexType>
>>>> <xs:complexType name="testStringArrayResponse">
>>>> <xs:sequence>
>>>> <xs:element name="return" type="xs:string"
>>>> maxOccurs="unbounded" minOccurs="0"/>
>>>> </xs:sequence>
>>>> </xs:complexType>
>>>> </xs:schema>
>>>>
>>>> I created WCF client and tried to invoke the service with the
>>>> new String[] {"s","",null} parameter,
>>>> but my service received only two first values (only
>>>> {"s",""}). The last null string is missed.
>>>>
>>>> I examined SOAP envelopes and they look accordingly:
>>>>
>>>> Inbound message:
>>>>
>>>> <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
>>>> <s:Header/>
>>>> <s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>> <testStringArray xmlns="http://wsitproto/">
>>>> <arg0 xmlns="">s</arg0>
>>>> <arg0 xmlns=""/>
>>>> </testStringArray>
>>>> </s:Body>
>>>> </s:Envelope>
>>>>
>>>> Outbound message:
>>>>
>>>> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
>>>> <S:Body>
>>>> <ns2:testStringArrayResponse
>>>> xmlns:ns2="http://wsitproto/">
>>>> <return>s</return>
>>>> <return></return>
>>>> </ns2:testStringArrayResponse>
>>>> </S:Body>
>>>> </S:Envelope>
>>>>
>>>> As I understand that's because elements are not marked as nillable="true" in WSDL.
>>>> I think the correct WSDL types would be as follows:
>>>>
>>>> <xs:schema xmlns:tns="http://wsitproto/"
>>>> xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
>>>> targetNamespace="http://wsitproto/">
>>>> <xs:element name="testStringArray" type="tns:testStringArray"/>
>>>> <xs:element name="testStringArrayResponse"
>>>> type="tns:testStringArrayResponse"/>
>>>> <xs:complexType name="testStringArray">
>>>> <xs:sequence>
>>>> <xs:element name="arg0" type="xs:string"
>>>> maxOccurs="unbounded" minOccurs="0" nillable="true"/>
>>>> </xs:sequence>
>>>> </xs:complexType>
>>>> <xs:complexType name="testStringArrayResponse">
>>>> <xs:sequence>
>>>> <xs:element name="return" type="xs:string"
>>>> maxOccurs="unbounded" minOccurs="0" nillable="true"/>
>>>> </xs:sequence>
>>>> </xs:complexType>
>>>> </xs:schema>
>>>>
>>>> (note the nillable attributes)
>>>>
>>>> And the question is how can I make WSIT generate and
>>>> correctly handle nillable types in WSDL?
>>>>
>>>>
>>>>
>>>> ----
>>>> Egor
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jax-ws.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jax-ws.dev.java.net
>>>>
>>>>
>>
>> VP>
>> ---------------------------------------------------------------------
>> VP> To unsubscribe, e-mail: users-unsubscribe_at_jax-ws.dev.java.net
>> VP> For additional commands, e-mail: users-help_at_jax-ws.dev.java.net
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>>
>>