users@jax-rpc.java.net

Array of Strings (please help!!)

From: John Huong <huongch_at_BIGFOOT.COM>
Date: Fri, 15 Nov 2002 16:53:15 +0800

I keep getting the following exception when I execute the JAX-RPC DII client
I just compiled..


array element position is out of bounds: [1]

My client code is follows..

import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.ParameterMode;
import com.sun.xml.rpc.encoding.SimpleTypeSerializer;
import com.sun.xml.rpc.encoding.CombinedSerializer;
import com.sun.xml.rpc.encoding.simpletype.XSDStringEncoder;
import com.sun.xml.rpc.encoding.SimpleTypeArraySerializer;
import com.sun.xml.rpc.encoding.ReferenceableSerializerImpl;
import com.sun.xml.rpc.encoding.SingletonSerializerFactory;
import com.sun.xml.rpc.encoding.SingletonDeserializerFactory;
import javax.xml.rpc.encoding.TypeMappingRegistry ;
import javax.xml.rpc.encoding.TypeMapping;
import javax.xml.rpc.encoding.SerializerFactory;
import javax.xml.rpc.encoding.DeserializerFactory;


public class objecttest3 implements
com.sun.xml.rpc.encoding.SerializerConstants,
com.sun.xml.rpc.wsdl.document.schema.SchemaConstants {

    private static String BODY_NAMESPACE_VALUE =
        "http://dynamic.org/wsdl";
    private static String ENCODING_STYLE_PROPERTY =
        "javax.xml.rpc.encodingstyle.namespace.uri";
    private static String NS_XSD =
        "http://www.w3.org/2001/XMLSchema";
    private static String URI_ENCODING =
         "http://schemas.xmlsoap.org/soap/encoding/";
    public static void main(String[] args) {
        try {
            String parm1 = args[0];
            String parm2 = args[1];
            String parm3 = args[2];
            String endpoint= "http://localhost:7000/johntest/testeasy2.php";
            ServiceFactory factory =
                ServiceFactory.newInstance();
            Service service =
                factory.createService(new QName("anything for the moment"));
    TypeMappingRegistry registry = service.getTypeMappingRegistry();
TypeMapping typeMapping =
registry.getTypeMapping(URI_ENCODING);

            //myformula testformula = new myformula();
            Call call = service.createCall();
            call.setTargetEndpointAddress(endpoint);

            call.setProperty(Call.SOAPACTION_USE_PROPERTY,
                new Boolean(true));
            call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
            call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
            QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
            QName elemName = new QName("", "string");
QName type = new QName(NS_XSD, "ArrayOfString");

CombinedSerializer stringSerializer = new
SimpleTypeSerializer(QNAME_TYPE_STRING, ENCODE_TYPE, NULLABLE,
URI_ENCODING, XSDStringEncoder.getInstance());
CombinedSerializer stringArraySerializer = new
SimpleTypeArraySerializer(type, ENCODE_TYPE, NULLABLE,
URI_ENCODING, elemName, QNAME_TYPE_STRING,
String.class, 1, null, (SimpleTypeSerializer)stringSerializer);
stringArraySerializer = new
ReferenceableSerializerImpl(SERIALIZE_AS_REF, stringArraySerializer);
SerializerFactory stringArraySerializerFactory = new
SingletonSerializerFactory(stringArraySerializer);
DeserializerFactory stringArrayDeserializerFactory = new
SingletonDeserializerFactory(stringArraySerializer);
typeMapping.register(String[].class, type,
stringArraySerializerFactory, stringArrayDeserializerFactory);

            //call.setReturnType(QNAME_TYPE_STRUCTURE,String.class);
            call.setReturnType(type);

            call.setOperationName(new QName(BODY_NAMESPACE_VALUE,
                "testarray"));
            call.addParameter("parm1", QNAME_TYPE_STRING,
                ParameterMode.IN);
            call.addParameter("parm2", QNAME_TYPE_STRING,
                ParameterMode.IN);
            call.addParameter("parm3", QNAME_TYPE_STRING,
                ParameterMode.IN);
            String[] params = { parm1,parm2,parm3 };

            String[] testformula = (String[])call.invoke(params);
            System.out.println("testing");

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}



The response that I get from the server is as follows (as captured by
Nettool).

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:si="http://soapinterop.org/xsd"><SOAP-ENV:Body><testarrayResponse><bla
htest xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string[1]"><item
xsi:type="xsd:string">firstnumber</item><item
xsi:type="xsd:string">secondnumber</item><item
xsi:type="xsd:string">secondnumber</item></blahtest></testarrayResponse></SO
AP-ENV:Body></SOAP-ENV:Envelope>

Please help.. I've been trying to get this to work for weeks .. sigh.