You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Shellman, Joel" <Jo...@Summit.Fiserv.com> on 2003/01/27 21:15:31 UTC

Sending Map to a server

In my service, I have a method that accepts a Map as a parameter:

public MyObject serviceMethod(Map values) {
	// impl...
}

I used Axis to auto generate the WSDL for it and it did generate:

    <s:schema targetNamespace="http://xml.apache.org/xml-soap">
      <s:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
      <s:complexType name="Map">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="item">
            <s:complexType>
              <s:all>
                <s:element name="key" type="s:anyType" />
                <s:element name="value" type="s:anyType" />
              </s:all>
            </s:complexType>
          </s:element>
        </s:sequence>
      </s:complexType>
      <s:element name="Map" nillable="true" type="s1:Map" />

For it (namespaces for tags are a little different, but shouldn't be an
issue).

I'm getting the error:

Caused by: org.xml.sax.SAXException: Bad types (class [Ljava.lang.Object; ->
int
erface java.util.Map)
        at
org.apache.axis.message.RPCHandler.onStartChild(RPCHandler.java:207)
        at
org.apache.axis.encoding.DeserializationContextImpl.startElement(Dese
rializationContextImpl.java:857)
        at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.ja
va:199)
        at
org.apache.axis.message.MessageElement.publishToHandler(MessageElemen
t.java:644)
        at
org.apache.axis.message.RPCElement.deserialize(RPCElement.java:201)
        at org.apache.axis.message.RPCElement.getParams(RPCElement.java:259)
        at
org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider
.java:161)
        at
org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:
289)

When I try to run this. The client is sending (using tcpmon):

<?xml version='1.0' encoding='utf-8'?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns=""
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:s1="http://xml.apache.org/xml-soap"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="urn:mydomain"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://guispectrum.spectrum.summitsite.com"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<mswsb:enter xmlns:mswsb="http://mydomain" xmlns="">
<values xsi:type="soapenc:Array" soapenc:arrayType="s1:item[4]">
<item xsi:type="s1:item">
<key xsi:type="xsd:string">ID</key>
<value xsi:type="xsd:string">ZZ</value></item>
<item xsi:type="s1:item">
<key xsi:type="xsd:string">TRAN_CODE</key>
<value xsi:type="xsd:string">WHOO</value></item>
<item xsi:type="s1:item">
<key xsi:type="xsd:string">PARAMETERS_1</key>
<value xsi:type="xsd:string"></value></item>
<item xsi:type="s1:item">
<key xsi:type="xsd:string">PARAMETERS_2</key>
<value
xsi:type="xsd:string"></value></item></values></mswsb:enter></SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Is what the client is sending wrong, and if so, what should it be sending?

I tried to add a typeMapping in server-config.wsdl:

      <typeMapping
        xmlns:ns="http://xml.apache.org/xml-soap"
        qname="ns:Map"
        type="java:java.util.Map"
        serializer="org.apache.axis.encoding.ser.MapSerializerFactory"
        deserializer="org.apache.axis.encoding.ser.MapDeserializerFactory"
        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      />

But that didn't help.

Thanks!

Joel Shellman

Re: Sending Map to a server

Posted by Benjamin Tomasini <bt...@neteverything.com>.
Maps are not typesafe.  While it is possible to get it to work, I don't
think you want to send a non-typesafe component over a webservice. It
would open the door to errors.  XML-RPC works the best when your types
are expiclity declared.  I would avoid anyType declarations.  Usually
they can be avoided.

Might I suggest you change your design and use an array of JavaBeans as
your "values" argument.

public class MyBean (

	private String key;
	private String value;

	// With your getters and setters below.

)

public MyObject serviceMethod(MyBean[] values) {

On Mon, 2003-01-27 at 15:15, Shellman, Joel wrote:
> In my service, I have a method that accepts a Map as a parameter:
> 
> public MyObject serviceMethod(Map values) {
> 	// impl...
> }
> 
> I used Axis to auto generate the WSDL for it and it did generate:
> 
>     <s:schema targetNamespace="http://xml.apache.org/xml-soap">
>       <s:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
>       <s:complexType name="Map">
>         <s:sequence>
>           <s:element minOccurs="0" maxOccurs="unbounded" name="item">
>             <s:complexType>
>               <s:all>
>                 <s:element name="key" type="s:anyType" />
>                 <s:element name="value" type="s:anyType" />
>               </s:all>
>             </s:complexType>
>           </s:element>
>         </s:sequence>
>       </s:complexType>
>       <s:element name="Map" nillable="true" type="s1:Map" />
> 
> For it (namespaces for tags are a little different, but shouldn't be an
> issue).
> 
> I'm getting the error:
> 
> Caused by: org.xml.sax.SAXException: Bad types (class [Ljava.lang.Object; ->
> int
> erface java.util.Map)
>         at
> org.apache.axis.message.RPCHandler.onStartChild(RPCHandler.java:207)
>         at
> org.apache.axis.encoding.DeserializationContextImpl.startElement(Dese
> rializationContextImpl.java:857)
>         at
> org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.ja
> va:199)
>         at
> org.apache.axis.message.MessageElement.publishToHandler(MessageElemen
> t.java:644)
>         at
> org.apache.axis.message.RPCElement.deserialize(RPCElement.java:201)
>         at org.apache.axis.message.RPCElement.getParams(RPCElement.java:259)
>         at
> org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider
> .java:161)
>         at
> org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:
> 289)
> 
> When I try to run this. The client is sending (using tcpmon):
> 
> <?xml version='1.0' encoding='utf-8'?>
> <SOAP-ENV:Envelope
> SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns=""
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:s1="http://xml.apache.org/xml-soap"
> xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
> xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
> xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="urn:mydomain"
> xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
> xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
> xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
> xmlns:tns="http://guispectrum.spectrum.summitsite.com"
> xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <SOAP-ENV:Body>
> <mswsb:enter xmlns:mswsb="http://mydomain" xmlns="">
> <values xsi:type="soapenc:Array" soapenc:arrayType="s1:item[4]">
> <item xsi:type="s1:item">
> <key xsi:type="xsd:string">ID</key>
> <value xsi:type="xsd:string">ZZ</value></item>
> <item xsi:type="s1:item">
> <key xsi:type="xsd:string">TRAN_CODE</key>
> <value xsi:type="xsd:string">WHOO</value></item>
> <item xsi:type="s1:item">
> <key xsi:type="xsd:string">PARAMETERS_1</key>
> <value xsi:type="xsd:string"></value></item>
> <item xsi:type="s1:item">
> <key xsi:type="xsd:string">PARAMETERS_2</key>
> <value
> xsi:type="xsd:string"></value></item></values></mswsb:enter></SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
> 
> Is what the client is sending wrong, and if so, what should it be sending?
> 
> I tried to add a typeMapping in server-config.wsdl:
> 
>       <typeMapping
>         xmlns:ns="http://xml.apache.org/xml-soap"
>         qname="ns:Map"
>         type="java:java.util.Map"
>         serializer="org.apache.axis.encoding.ser.MapSerializerFactory"
>         deserializer="org.apache.axis.encoding.ser.MapDeserializerFactory"
>         encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>       />
> 
> But that didn't help.
> 
> Thanks!
> 
> Joel Shellman