participate


Java Technologies for Web Services - Throwing Exceptions in WebServices
This question is answered.

<<   Back to Forum  |   Give us Feedback
This topic has 2 replies on 1 page.
DnlCYan
Posts:7
Registered: 9/19/07
Throwing Exceptions in WebServices   
Jun 21, 2008 4:56 AM
 
 
Hi
I'm implementing a webservice server that throws logical exceptions to others tiers.
My exception HelloException extends RuntimeException.
And I'm doing something like this in the server:

@Stateless(name = "Hello")
@WebService(serviceName = "GreeterService")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL)
public class HelloBean implements HelloLocal {
private String message = new String("Hello, Oi,");

public HelloBean() {
}

@WebMethod(operationName = "sayHelloOp")
@WebResult(name="resultado")
public String sayHello(@WebParam(name = "nome", mode = WebParam.Mode.IN)
String name) {
throw new HelloException("nao nao");
}

What I get in client side is this ServerException:

start fault message:
Internal Server Error (Caught exception while handling request: oracle.oc4j.rmi.OracleRemoteException: pt.sef.webservice.test
ing.HelloException: nao nao; nested exception is:
pt.sef.webservice.testing.HelloException: nao nao)
:end fault message


What I would like is to just get my exception with message "nao nao" or at least an exception just with the message. And not the encapsulation of Internal Server Error

How can I do it?

I'm using oracle AS, and EJB3.0 annotations
 
DnlCYan
Posts:7
Registered: 9/19/07
Re: Throwing Exceptions in WebServices   
Jun 21, 2008 5:01 AM (reply 1 of 2)  (In reply to original post )
 
 
I also encapsulate my exception in SOAPFaultException. Change server to this:

try{
        throw new HelloException("nao nao");
        }catch(HelloException e){
            throw new SOAPFaultException(null, 
                                  e.getMessage(), null, null);
        }


but similar response in the client was received:

start fault message:
Internal Server Error (Caught exception while handling request: oracle.oc4j.rmi.OracleRemoteException: javax.xml.rpc.soap.SOA
PFaultException: nao nao; nested exception is:
javax.xml.rpc.soap.SOAPFaultException: nao nao)
:end fault message

Any ideas?
 
DnlCYan
Posts:7
Registered: 9/19/07
Re: Throwing Exceptions in WebServices   
Jun 23, 2008 3:42 AM (reply 2 of 2)  (In reply to #1 )
 
 
Hi,

Found my own solution:D

I have to define explicitly an endpointInterface throwing my exception HelloException

Although I couldn't use SOAPFaultException (seems it has some sort of problem generating \SOAPFaultException__LiteralSerializer.java)
Neither a RuntimeException

And beside throwing my HelloException, one might note that I also set throwing RemoteException in the method in the remote interface. This will clear an warning shown in compilation time.

So my solution goes like this:

pt.sef.webservice.testingHelloBean
@Stateless(name = "Hello")
@WebService(endpointInterface="pt.sef.webservice.testing.HelloBeanRemote")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL)
public class HelloBean implements HelloLocal, HelloBeanRemote {
 
    public HelloBean() {
    }
 
    @WebMethod(operationName = "sayHelloOp")
    @WebResult(name = "resultado")
    public String sayHello(@WebParam(name = "nome", mode = WebParam.Mode.IN)
        String name) throws HelloException{
            throw new HelloException("nao nao");
        }
    }


pt.sef.webservice.testing.HelloBeanRemote
@javax.ejb.Remote
@WebService(serviceName = "GreeterService")
public interface HelloBeanRemote extends java.rmi.Remote{
    @WebMethod(operationName = "sayHelloOp")
    @WebResult(name = "resultado")
    public String sayHello(@WebParam(name = "nome", mode = WebParam.Mode.IN)
        String name) throws HelloException, RemoteException;
}


pt.sef.webservice.testing.HelloException
public class HelloException extends Exception{
    public HelloException() {
    }
    
    public HelloException(String msg){
        super(msg);
    }
}



Response found in client was exacly my exception:
client.proxy.HelloException | LocalizedMessage:nao nao | Message:nao nao | Cause:null | Stack:[Ljava.lang.StackTraceElement;@19cb082
 
This topic has 2 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums