Hi,

 

I post this question again, because I have not become any response. I want to know if the steps which use to throw a Fault is right. I write a interface in with two methods like:

 

1.)

public interface CUserService

{

    public boolean addUser(String pseudonym, User user) throws CUserException;

    public boolean removeUser(String pseudonym) throws CUserException;

}

 

2.) In the class CUserException I write the following:

public class CUserException extends RemoteException

{

            public  CUserException(String message)

            {

                        super(message);

}

}

 

3.)  After that I use Java2WSDL and generate my wsdl file.

4.) I use WSDL2Java to generate the client and server stubs. I see that in the wsdd file is an entry like:

 

<typeMapping

        xmlns:ns="http://exception.confuoco"

        qname="ns:CUserException"

        type="java:confuoco.exception.CUserException"

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

        deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

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

      />

5.) Then I deploy the service.

5.) I see that my CUserException class was overwritten by WSDL2Java.

6.) I write in my CUserServiceSoapBindingImpl a “if else” to test the fault like:

 

public boolean addUser(java.lang.String pseudonym, confuoco.webservice.User user) throws confuoco.exception.CUserException {

       

            if(user != null)

            {

                        System.out.println("User is not null");

            }

            else

            {

                        System.out.println("User is null ");

                        CUserException cue = new CUserException();

                        cue.setFaultString("User object is null ");

                        throw cue;

            }

           

            return false;

    }

 

7.) on the Client side I catch the Axis Fault with:

 

try

                        {

                                  

                                   CUserServiceServiceLocator locator = new CUserServiceServiceLocator();

                                   CUserService cUserService = locator.getCUserService();

                                   User user = null;

                                   cUserService.addUser("Test", null);

                                              

                        }

                       

                        catch(ServiceException se)

                        {

                                   se.printStackTrace();

                        }

                        catch(AxisFault af)

                        {

                                   System.out.println("AXisFault: " + af.getFaultString());

                                  

                        }

 

Console:

Ouput: User object is null.

 

 

Is that the right way to throw a Fault and catch???? If  I use cue.setMessage ("User object is null "); instead cue.setFaultString("User object is null "); and want to catch it on the client side I become for the result not the string a null object is returned?

 

 

Thanks for any help.

 

Regards

Ferruh

 

 

Reply via email to