axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Balakrishna, Vandana (Cognizant)" <Vanda...@pun.COGNIZANT.COM>
Subject RE: Re: How to get bean data in client?
Date Thu, 10 Apr 2003 04:44:41 GMT
Hi Ranjith,

Similar to your requirement, we need to throw an application specific exception and pass a
hashmap in it. But since we couldn't find out how to do that...we resorted to passing the
values of the hashmap in the FaultDetail field as xml elements.

Please tell me how you managed to send your embedded bean in your custom exception? That would
save us the xml parsing required to retrieve the values and reconstruct the hashmap at the
client end.

regards,
Vandana. 

-----Original Message-----
From: PILLAI,RANJITH (HP-PaloAlto,ex1) [mailto:ranjith.pillai@hp.com]
Sent: Thursday, April 10, 2003 5:09 AM
To: 'axis-user@ws.apache.org'
Subject: RE: Re: How to get bean data in client?


Hi Thomas and Oliver,

Thanks for your reply again. Finally I got a work around for my problem.
The problem was with namespace.
Please let me know if you guys need more info about it.

Oliver... I prefer not to put any AxisFault code into my service
implemention. Please let me know if you need any help, I am throwing Custom
Java Exceptions with embedded bean and able to extract data properly at
client side.

Thanks again,
Ran

-----Original Message-----
From: Thomas.Rothfuss@homag.de [mailto:Thomas.Rothfuss@homag.de] 
Sent: Wednesday, April 09, 2003 2:57 AM
To: axis-user@ws.apache.org
Subject: Antwort: Re: How to get bean data in client?


Hi Ran,

let me show you my whole scenario. I use my own example, but it's similar
to yours.

Here are the relevant parts of the wsdl file:


<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:WDC_ServerSoap" xmlns
="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap
="http://xml.apache.org/xml-soap" xmlns:impl="urn:WDC_ServerSoap"
xmlns:intf="urn:WDC_ServerSoap" xmlns:soapenc
="http://schemas.xmlsoap.org/soap/encoding/" 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:WDC_ServerSoap" xmlns
="http://www.w3.org/2001/XMLSchema">
   <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
   <complexType name="ExceptionData">
    <sequence>
     <element name="Number" type="xsd:int"/>
     <element name="IsNlsText" type="xsd:boolean"/>
     <element name="Text" nillable="true" type="xsd:string"/>
     <element name="FilledText" nillable="true" type="xsd:string"/>
     ....
    </sequence>
   </complexType>
   <complexType name="WdcServerException">
    <sequence>
     <element maxOccurs="unbounded" name="Data" nillable="true" type
="impl:ExceptionData"/>
    </sequence>
   </complexType>
  </schema>
 </wsdl:types>
...
   <wsdl:message name="WdcServerException">
      <wsdl:part name="fault" type="impl:WdcServerException"/>
   </wsdl:message>
...
   <wsdl:portType name="SoapInterfaceOperations">
      <wsdl:operation name="getValue" parameterOrder="in0">
         <wsdl:input message="impl:getValueRequest" name
="getValueRequest"/>
         <wsdl:output message="impl:getValueResponse" name
="getValueResponse"/>
         <wsdl:fault message="impl:WdcServerException" name
="WdcServerException"/>
      </wsdl:operation>
...
   </wsdl:portType>
...
   <wsdl:binding name="WDC_ServerSoapSoapBinding" type
="impl:SoapInterfaceOperations">
      <wsdlsoap:binding style="rpc" transport
="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="getValue">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="getValueRequest">
            <wsdlsoap:body encodingStyle
="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:WDC_ServerSoap"
use="encoded"/>
         </wsdl:input>
         <wsdl:output name="getValueResponse">
            <wsdlsoap:body encodingStyle
="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:WDC_ServerSoap"
use="encoded"/>
         </wsdl:output>
         <wsdl:fault name="WdcServerException">
            <wsdlsoap:fault encodingStyle
