As you have observed, the default behavior of Apache SOAP (cf. arrays in
SOAPMappingRegistry.java) is to serialize a Long in a manner indistinguishable
from a Long, and when looking for a matching method signature that includes a
long[] parameter, Long[] is not checked for.  While changing the latter would, I
believe, require a change to the Apache SOAP source, you can change the
serialization of Long by providing a custom serializer (and a deserializer for
the server to unmarshal the SOAP message).  You cannot use the BeanSerializer,
because Long does not fit the criteria (e.g. no default constructor, no
read/write properties).

Actually, the serializer and deserializer you need already exist.  The
LongObjectDeserializer deserializes a Long.  The serializer already registered
for Long can be re-used.

In the client code, do something like:

    SOAPMappingRegistry smr = new SOAPMappingRegistry();
    Serializer ser = smr.querySerializer(long.class, Constants.NS_URI_SOAP_ENC);
    Deserializer deser = new LongObjectDeserializer();
    smr.mapTypes(Constants.NS_URI_SOAP_ENC,
                 new QName("urn:some-urn-you-create", "LongObject"),
                 Long.class, ser, deser);

In the server DeploymentDescriptor.xml, do something like:

  <isd:mappings>
    <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
             xmlns:x="urn:some-urn-you-create" qname="x:LongObject"
             javaType="java.lang.Long"
             java2XMLClassName=""

xml2JavaClassName="org.apache.soap.encoding.soapenc.LongObjectDeserializer"/>
  </isd:mappings>

Scott Nichol

----- Original Message -----
From: "Kelvin Cheung" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, March 20, 2002 11:51 PM
Subject: long[] vs Long[] serialization


> Hi,
>
> Currently I need to wrap a function with java.lang.Long[] as one of the
> parameters.
>
> As I made up the call as follow:
>
>     Long longArray[] = {new Long(1),new Long(2)};
>     params.addElement (new Parameter("longArray", longArray.getClass(),
> longArray, null));
>
> What I observed is that within the SOAP Envelope, the array Long[] is always
> treated as an long[] array.  When this being deserialized at the SOAP
> Engine, it tries to find a signature with long[] as the parameter.  So I got
> an error message:
>
> Ouch, the call failed:
>   Fault Code   = SOAP-ENV:Server
>   Fault String = Exception while handling service request:
> samples.test.TestArray.testWrapper(long[]) -- no signature match
>
> Is there a way that I can use the default Serializer/Deserializer to pass an
> Long[] array?
>
>
> In another situation, I have created a custom Serializer/Deserializer as
> well as the WSDL files.  If a client wants to use my SOAP Service, is there
> any way (by providing more standard documents?) that the service can be
> invoked without a Serializer/Deserializer on the client side?
>
> Thanks for your advice!
>
> kelvin


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Reply via email to