axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Srinadh Karumuri <skaru...@bbn.com>
Subject RE: returning arrays of custom java objects
Date Wed, 11 May 2005 19:13:28 GMT
Ben,

I thank you with my whole heart. It works!

You should think of writing an article. If you are ok with it I will post 
this email in the forum for someone like me.

I had to make a small modification though. It didn't like doing the 
TypeMapping for array saying Bad Types. So I took off the TypeMapping from 
the client for Array and just left the Single/Bean part.
Here is my final client code:
String endpoint =
"http://localhost:" + options.getPort() + 
"/bserv/services/EmployeeDataService";
String method = args[0];
String arg1 = args[1];;
String arg2 = args[2];;
Service service = new Service();

qname = new QName("EmployeeLateTSArray", "EmployeeLateTSBean");
TypeMappingRegistry tmr = service.getTypeMappingRegistry();
TypeMapping tmlts = tmr.createTypeMapping();
tmlts.register(
   Class.forName("com.bbn.ws.EmployeeLateTSBean"),
     qname,
     new 
org.apache.axis.encoding.ser.BeanSerializerFactory(EmployeeLateTSBean.class,qname),
     new 
org.apache.axis.encoding.ser.BeanDeserializerFactory(EmployeeLateTSBean.class,qname));
tmr.register("http://schemas.xmlsoap.org/soap/encoding/", tmlts);

qname = new QName("EmployeeLateTSArray", "EmployeeLateTSBeanArray");
call = (Call) service.createCall();
call.setReturnType (qname);
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(method);
call.addParameter("admnum", XMLType.XSD_INTEGER, ParameterMode.IN);
call.addParameter("mgrnum", XMLType.XSD_INTEGER, ParameterMode.IN);
call.setReturnType(qname);

EmployeeLateTSBean e[] = (EmployeeLateTSBean[])call.invoke(new Object[] { 
new Integer(arg1), new Integer(arg2) }); //arg1, arg2 });

My WDSL:

  <service name="EmployeeDataService" provider="java:RPC">
   <requestFlow>
    <handler type="java:org.apache.axis.handlers.SOAPMonitorHandler"/>
   </requestFlow>
   <responseFlow>
    <handler type="java:org.apache.axis.handlers.SOAPMonitorHandler"/>
   </responseFlow>
   <parameter name="allowedMethods" value="getEmployeeLateTSDataArray"/>
   <parameter name="scope" value="application"/>
   <parameter name="className" value="com.bbn.ws.EmployeeDataService"/>
   <typeMapping type="java:com.bbn.ws.EmployeeLateTSBean"
                qname="ns1:EmployeeLateTSBean"
                    xmlns:ns1="EmployeeLateTSArray"
                 deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory" 

                 serializer="org.apache.axis.encoding.ser.BeanSerializerFactory" 

              encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   <typeMapping qname="ns1:EmployeeLateTSBeanArray"
              xmlns:ns1="EmployeeLateTSArray"
              type="java:com.bbn.ws.EmployeeLateTSBean[]"
                 deserializer="org.apache.axis.encoding.ser.ArrayDeserializerFactory" 

                 serializer="org.apache.axis.encoding.ser.ArraySerializerFactory" 

              encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  </service>

Thank you,
Sri.