="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:WDC_ServerSoap"
use="encoded"/>
         </wsdl:fault>
      </wsdl:operation>
...
   </wsdl:binding>
   <wsdl:service name="SoapInterfaceOperationsService">
      <wsdl:port binding="impl:WDC_ServerSoapSoapBinding" name
="WDC_ServerSoap">
         <wsdlsoap:address location
="http://localhost:8080/axis/services/WDC_ServerSoap"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>


Here's the wsdd file:

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

      <!-- Services from SoapInterfaceOperationsService WSDL service -->

      <service name="WDC_ServerSoap" provider="java:RPC" style="rpc" use
="encoded">
          <parameter name="wsdlTargetNamespace" value
="urn:WDC_ServerSoap"/>
          <parameter name="wsdlServiceElement" value
="SoapInterfaceOperationsService"/>
          <parameter name="wsdlServicePort" value="WDC_ServerSoap"/>
          <parameter name="className" value
="Homag.WoodCommander.WDC_Server.Soap.WDC_ServerSoapSoapBindingSkeleton"/>
          <parameter name="wsdlPortType" value="SoapInterfaceOperations"/>
          <parameter name="allowedMethods" value="*"/>
          <parameter name="scope" value="Session"/>

          <typeMapping
            xmlns:ns="urn:WDC_ServerSoap"
            qname="ns:ExceptionData"
            type="java:Homag.WoodCommander.WDC_Server.Soap.ExceptionData"
            serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
            deserializer
="org.apache.axis.encoding.ser.BeanDeserializerFactory"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
          />
          <typeMapping
            xmlns:ns="urn:WDC_ServerSoap"
            qname="ns:WdcServerException"
            type
="java:Homag.WoodCommander.WDC_Server.Soap.WdcServerException"
            serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
            deserializer
="org.apache.axis.encoding.ser.BeanDeserializerFactory"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
          />
      </service>
    </deployment>


I use the WSDL2Java Tool to generate the classes, e.g.
WdcServerException.java and ExceptionData.java
The creation of the SOAPServer Exception looks like this:

        Homag.WoodCommander.WDC_Server.Soap.ExceptionData[] exceptionDatas
= new Homag.WoodCommander.WDC_Server.Soap.ExceptionData[cntExceptions];
        int i = 0;
        for (; i < cntExceptions; ++i) {
            Homag.WoodCommander.WDC_Server.Soap.ExceptionData exceptionData
= new Homag.WoodCommander.WDC_Server.Soap.ExceptionData();
            exceptionData.setNumber(e1.Data[i].Number);
            exceptionData.setIsNlsText(e1.Data[i].IsNlsText);
            exceptionData.setText(e1.Data[i].Text);
            exceptionData.setFilledText(e1.Data[i].FilledText);
            exceptionData.setSourceFunction(e1.Data[i].SourceFunction);
            exceptionData.setSourceFileName(e1.Data[i].SourceFileName);
            exceptionData.setSourceLineNumber(e1.Data[i].SourceLineNumber);
            exceptionData.setFillingWords(e1.Data[i].FillingWords);
            exceptionData.setCategory(e1.Data[i].Category);
            exceptionData.setPriority(e1.Data[i].Priority);

            exceptionDatas[i] = exceptionData;
        }
        throw new Homag.WoodCommander.WDC_Server.Soap.WdcServerException
(exceptionDatas);



