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 Jiang Liu <j....@student.rmit.edu.au> on 2007/03/27 06:13:22 UTC

[Axis2]personalized exceptions

Hi experts,
In my service, i want to throw my personalized exception(s) except AxisFault, Suppose i have a Bookshop service, here is my service skeleton:

public class BookshopServiceSkeleton{
/**
* Auto generated method signature
* @param param0
*/
public bookshop.org.xsd.HelloBookshopResponseDocument helloBookshop (bookshop.org.xsd.HelloBookshopDocument param0) throws HelloBookshopFaultException{
//Todo fill this with the necessary business logic
//throw new java.lang.UnsupportedOperationException("Please implement " + this.getClass().getName() + "#helloBookshop");
System.out.println("Bookshop test method receives client call!");
System.out.println("client sent: " + param0.getHelloBookshop().getName() + =
", and " + param0.getHelloBookshop().getFactor());
if(param0.getHelloBookshop().getFactor() == 100) {
throw new HelloBookshopFaultException("Server got factor as:" + param0.getH=
elloBookshop().getFactor() + " and throws this exception!");
}
else {
bookshop.org.xsd.HelloBookshopResponseDocument resDoc = bookshop.org.xsd.=
HelloBookshopResponseDocument.Factory.newInstance();
bookshop.org.xsd.HelloBookshopResponseDocument.HelloBookshopResponse res = resDoc.addNewHelloBookshopResponse();
res.setReturn("Hello " + param0.getHelloBookshop().getName());
return resDoc;
}
}
}

The logic is pretty simple: if received factor is 100, throw my own "HelloBookshopFaultException".

My generated WSDL file successfully covered the fault message:
<wsdl:definitions targetNamespace=3D"http://org.bookshop">
...
<wsdl:types>
<xs:schema attributeFormDefault="qualified" ...>
<xs:element name="helloBookshopFault">
<xs:complexType>
<xs:sequence>
<xs:element name="helloBookshopFault" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
...
<wsdl:message name="helloBookshopFault">
<wsdl:part name="part1" element="ns:helloBookshopFault"/>
</wsdl:message>
<wsdl:portType name="BookshopServicePortType">
<wsdl:operation name="helloBookshop">
<wsdl:input message="axis2:helloBookshopMessage" .../>
<wsdl:output message="axis2:helloBookshopResponseMessage" .../>
<wsdl:fault message="axis2:helloBookshopFault" name="helloBookshopFault" .../>
</wsdl:operation>
</wsdl:portType>
...
</definitions>

My client stub files include BookshopServiceStub and HelloBookshopFaultExce=
ption. Here is my sample Client class:
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
BookshopServiceStub stub = new BookshopServiceStub();
HelloBookshopDocument reqDoc = HelloBookshopDocument.Factory.newInstance();
HelloBookshopDocument.HelloBookshop req =  reqDoc.addNewHelloBookshop();

java.util.Scanner sc =3D new java.util.Scanner(System.in);
System.out.println("Name is hard-coded, just input failing factor: ");
req.setName("My Name");
req.setFactor(sc.nextInt());
try {
HelloBookshopResponseDocument resDoc =3D3D stub.helloBooksho(reqDoc);
System.out.println(resDoc.getHelloBookshopResponse().getReturn());
}
catch(bookshop.org.HelloBookshopFaultException e) {
e.getFaultMessage();
}
}
catch(Exception e) {
e.printStackTrace();
}
}

All procedures were using xmlbeans. here is my execution result:

C:\Documents and Settings\Desktop\Exp_Bookshop\client\build\classes>java
-Djava.ext.dirs=3D3Dh:\lib bookshop.org.Client
Name is hard-coded, just input failing factor:
100

org.apache.axis2.AxisFault: java.lang.NullPointerException
at org.apache.axis2.description.OutInAxisOperationClient.send(OutIn=3D
AxisO
peration.java:271)
at org.apache.axis2.description.OutInAxisOperationClient.execute(Ou=3D
tInAx
isOperation.java:202)
at bookshop.org.BookshopServiceStub.helloBookshop(BookshopServiceStub.java:=
157)
at bookshop.org.Client.main(Client.java:22)

The question is how can I get myself defined HelloBookshopFaultException and its contents but not any AxisFault or NullPointerException? I have read this article: http://wso2.org/library/171, but i don't think it covers my intentions.

Regards

=======================

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