At 03:13 PM 5/10/2005, Benjamin.Temko@VerizonWireless.com wrote:
>Sri,
>
>I'm using the version of the Service constructor which takes an URL of a 
>WSDL file which describes the service (e.g. 
><http://yourserver.com:8080/axis/services/MyService?wsdl>http://yourserver.com:8080/axis/services/MyService?wsdl),

>and the qualified name (QName) which is the name of your service as 
>specified in that WSDl file.
>
>For example, When I made a test service using a class named Calculator, I 
>got a WSDL like this:
>
>========================================
><wsdl:definitions 
>targetNamespace="<http://d2:8080/axis/services/Calculator>http://d2:8080/axis/services/Calculator">
>-
>  <!--
>WSDL created by Apache Axis version: 1.2RC2
>Built on Nov 16, 2004 (12:19:44 EST)
>-->
>-
>  <wsdl:message name="subtractResponse">
><wsdl:part name="subtractReturn" type="xsd:int"/>
></wsdl:message>
>-
>  <wsdl:message name="testMethodRequest">
><wsdl:part name="in0" type="xsd:int"/>
><wsdl:part name="in1" type="xsd:int"/>
></wsdl:message>
>-
>  <wsdl:message name="addResponse">
><wsdl:part name="addReturn" type="xsd:int"/>
></wsdl:message>
>-
>  <wsdl:message name="testMethodResponse">
><wsdl:part name="testMethodReturn" type="xsd:int"/>
></wsdl:message>
>-
>  <wsdl:message name="subtractRequest">
><wsdl:part name="in0" type="xsd:int"/>
><wsdl:part name="in1" type="xsd:int"/>
></wsdl:message>
>-
>  <wsdl:message name="addRequest">
><wsdl:part name="in0" type="xsd:int"/>
><wsdl:part name="in1" type="xsd:int"/>
></wsdl:message>
>-
>  <wsdl:message name="stringMethodRequest">
><wsdl:part name="in0" type="xsd:int"/>
><wsdl:part name="in1" type="xsd:int"/>
></wsdl:message>
>-
>  <wsdl:message name="stringMethodResponse">
><wsdl:part name="stringMethodReturn" type="xsd:string"/>
></wsdl:message>
>-
>  <wsdl:portType name="Calculator">
>-
>  <wsdl:operation name="add" parameterOrder="in0 in1">
><wsdl:input message="impl:addRequest" name="addRequest"/>
><wsdl:output message="impl:addResponse" name="addResponse"/>
></wsdl:operation>
>-
>  <wsdl:operation name="subtract" parameterOrder="in0 in1">
><wsdl:input message="impl:subtractRequest" name="subtractRequest"/>
><wsdl:output message="impl:subtractResponse" name="subtractResponse"/>
></wsdl:operation>
>-
>  <wsdl:operation name="testMethod" parameterOrder="in0 in1">
><wsdl:input message="impl:testMethodRequest" name="testMethodRequest"/>
><wsdl:output message="impl:testMethodResponse" name="testMethodResponse"/>
></wsdl:operation>
>-
>  <wsdl:operation name="stringMethod" parameterOrder="in0 in1">
><wsdl:input message="impl:stringMethodRequest" name="stringMethodRequest"/>
><wsdl:output message="impl:stringMethodResponse" name="stringMethodResponse"/>
></wsdl:operation>
></wsdl:portType>
>-
>  <wsdl:binding name="CalculatorSoapBinding" type="impl:Calculator">
><wsdlsoap:binding style="rpc" 
>transport="http://schemas.xmlsoap.org/soap/http"/>
>-
>  <wsdl:operation name="add">
><wsdlsoap:operation soapAction=""/>
>-
>  <wsdl:input name="addRequest">
><wsdlsoap:body 
>encodingStyle="<http://schemas.xmlsoap.org/soap/encoding/>http://schemas.xmlsoap.org/soap/encoding/"

>namespace="<http://d2:8080/axis/services/Calculator>http://d2:8080/axis/services/Calculator"

>use="encoded"/>
></wsdl:input>
>-
>  <wsdl:output name="addResponse">
><wsdlsoap:body 
>encodingStyle="<http://schemas.xmlsoap.org/soap/encoding/>http://schemas.xmlsoap.org/soap/encoding/"

>namespace="<http://d2:8080/axis/services/Calculator>http://d2:8080/axis/services/Calculator"

>use="encoded"/>
></wsdl:output>
></wsdl:operation>
>-
>  <wsdl:operation name="subtract">
><wsdlsoap:operation soapAction=""/>
>-
>  <wsdl:input name="subtractRequest">
><wsdlsoap:body 
>encodingStyle="<http://schemas.xmlsoap.org/soap/encoding/>http://schemas.xmlsoap.org/soap/encoding/"

>namespace="<http://d2:8080/axis/services/Calculator>http://d2:8080/axis/services/Calculator"

>use="encoded"/>
></wsdl:input>
>-
>  <wsdl:output name="subtractResponse">
><wsdlsoap:body 
>encodingStyle="<http://schemas.xmlsoap.org/soap/encoding/>http://schemas.xmlsoap.org/soap/encoding/"

>namespace="<http://d2:8080/axis/services/Calculator>http://d2:8080/axis/services/Calculator"

>use="encoded"/>
></wsdl:output>
></wsdl:operation>
>-
>  <wsdl:operation name="testMethod">
><wsdlsoap:operation soapAction=""/>
>-
>  <wsdl:input name="testMethodRequest">
><wsdlsoap:body 
>encodingStyle="<http://schemas.xmlsoap.org/soap/encoding/>http://schemas.xmlsoap.org/soap/encoding/"

>namespace="<http://d2:8080/axis/services/Calculator>http://d2:8080/axis/services/Calculator"

>use="encoded"/>
></wsdl:input>
>-
>  <wsdl:output name="testMethodResponse">
><wsdlsoap:body 
>encodingStyle="<http://schemas.xmlsoap.org/soap/encoding/>http://schemas.xmlsoap.org/soap/encoding/"

>namespace="<http://d2:8080/axis/services/Calculator>http://d2:8080/axis/services/Calculator"

>use="encoded"/>
></wsdl:output>
></wsdl:operation>
>-
>  <wsdl:operation name="stringMethod">
><wsdlsoap:operation soapAction=""/>
>-
>  <wsdl:input name="stringMethodRequest">
><wsdlsoap:body 
>encodingStyle="<http://schemas.xmlsoap.org/soap/encoding/>http://schemas.xmlsoap.org/soap/encoding/"

>namespace="<http://d2:8080/axis/services/Calculator>http://d2:8080/axis/services/Calculator"

>use="encoded"/>
></wsdl:input>
>-
>  <wsdl:output name="stringMethodResponse">
><wsdlsoap:body 
>encodingStyle="<http://schemas.xmlsoap.org/soap/encoding/>http://schemas.xmlsoap.org/soap/encoding/"

>namespace="<http://d2:8080/axis/services/Calculator>http://d2:8080/axis/services/Calculator"

>use="encoded"/>
></wsdl:output>
></wsdl:operation>
></wsdl:binding>
>-
>  <wsdl:service name="CalculatorService">
>-
>  <wsdl:port binding="impl:CalculatorSoapBinding" name="Calculator">
><wsdlsoap:address location="http://d2:8080/axis/services/Calculator"/>
></wsdl:port>
></wsdl:service>
></wsdl:definitions>
>========================================
>
>Now, notice at the top of this WSDL, the target namespace is 
>"<http://d2:8080/axis/services/Calculator>http://d2:8080/axis/services/Calculator",

>and at the bottom of this WSDL that the service name is 
>"CalculatorService".  So to instantiate the service, I do this:
>
>QName qn = new 
>QName("<http://d2:8080/axis/services/Calculator>http://d2:8080/axis/services/Calculator",

>"CalculatorService");
>Service service = new Service(wsdlUrl, qn);
>
>This populates my service with everything I need.  I can then just do 
>service.call() on the thing and pass it the names of the methods I know to 
>be there.  The WSDL file contains everything axis needs except the type 
>mapping, which you provide yourself with the calls to register().
>
>Hope this helps!
>
>Ben
>
>-----Original Message-----
>From: Srinadh Karumuri [mailto:skarumur@bbn.com]
>Sent: Tuesday, May 10, 2005 2:25 PM
>To: Benjamin.Temko@VerizonWireless.com
>Subject: RE: returning arrays of custom java objects
>
>Ben,
>Thanks for sharing the code. I am trying your way, with the TypeMapping.....
>Could you tell me how you initiated the service = new Service(.....,...);
>wsdlUrl - is the location of the file.
>qn - qname I am doing qname = new QName("EmployeeDataService");
>which I am unable to set and keep getting the error:
>         javax.xml.rpc.ServiceException: Cannot find 
> service:  EmployeeDataService
>
>-Sri
>>
>
>
>___________________________________________________________________
>The information contained in this message and any attachment may be
>proprietary, confidential, and privileged or subject to the work
>product doctrine and thus protected from disclosure.  If the reader
>of this message is not the intended recipient, or an employee or
>agent responsible for delivering this message to the intended
>recipient, you are hereby notified that any dissemination,
>distribution or copying of this communication is strictly prohibited.
>If you have received this communication in error, please notify me
>immediately by replying to this message and deleting it and all
>copies and backups thereof.  Thank you.
>

Mime
View raw message