Within the SoapClient java file there's following code:

    try {
        call    = (Call) service.createCall();

        call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
        call.setOperationName( new QName("WDC_ServerSoap", "setup") );

        qname = new javax.xml.namespace.QName
( "http://schemas.xmlsoap.org/soap/envelope/", "Fault" );
        call.registerTypeMapping(
Homag.WoodCommander.WDC_Server.Soap.WdcServerException.class, qname,
            new org.apache.axis.encoding.ser.BeanSerializerFactory(
Homag.WoodCommander.WDC_Server.Soap.WdcServerException.class, qname ),
            new org.apache.axis.encoding.ser.BeanDeserializerFactory(
Homag.WoodCommander.WDC_Server.Soap.WdcServerException.class, qname ) );
        qname = new javax.xml.namespace.QName( "urn:WDC_ServerSoap",
"WdcServerException" );
        call.registerTypeMapping(
Homag.WoodCommander.WDC_Server.Soap.WdcServerException.class, qname,
            new org.apache.axis.encoding.ser.BeanSerializerFactory(
Homag.WoodCommander.WDC_Server.Soap.WdcServerException.class, qname ),
            new org.apache.axis.encoding.ser.BeanDeserializerFactory(
Homag.WoodCommander.WDC_Server.Soap.WdcServerException.class, qname ) );
        qname = new javax.xml.namespace.QName( "urn:WDC_ServerSoap",
"ExceptionData" );
        call.registerTypeMapping(
Homag.WoodCommander.WDC_Server.Soap.ExceptionData.class, qname,
            new org.apache.axis.encoding.ser.BeanSerializerFactory(
Homag.WoodCommander.WDC_Server.Soap.ExceptionData.class, qname ),
            new org.apache.axis.encoding.ser.BeanDeserializerFactory(
Homag.WoodCommander.WDC_Server.Soap.ExceptionData.class, qname ) );

        call.setReturnType( org.apache.axis.encoding.XMLType.AXIS_VOID );
        call.invoke( new Object[] { } );
    }
    catch (Homag.WoodCommander.WDC_Server.Soap.WdcServerException e) {
      try {
          // for debugging
          //java.util.Vector bodyElements = call.getMessageContext
().getResponseMessage().getSOAPEnvelope().getBodyElements();
          //for (int i = 0; i < bodyElements.size(); ++i) {
          //   System.out.println("bodyElement[" + i + "] = " +
bodyElements.elementAt(i).toString());
          //}
          Homag.WoodCommander.WDC_Server.Soap.WdcServerException obj =
(Homag.WoodCommander.WDC_Server.Soap.WdcServerException)
((SOAPBodyElement)(bodyElements.elementAt(1))).getObjectValue();

          for (int i = 0; i < obj.getData().length; ++i) {
              Homag.WoodCommander.WDC_Server.Soap.ExceptionData data =
obj.getData(i);
              System.out.println(i + ": data.getNumber() = " +
data.getNumber());
              System.out.println(i + ": data.isIsNlsText() = " +
data.isIsNlsText());
              System.out.println(i + ": data.getText() = " + data.getText
());
              System.out.println(i + ": data.getFilledText() = " +
data.getFilledText());
              System.out.println(i + ": data.getSourceFunction() = " +
data.getSourceFunction());
              System.out.println(i + ": data.getSourceFileName() = " +
data.getSourceFileName());
              System.out.println(i + ": data.getSourceLineNumber() = " +
data.getSourceLineNumber());
             }
         }catch (org.apache.axis.AxisFault axisFault2){
         }
    }
    catch (Exception e1) {
        System.err.println(e1.toString());
    }


The SOAP Fault message looks like this:


    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv
="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd
="http://www.w3.org/2001/XMLSchema" xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance">
     <soapenv:Body>
      <soapenv:Fault>
       <faultcode>soapenv:Server.generalException</faultcode>
       <faultstring></faultstring>
       <detail>
        <ns1:fault href="#id0" xmlns:ns1="urn:WDC_ServerSoap"/>
        <ns2:exceptionName xmlns:ns2
