views:

139

answers:

1

I have a client/server application that communicates via SOAP. The server-side application is a JEE 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?

Thanks in advance.

+3  A: 

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

References

Pascal Thivent
Right, he was after all using the wrong tools. That clears up everything.
BalusC
@BalusC At least, I think so.
Pascal Thivent
@Pascal Nice Explanation.
org.life.java
Thanks! I'm going to try this out.