I have a client/server application that communicates via SOAP. The server-side application is a Java EE app that exposes web services using JAX-WS. I have a servlet filter setup to perform certain checks before a service is invoked.
This is all working pretty well, except for exception handling. If I throw an exception from the filter, it gets returned to the client as a generic server exception. I need to find a way to propagate a custom exception containing a specific message, so the client can display the message to the user.
Any insight?
A servlet filter isn't really the right tool if you want to send the exception in a SOAP response and I would consider using a JAX-WS handler for the verification of incoming messages instead (JAX-WS handlers are somehow to JAX-WS services what Filters are to Servlets).
Frmo Working with Headers in JAX-WS SOAPHandlers:
JAX-WS Handlers
In addition to support for web
services development, the JAX-WS
framework (the latest Java programming
language API for creating SOAP-based
web services and web service
consumers) also provides a handler
framework. Handlers provide a means
to inspect and manipulate incoming or
outgoing SOAP messages (on both the
client as well as server side). They
act as powerful message interceptors
that can perform an array of functions
such as message transformation,
content filtering, tracking, etc. In
fact, handlers are often used in
runtime environments to implement web
service and SOAP specifications such
as WS-Security, WS-ReliableMessaging,
etc. JAX-WS handlers are similar to
EJB interceptors or servlet filters.
Handlers, like interceptors and
filters, encourage developers to
follow the chain of responsibility
pattern.
Resources
- Writing a Handler in JAX-WS (start here)
- Handler example using JAXWS 2.0
References
- Java API for XML-Based Web Services (JAX-WS) 2.0 specification
- APIs
javax.xml.ws.handler.Handler
javax.xml.ws.handler.LogicalHandler
javax.xml.ws.handler.soap.SOAPHandler