="http://xml.apache.org/axis/">Homag.WoodCommander.WDC_Server.Soap.WdcServer
Exception</ns2:exceptionName>
        <ns3:stackTrace xmlns:ns3="http://xml.apache.org/axis/">AxisFault
     faultCode:
{http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
     faultSubcode:
     faultString:
     faultActor: null
     faultNode: null
     faultDetail:
        exceptionName:
Homag.WoodCommander.WDC_Server.Soap.WdcServerException


        at
Homag.WoodCommander.WDC_Server.Soap.WDC_ServerSoapSoapBindingImpl.convertWDC
Exception(WDC_ServerSoapSoapBindingImpl.java:36)
        at
Homag.WoodCommander.WDC_Server.Soap.WDC_ServerSoapSoapBindingImpl.setup(WDC_
ServerSoapSoapBindingImpl.java:170)
        at
Homag.WoodCommander.WDC_Server.Soap.WDC_ServerSoapSoapBindingSkeleton.setup(
WDC_ServerSoapSoapBindingSkeleton.java:178)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
        at java.lang.Thread.run(Thread.java:536)
    </ns3:stackTrace>
       </detail>
      </soapenv:Fault>
      <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle
="http://schemas.xmlsoap.org/soap/encoding/" xsi:type
="ns4:WdcServerException" xmlns:soapenc
="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns4
="urn:WDC_ServerSoap">
       <Data href="#id1"/>
       <Data href="#id2"/>
       <Data href="#id3"/>
      </multiRef>
      <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle
="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns5:ExceptionData"
xmlns:ns5="urn:WDC_ServerSoap" xmlns:soapenc
="http://schemas.xmlsoap.org/soap/encoding/">
       <Number xsi:type="xsd:int">2</Number>
       <IsNlsText xsi:type="xsd:boolean">false</IsNlsText>
       <Text xsi:type="xsd:string">Error %ld</Text>
       <FilledText xsi:type="xsd:string">Error 1</FilledText>
       <SourceFunction xsi:type
="xsd:string">sourceFunction</SourceFunction>
       <SourceFileName xsi:type
="xsd:string">SourceFileName</SourceFileName>
       <SourceLineNumber xsi:type="xsd:int">123</SourceLineNumber>
       <FillingWords xsi:type="xsd:string">2</FillingWords>
       <FillingWords xsi:type="xsd:string">2A</FillingWords>
       <Category xsi:type="xsd:int">1</Category>
       <Priority xsi:type="xsd:int">2</Priority>
      </multiRef>
      <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle
="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns6:ExceptionData"
xmlns:ns6="urn:WDC_ServerSoap" xmlns:soapenc
="http://schemas.xmlsoap.org/soap/encoding/">
       <Number xsi:type="xsd:int">1</Number>
       <IsNlsText xsi:type="xsd:boolean">false</IsNlsText>
       <Text xsi:type="xsd:string">Error %ld</Text>
       <FilledText xsi:type="xsd:string">Error 0</FilledText>
       <SourceFunction xsi:type
="xsd:string">sourceFunction</SourceFunction>
       <SourceFileName xsi:type
="xsd:string">SourceFileName</SourceFileName>
       <SourceLineNumber xsi:type="xsd:int">123</SourceLineNumber>
       <FillingWords xsi:type="xsd:string">0</FillingWords>
       <FillingWords xsi:type="xsd:string">0B</FillingWords>
       <Category xsi:type="xsd:int">1</Category>
       <Priority xsi:type="xsd:int">2</Priority>
      </multiRef>
      <multiRef id="id3" soapenc:root="0" soapenv:encodingStyle
="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns7:ExceptionData"
xmlns:ns7="urn:WDC_ServerSoap" xmlns:soapenc
="http://schemas.xmlsoap.org/soap/encoding/">
       <Number xsi:type="xsd:int">3</Number>
       <IsNlsText xsi:type="xsd:boolean">false</IsNlsText>
       <Text xsi:type="xsd:string">Error %ld</Text>
       <FilledText xsi:type="xsd:string">Error 2</FilledText>
       <SourceFunction xsi:type
="xsd:string">sourceFunction</SourceFunction>
       <SourceFileName xsi:type
="xsd:string">SourceFileName</SourceFileName>
       <SourceLineNumber xsi:type="xsd:int">123</SourceLineNumber>
       <Category xsi:type="xsd:int">1</Category>
       <Priority xsi:type="xsd:int">2</Priority>
      </multiRef>
     </soapenv:Body>
    </soapenv:Envelope>



Hope this helps you
Thomas



Mime
View raw message