axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicholas Remy <nr...@caci.com>
Subject Re: Problem returning string array types
Date Mon, 08 Mar 2004 12:57:45 GMT
Don't know the specific answer to your question regarding a true 
deserialization "problem" with String arrays, but I've been using the 
following Java client code as a work-around to this exact problem, and it 
seems to work okay for us:

        try {
            String endpointURL = 
"http://localhost:8080/axis/services/yourServiceName";

            Service service = new Service();
            Call call = (Call) service.createCall();

            call.setTargetEndpointAddress( new java.net.URL(endpointURL) 
);

            call.setOperationName( new QName("yourServiceClass", 
"yourMethod") );

            call.addParameter("inputParam", XMLType.XSD_STRING, 
ParameterMode.IN);
            call.setReturnType( XMLType.XSD_ANY );

            String[] ret = (String[]) call.invoke( new Object[] { "value" 
} );
        } catch (Exception e) {
            System.err.println(e.toString());
        }



The thing to key in on here is the XMLType.XSD_ANY value in the 
setReturnType method.  As I said, I don't know if this is the BEST way to 
approach this, but as a last-ditch, stop-gap measure, it may work for you.


Nicholas (Nick) Remy









Ray Kramp <ray_kramp@yahoo.com> 
03/05/2004 06:02 PM
Please respond to
axis-user@ws.apache.org


To
axis-user@ws.apache.org
cc

Subject
Problem returning string array types






Hi Axis users,

I was wondering if someone might know the solution to a deserialization 
problem
that I'm experiencing when returning a Java String array type in a 
response
from a service method.

My service is deployed to Axis 1.1 and it's invoked using client stubs
generated with Axis WSDL2Java.  I'm able to pass string arrays in 
requests, but
when I return a string array I encounter this exception:

  org.xml.sax.SAXException: Bad types
  (class [Ljava.lang.Object; -> class java.lang.String)
  at org.apache.axis.message.RPCHandler.onStartChild
  (RPCHandler.java:311)
  at org.apache.axis.encoding.DeserializationContextImpl.startElement
  (DeserializationContextImpl.java:963)

For example, here's a test class that I've deployed to Axis:

    package arraytest;
    public class Test {
        public String[]  method() {
            return new String [] {"a", "b", "c"};
        }
    }

My wsdd file is defined as:

    <?xml version="1.0" encoding="UTF-8"?>
    <deployment
     xmlns="http://xml.apache.org/axis/wsdd/"
     xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
     <service name="TestService" provider="java:RPC">
      <parameter name="allowedMethods" value="method"/>
      <parameter name="scope" value="request"/>
      <parameter name="className" value="arraytest.Test"/>
      <typeMapping 
       encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
       serializer="org.apache.axis.encoding.ser.ArraySerializerFactory"
 deserializer="org.apache.axis.encoding.ser.ArrayDeserializerFactory"
       type="java:java.lang.String[]"
       qname="ns1:ArrayOfString"
       xmlns:ns1="urn:java.lang"/>
     </service>
    </deployment>

Is there a problem with the type mapping that I've created?  My client is 
using
stub classes generated with Axis WSDL2Java.  The code which makes the call 
was
generated as:

    public java.lang.String[] method() throws java.rmi.RemoteException {
        if (super.cachedEndpoint== null) {
            throw new org.apache.axis.NoEndPointException();
        }
        org.apache.axis.client.Call _call = createCall();
        _call.setOperation(_operations[0]);
        _call.setUseSOAPAction(true);
        _call.setSOAPActionURI("");
        _call.setSOAPVersion
         (org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
        _call.setOperationName(new javax.xml.namespace.QName
         ("http://arraytest", "method"));

        setRequestHeaders(_call);
        setAttachments(_call);
        java.lang.Object _resp = _call.invoke(new java.lang.Object[] {});

        if (_resp instanceof java.rmi.RemoteException) {
            throw (java.rmi.RemoteException)_resp;
        }
        else {
            extractAttachments(_call);
            try {
                return (java.lang.String[]) _resp;
            } catch (java.lang.Exception _exception) {
                return (java.lang.String[])
                  org.apache.axis.utils.JavaUtils.convert(
                  _resp, java.lang.String.class);
            }
        }
    }

Here's my wsdl document:

    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions
     targetNamespace="http://localhost:18080/axis/services/TestService"
     xmlns="http://schemas.xmlsoap.org/wsdl/"
     xmlns:apachesoap="http://xml.apache.org/xml-soap"
     xmlns:impl="http://localhost:18080/axis/services/TestService"
     xmlns:intf="http://localhost:18080/axis/services/TestService"
     xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
     xmlns:tns1="urn:java.lang"
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
     xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <wsdl:types>
        <schema
         targetNamespace="urn:java.lang"
         xmlns="http://www.w3.org/2001/XMLSchema">
          <import
           namespace="http://schemas.xmlsoap.org/soap/encoding/" />

          <complexType
           name="ArrayOfString">
            <complexContent>
              <restriction
               base="soapenc:Array">
                <attribute
                 ref="soapenc:arrayType"
                 wsdl:arrayType="xsd:string[]" />
              </restriction>
            </complexContent>
          </complexType>
        </schema>
      </wsdl:types>

      <wsdl:message
       name="methodResponse">
        <wsdl:part
         name="methodReturn"
         type="tns1:ArrayOfString" />
      </wsdl:message>

      <wsdl:message
       name="methodRequest">
      </wsdl:message>

      <wsdl:portType
       name="Test">
        <wsdl:operation
         name="method">
          <wsdl:input
           message="impl:methodRequest"
           name="methodRequest" />

          <wsdl:output
           message="impl:methodResponse"
           name="methodResponse" />
        </wsdl:operation>
      </wsdl:portType>

      <wsdl:binding
       name="TestServiceSoapBinding"
       type="impl:Test">
        <wsdlsoap:binding
         style="rpc"
         transport="http://schemas.xmlsoap.org/soap/http" />

        <wsdl:operation
         name="method">
          <wsdlsoap:operation
           soapAction="" />

          <wsdl:input
           name="methodRequest">
            <wsdlsoap:body
             encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
             namespace="http://arraytest"
             use="encoded" />
          </wsdl:input>

          <wsdl:output
           name="methodResponse">
            <wsdlsoap:body
             encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
             namespace="http://localhost:18080/axis/services/TestService"
             use="encoded" />
          </wsdl:output>
        </wsdl:operation>
      </wsdl:binding>

      <wsdl:service
       name="TestService">
        <wsdl:port
         binding="impl:TestServiceSoapBinding"
         name="TestService">
          <wsdlsoap:address
           location="http://localhost:18080/axis/services/TestService" />
        </wsdl:port>
      </wsdl:service>
    </wsdl:definitions>

Thanks in advance!

Ray


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com



Mime
View raw message