axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "robert lazarski" <robertlazar...@gmail.com>
Subject Re: [axis2] UserExceptions and WSDL
Date Thu, 22 Jun 2006 00:56:34 GMT
I'll try and help, though I'm not a fan of faults. Typically I use
error codes and put the stack trace as a string. That's reflected in
the following WSDL, which also for demonstration defines a fault:

<?xml version="1.0" encoding="UTF-8"?>

<definitions name="SimpleService" targetNamespace="http://simpleNS"
xmlns:tns="http://simpleNS" xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:ns2="http://simpleNS/types"
xmlns:customfault="http://www.example.com/wsdl/2006-06-13/customfault">

  <types>
    <schema targetNamespace="http://simpleNS/types"
xmlns:tns="http://simpleNS/types"
xmlns:soap11-enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://www.w3.org/2001/XMLSchema">
      <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
      <element name="simpleLogin">
        <complexType>
          <sequence>
            <element name="user_name" type="xsd:string"/>
            <element name="user_password" type="xsd:string"/>
          </sequence>
        </complexType>
      </element>
      <element name="simpleLoginResponse">
        <complexType>
          <sequence>
            <element name="soap_session_id" type="xsd:string"/>
            <element name="web_user_name" type="xsd:string"/>
          </sequence>
        </complexType>
      </element>
      <element name="myFault" type="xsd:string"/>
    </schema>
  </types>
  <message name="SimpleEndpoint_simpleLogin">
     <part name="parameters" element="ns2:simpleLogin"/>
  </message>
  <message name="SimpleEndpoint_simpleLoginResponse">
    <part name="result" element="ns2:simpleLoginResponse"/>
  </message>
  <message name="MyFault">
     <part name="faultDetail" element="ns2:myFault"/>
  </message>
  <portType name="SimpleEndpoint">
    <operation name="simpleLogin">
      <input message="tns:SimpleEndpoint_simpleLogin"
name="SimpleEndpoint_simpleLogin"/>
      <output message="tns:SimpleEndpoint_simpleLoginResponse"
name="SimpleEndpoint_simpleLoginResponse"/>
      <fault name="MyFault" message="tns:MyFault"/>
    </operation>
  </portType>
  <binding name="SimpleEndpointBinding" type="tns:SimpleEndpoint">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document"/>
    <operation name="simpleLogin">
      <soap:operation soapAction="simpleLogin"/>
      <input name="SimpleEndpoint_simpleLogin">
        <soap:body use="literal"/>
      </input>
      <output name="SimpleEndpoint_simpleLoginResponse">
        <soap:body use="literal"/>
      </output>
      <fault name="MyFault">
           <soap:fault name="MyFault" use="literal"/>
      </fault>
    </operation>
  </binding>
  <service name="SimpleService">
    <port name="SimpleEndpointPort" binding="tns:SimpleEndpointBinding">
      <soap:address
location="http://localhost:8080/axis2/services/SimpleService"/></port></service></definitions>


Using xmlbeans, that results in:

**
     * SimpleServiceSkeleton.java
     *
     * This file was auto-generated from WSDL
     * by the Apache Axis2 version: SNAPSHOT Jun 20, 2006 (11:24:21 GMT+00:00)
     */
    package org.simple.endpoint;
    /**
     *  SimpleServiceSkeleton java skeleton for the axisService
     */
    public class SimpleServiceSkeleton{


        /**
         * Auto generated method signature

          * @param param0

         */
        public  simplens.types.SimpleLoginResponseDocument simpleLogin
                  (simplens.types.SimpleLoginDocument param0 )

           throws org.simple.endpoint.SimpleServiceSkeleton.MyFaultException{
                //Todo fill this with the necessary business logic
                throw new  java.lang.UnsupportedOperationException();
        }

         public static class MyFaultException extends java.rmi.RemoteException{

            private simplens.types.MyFaultDocument faultMessage;

            public void setFaultMessage(simplens.types.MyFaultDocument msg){
               faultMessage = msg;
            }

            public simplens.types.MyFaultDocument getFaultMessage(){
               return faultMessage;
            }
         }

    }

The way I would normally handle exceptions would be a slight change to
the wsdl:

<complexType name="ReturnWebBase">
        <sequence>
          <element name="errorMessage" type="xsd:string"/>
          <element name="successErrorCode" type="xsd:int"/>
        </sequence>
      </complexType>

<element name="simpleLoginResponse">
        <complexType>
          <complexContent>
            <extension base="tns:ReturnWebBase">
              <sequence>
                <element name="soap_session_id" type="xsd:string"/>
                <element name="web_user_name" type="xsd:string"/>
              </sequence>
            </extension>
          </complexContent>
        </complexType>
      </element>

try {
   ...
} catch (Exception ex) {
            retElement.setErrorMessage(ex.getMessage());
            retElement.setSuccessErrorCode(MessagesCodes.FAILURE);
        }

HTH,
Robert
http://www.braziloutsource.com/

On 6/21/06, studium-sbr@web.de <studium-sbr@web.de> wrote:
> Sorry for bringing this up again, but nobody answered.
> Any hints ?
>
> > Hi,
> >
> > I have a service implementation, that is NOT generated by WSDL2Java. It is just
simple Java-classes.
> > There I have some methods, that can throw my own UserExceptions.
> >
> > To put some helpful response back to the client, I manually create my SOAPFaults
and put them on the incoming MessageContext, then throwing an AxisFault. Chinthaka was so
kind to describe that on:
> > http://www.wso2.net/kb/171
> >
> > So shortly, how it looks like:
> >
> > ------ Service imlementation ------
> > ....
> >
> > public OMElement myMethod(OMElement input) throws AxisFault {
> >    try {
> >        // do what the service should do
> >        throw new MyUserException("message", originalException);
> >    }
> >    catch ( (Exception e) {
> >       // build the SOAPFault with all the details
> >       // put it on the MC
> >       // throw new AxisFault("some errortext");
> >   }
> > }
> >
> > --------- MYUserExcption -----------
> > public class MyUserException extends RemoteException {
> >
> >               public MyUserException(String message, Throwable ex){
> >                       super(message, ex);
> >               }
> > }
> >
> >
> > I suggest, if I generate a WSDL-File from this code, there would not appear MyUserException
in a faultmessage.
> > I have to admit, I haven't tried it so far.
> > My questions:
> > - Is this the right way to use UserExceptions?
> > - How can I achieve the Userexceptions been represented in the WSDL-file?
> >
> > Maybe someone could provide an example?!
> >
> > Thanks in advance for your time
> >
> > Bille
> >
>
>
> ______________________________________________________________
> Verschicken Sie romantische, coole und witzige Bilder per SMS!
> Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Mime
View raw message