JAX-WS servlet filter exceptions

2019-07-21 03:31发布

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?

1条回答
等我变得足够好
2楼-- · 2019-07-21 03:33

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

查看更多
登录 后发表回答