Hi all
I'm developing a proyect with axis2 and now i'm trying the server throws an
exception to the clients. I'm having lots of problems with it so i've written a
small example but it doesn't work too.
The problem is that the server, instead of throwing the exception captures it
or if the server doesn't capture it the client receives a remoteexception. Here
is my code and thanks for the help.
Adrián
Server side
package ws.example;
public class Server{
public void llamada()throws MyException{
final MyException miprueba=new MyException(2,"Esto es una prueba");
throw miprueba;
}
package ws.example;
public class MyException extends java.lang.Exception {
private int errorCode;
private String errorDescription;
public MyException(int errorCode, String errorDescription) {
this.errorCode = errorCode;
this.errorDescription = errorDescription;
}
public int getErrorCode(){
return errorCode;
}
public String getErrorDescription(){
return errorDescription;
}
}
Client side
package client;
import client.ServerStub.*;
import org.apache.axis2.AxisFault;
import java.rmi.RemoteException;
public class Cliente {
public static void main(String[] args) {
ServerStub stub=null;
try{
stub=new ServerStub();
}catch(AxisFault e){
}
try{
stub.llamada();
}catch(client.MyException e){
System.out.println(e.getFaultMessage().getMyException().getErrorDescription());
}catch(RemoteException ex){
ex.printStackTrace();
System.out.println("Bad news");
}catch(java.lang.Exception fault){
System.out.println(fault.getCause().toString());
}
}
}
The wsdl was generated with java2wsdl, but i've tried with java2wsdl and i've
obtained the same result.
<?xml version="1.0" encoding="UTF-8"?>
xmlns:axis2="http://example.ws"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:ns0="http://example.ws/xsd"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:ns1="http://org.apache.axis2/xsd"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:stns="java:WS.exception"
targetNamespace="http://example.ws">
<wsdl:types>
attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://example.ws/xsd">
<xs:element name="MyException" type="xsd:MyException" />
<xs:complexType name="MyException">
<xs:sequence>
<xs:element name="errorCode"
type="xs:int" />
<xs:element name="errorDescription"
nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="llamadaRequest" />
<wsdl:message name="llamadaResponse" />
<wsdl:message name="MyException">
<wsdl:part name="parameters" element="ns0:MyException" />
</wsdl:message>
<wsdl:portType name="ServerPortType">
<wsdl:operation name="llamada">
<wsdl:input message="axis2:llamadaRequest"
wsaw:Action="urn:llamada" />
<wsdl:output message="axis2:llamadaResponse"
wsaw:Action="urn:llamadaResponse" />
<wsdl:fault message="axis2:MyException" name="MyException"
wsaw:Action="urn:MyException" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServerSOAP11Binding"
type="axis2:ServerPortType">
style="document" />
<wsdl:operation name="llamada">
<soap:operation soapAction="urn:llamada" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="MyException">
<soap:fault use="literal" name="MyException" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ServerSOAP12Binding"
type="axis2:ServerPortType">
style="document" />
<wsdl:operation name="llamada">
<soap12:operation soapAction="urn:llamada" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
<wsdl:fault name="MyException">
<soap12:fault use="literal" name="MyException" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ServerHttpBinding"
type="axis2:ServerPortType">
<http:binding verb="POST" />
<wsdl:operation name="llamada">
<http:operation location="Server/llamada" />
<wsdl:input>
<mime:content type="text/xml" part="llamada" />
</wsdl:input>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Server">
<wsdl:port name="ServerSOAP11port_http"
binding="axis2:ServerSOAP11Binding">
<soap:address
location="http://localhost:8080/axis2/services/Server" />
</wsdl:port>
<wsdl:port name="ServerSOAP12port_http"
binding="axis2:ServerSOAP12Binding">
<soap12:address
location="http://localhost:8080/axis2/services/Server" />
</wsdl:port>
<wsdl:port name="ServerHttpport"
binding="axis2:ServerHttpBinding">
<http:address
location="http://localhost:8080/axis2/services/Server" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Thanks again.
______________________________________________
¿Con Mascota por primera vez? Sé un mejor Amigo. Entra en Yahoo! Respuestas
http://es.answers.yahoo.com/info/welcome