Generic Fault Handling - JBoss Issue Tracker

hungryhorsecabinSoftware and s/w Development

Dec 14, 2013 (3 years and 9 months ago)

90 views

Generic Fault Handling
The JAX-WS specification defines two type of faults.One is a generic JAX-WS runtime exception.The other is
a protocol specific class of exceptions that is thrown during message processing.
Runtime Faults.......................................................................................................................2
Protocol Faults........................................................................................................................3
1
Draft
Runtime Faults
Overview
Most of the JAX-WS APIs throw a generic
javax.xml.ws.WebServiceException exception.
APIs that throw
WebServiceException
Table 1 on page 2 lists the JAX-WS APIs that can throw the generic
WebServiceException exception.
Table 1.APIs that Throw WebServiceException
ReasonAPI
There is an error in the handler chain configuration.Binding.setHandlerChain()
The specified class is not supported by the implementation.BindingProvider.getEndpointReference()
There is an error in the Dispatch instance's configuration or
an error occurred while communicating with the service.
Dispatch.invoke()
There is an error in the Dispatch instance's configuration.Dispatch.invokeAsync()
There is an error in the Dispatch instance's configuration or
an error occurred while communicating with the service.
Dispatch.invokeOneWay()
An error occurred when using a supplied JAXBContext to
unmarshall the payload.The cause field of the
LogicalMessage.getPayload()
WebServiceException contains the original
JAXBException.
An error occurred when setting the payload of the message.
If the exception is thrown when using a JAXBContext,the
LogicalMessage.setPayload()
cause field of the WebServiceException contains the
original JAXBException.
The specified class is not supported by the implementation.WebServiceContext.getEndpointReference()
2
DraftGeneric Fault Handling
Protocol Faults
Overview
Protocol exceptions are thrown when an error occurs during the processing
of a request.All synchronous remote invocations can throw a protocol
exception.The underlying cause occurs either in the consumer's message
handling chain or in the service provider.
The JAX-WS specification defines a generic protocol exception.It also specifies
a SOAP-specific protocol exception and an HTTP-specific protocol exception.
Types of protocol exceptions
The JAX-WS specification defines three types of protocol exception.Which
exception you catch depends on the transport and binding used by your
application.
Table 2 on page 3 describes the three types of protocol exception and when
they are thrown.
Table 2.Types of Generic Protocol Exceptions
When ThrownException Class
This exception is the generic protocol exception.It can be caught
regardless of the protocol in use.It can be cast into a specific fault
javax.xml.ws.ProtocolException
type if you are using the SOAP binding or the HTTP binding.When
using the XML binding in combination with the HTTP or JMS
transports,the generic protocol exception cannot be cast into a
more specific fault type.
This exception is thrown by remote invocations when using the
SOAP binding.For more information see Using the SOAP protocol
exception on page 3.
javax.xml.ws.soap.SOAPFaultException
This exception is thrown when using the FUSE Services Framework
HTTP binding to develop RESTful services.For more information
see Developing RESTful Services.
javax.xml.ws.http.HTTPException
Using the SOAP protocol
exception
The SOAPFaultException exception wraps a SOAP fault.The underlying
SOAP fault is stored in the fault field as a javax.xml.soap.SOAPFault
object.
If a service implementation needs to throw an exception that does not fit any
of the custom exceptions created for the application,it can wrap the fault in
3
Protocol FaultsDraft
a SOAPFaultException using the exceptions creator and throw it back to
the consumer.Example 1 on page 4 shows code for creating and throwing
a SOAPFaultException if the method is passed an invalid parameter.
Example 1.Throwing a SOAP Protocol Exception
public Quote getQuote(String ticker)
{
...
if(tickers.length()<3)
{
SOAPFault fault = SOAPFactory.newInstance().createFault();
fault.setFaultString("Ticker too short");
throw new SOAPFaultException(fault);
}
...
}
When a consumer catches a SOAPFaultException exception they can retrieve
the underlying cause of the exception by examining the wrapped SOAPFault
exception.As shown in Example 2 on page 4,the SOAPFault exception is
retrieved using the SOAPFaultException exception's getFault() method.
Example 2.Getting the Fault from a SOAP Protocol Exception
...
try
{
proxy.getQuote(ticker);
}
catch (SOAPFaultException sfe)
{
SOAPFault fault = sfe.getFault();
...
}
4
DraftGeneric Fault Handling