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 "Marcia Perry (DSD staff)" <MP...@lbl.gov> on 2004/01/17 00:45:51 UTC

DII invoke that returns array

Hi,

I'm playing with the faults/samples/ web service that comes
in the axis-1.1 distribution.  After reading and searching I
still have a question that I hope someone can answer.

The EmployeeInfo.java file (the src file for the web service)
has this function:
     public Employee[] getEmployees() throws AxisFault
     {
        Collection values = map.values();
        Employee[] emps = new Employee[values.size()];
        values.toArray(emps);
        return emps;
     }

I modified the Richard Hansen's EmployeeClient.java file (posted
on axis-dev mailing list Aug. 2003) to call this method, shown 
below. I can't get it to work--probably need to just make a 
trivial tweak but I'm stuck (after LOTS of searching/reading), so 
please help if you can.

EmployeeClient.java:

import org.apache.axis.encoding.ser.*;
import org.apache.axis.AxisFault;
import org.apache.axis.utils.Options;
import javax.xml.rpc.*;
import javax.xml.rpc.encoding.*;
import javax.xml.namespace.QName;
import java.net.URL;
import java.util.*;
import javax.rmi.RemoteException;

public class EmployeeClient {
    private static String URI = "http://faults.samples';
    private static String SERVICE_NAME = "EmployeeInfoService";
    private URL url;
    private ServiceFactory serviceFactory;
    private Service service;

    public EmployeeClient(String endpt) throws Exception {
        url = new URL(endpt);
        serviceFactory = ServiceFactory.newInstance();
        service = serviceFactory.createService(
                new QName(URI, SERVICE_NAME));
        TypeMappingRegistry registry = service.getTypeMappingRegistry();
        TypeMapping map = registry.getDefaultTypeMapping();
        QName employeeQName = new QName(URI, "Employee");
        map.register(Employee.class, employeeQName,
            new BeanSerializerFactory(Employee.class, employeeQName),
            new BeanDeserializerFactory(Employee.class, employeeQName));
        
        // I ADDED THE FOLLOWING--Don't KNOW IF IT'S CORRECT
        map.register(Employee[].class, employeeQName,
            new ArraySerializerFactory(), new
ArrayDeserializerFactory());
        // End Marcia's section

        QName faultQName = new QName(URI, "NoSuchEmployeeFault");
        map.register(NoSuchEmployeeFault.class, faultQName,
            new BeanSerializerFactory(NoSuchEmployeeFault.class, 
                faultQName),
            new BeanDeserializerFactory(NoSuchEmployeeFault.class,
                faultQName));
       }
       
       private Call createCall(String op) throws ServiceException {
            Call call = service.createCall();
            call.setTargetEndpointAddress(url.toString());
            call.setProperty(Call.SESSION_MAINTAIN_PROPERTY,
                 Boolean.TRUE);
            call.setProperty(Call.SOAPACTION_USE_PROPERTY,
                Boolean.TRUE);
            call.setProperty(Call.SOAPACTION_URI_PROPERTY, URI);
            call.setOperationName(new QName(URI, op));
            return call;
       }
 
       public void getEmployee(String id) throws ServiceException,
        RemoteException {
             // Code omitted from this post--it works
       }

       public void addEmployee(Employee emp) throws ServiceException,
        RemoteException {
             // Code omitted from this post -- it works
       }

       public void getEmployees() throws ServiceException, 
        RemoteException {
            // THIS IS THE WHERE I'D LIKE HELP!!!
            try {
                Call call = createCall("getEmployees");
		
		// I ADDED THIS LINE
                call.setReturnType(XMLType.SOAP_ARRAY);

                // Line below doesn't even compile!!
                Employee[] emps = 
                    call.invoke(new Object[] {});
            } catch(AxisFault e) {
                // handle the fault--System.out.println()'s
            }
        }

        public static void main(String[] args) {
            try {
                Options opts = new Options(args);
                EmployeeClient test = new EmployeeClient(opts.getURL());
                String[] args2 = opts.getRemainingArgs();
                // LINE BELOW COMPILES AND WORKS!
                test.addEmployee(new Employee("#001", "Marcia"));
                
                // I WANT TO TEST THE LINE BELOW AND GET
THE                			// ARRAY OF EMPLOYEEs TO WORK!
                test.getEmployees();
           } catch(Exception e) {
                System.out..........;
           }
        }
    }

Thanks for helping me on this or offering sample code
that does a call.invoke() using DII to get an array of
objects (Java beans) back.  
    -- marcia
-- 
----------------------------------------------------------------
Marcia Perry                            MPerry@lbl.gov
Lawrence Berkeley National Laboratory   WORK#  (510) 486-6786
1 Cyclotron Road                        FAX#   (510) 486-6363
Berkeley, CA 94720     			MS: 50A-3111