You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by bu...@apache.org on 2004/02/09 15:17:42 UTC

DO NOT REPLY [Bug 26794] New: - Couldn't converted the type from object to array.

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26794>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26794

Couldn't converted the type from object to array.

           Summary: Couldn't converted the type from object to array.
           Product: Axis
           Version: 1.1
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Samples
        AssignedTo: axis-dev@ws.apache.org
        ReportedBy: tritreechina@hotmail.com


I wanted to convert the data type from object to String[] . I got the exception 
just like following: 

Exception in thread "main" java.lang.ArrayStoreException 
       at org.apache.axis.utils.JavaUtils.convert(JavaUtils.java:432) 
       at ArrayClient.main(ArrayClient.java:50) 

JDK: j2sdk1.4.2_03 
tomcat: 5.018 
Axis: 1.1 
system: windows 2000 server(chinese) 


What can I do? 
Thanks at all.


Here is the sources:
// File : AddressService.java

public class AddressService {
  private int[] id = {111, 222, 333};
  private String[][] addressBook = {{"Street 11", "London", "UK", "34534"},
                                    {"Lane 4", "New York", "USA", "53457"},
                                    {"Lane 5", "LA", "USA", "67635"}};

  public String[] getArray(int id) {
    for (int i=0; i<addressBook.length; i++) {
      if(this.id[i] == id) {
        return addressBook[i];
      }
    }
    String error[] = {"id not found!"}; 
    return error;
  }
}


<!-- File: address.wsdd -->
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

  <service name="AddressService" provider="java:RPC">
    <parameter name="className" value="AddressService"/>
    <parameter name="allowedMethods" value="*"/>
    <typeMapping 
        serializer="org.apache.axis.encoding.ser.ArraySerializerFactory"
        deserializer="org.apache.axis.encoding.ser.ArrayDeserializerFactory"
        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
        type="java:java.lang.String[]"
        qname="ns1:ArrayOfstring"
        xmlns:ns1="http://soapinterop.org/xsd"/>
  </service>
</deployment>

//File: ArrayClient.java 
import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.utils.Options;
import org.apache.axis.utils.JavaUtils;

import org.apache.axis.encoding.ser.ArraySerializerFactory;
import org.apache.axis.encoding.ser.ArrayDeserializerFactory;

import org.apache.axis.encoding.XMLType;

import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ArrayClient {
  public static void main(String [] args) throws Exception {
    String url = "http://localhost:8080/axis/servlet/AxisServlet";
    String id = null;
    try {
      BufferedReader reader = new BufferedReader(
                                    new InputStreamReader(System.in));
      System.out.print("Enter id: ");
      id = reader.readLine();
    } catch (Exception e){
      e.printStackTrace();
    }

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

    QName qn = new QName("http://soapinterop.org/xsd", "ArrayOfstring");

    call.registerTypeMapping(String[][].class, qn,
               new ArraySerializerFactory(),
               new ArrayDeserializerFactory());

    String result[] = {""};

    try {
      call.setTargetEndpointAddress(new java.net.URL(url));
      call.setOperationName(new QName("AddressService", "getArray"));
      call.addParameter("id", XMLType.XSD_INT, ParameterMode.IN);
      call.setReturnType(qn);

      Object resp = call.invoke(new Object[] {new Integer(id)});

      result = (String[])JavaUtils.convert(resp, String[].class);

    } catch (AxisFault fault) {
	System.out.println("Error : " + fault.toString());
	fault.printStackTrace();
    }
    System.out.println("Address of " + id);
    for(int i=0; i<result.length; i++)
      System.out.println("\t" + result[i]);
  }
}