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
Related
We have currently implemented SOAP endpoints with CXF (Spring Boot). In accordance with the contract-first approach, we provide a WSDL, generate Java objects, and services from it (cxf-codegen-plugin) and finally implement the service interface.
This is all very nice and simple, but we only need the SOAP XML or the corresponding DOM tree. Not only is the conversion to Java objects unnecessary, we also have to convert them back to XML and lose some information from the original XML.
As far as I understand is SAAJ (SOAP with Attachments API for Java) exactly right here, or am I missing something? At most all resources about SAAJ are quite old and "low level". I cannot find good resources for that kind of approach.
In addition, we want to implement new services as microservices soon and are currently reviewing Quarkus and Apache Camel. However, I cannot find a (simple) way to create corresponding endpoints from the WSDLs, via which we then receive the SOAP message as plain XML / DOM tree.
In jax-ws, message-level access can be accomplished on the server side using web service Provider-based endpoints, and on the client side using Dispatch clients.
A web service Provider-based endpoint offers a dynamic alternative to the Java service endpoint interface (SEI)-based endpoint. Unlike the SEI-based endpoint that abstracts the details of converting between Java objects and their XML representation, the Provider interface enables you to access the content directly at the XML message level—without the JAXB binding. web service Provider-based endpoints can be implemented synchronously or asynchronously using the javax.xml.ws.Provider or com.sun.xml.ws.api.server.AsyncProvider interfaces, respectively.
See https://cxf.apache.org/docs/provider-services.html for details
Since we know the fact that REST services can be used with SOAP ones, is there a way to intercept SOAP services using Jax-RS. I got both REST/SOAP services running in my system and I need to have some sort of interceptor to intercept the service calls. I can easily intercept the REST calls using JAX-RS but not the SOAP services.
Has anyone gone through this kind of situation, please let me know.
You can do this by exposing your SOAP web services as Camel end points. Then you can use camel to 'log the request/response as a pre/post processor'. There are lost of articles on the subject- here is an example of exposing your SOAP WS via Camel.
I have a backend system that currently returns a domain object. I want to build a REST & SOAP front end using mule. To create responses that are REST or SOAP based, and ensure that the backend is protocol agnostic, I am thinking about creating two protocol adapters (REST and SOAP). It is unclear to me if it is better to create a mule translator for the service, which understands the protocol and delegates to generate an appropriate response, or just create two class interfaces (using JAX-RS/JAX-WS annotations) to the service.
I'm not finding much literature, best practices, or design patterns on the subject. Can someone point me to some useful material or provide their opinions?
Writing transformers for message formatting would be a waste of time.
You should write service classes with JAX-RS/JAX-WS annotations, transports exist for both.
For a REST service you can use the Jersey transport:
http://www.mulesoft.org/documentation/display/JERSEY/User's+Guide
For SOAP service you can use the CXF transport (also supports JAX-RS):
http://www.mulesoft.org/documentation/display/CXF/Building+a+web+service
Note: You don't need mule for this at all, both Jersey and CXF run in a servlet container like tomcat.
I'm looking for an example of how to set up a very simple Mule configuration to route a SOAP web service call from a client to a service provider. Initially, there will just be one provider, and then I will want to add multiple service providers and a round-robin routing strategy in Mule.
Most of the examples on the Mule site have the service provider running within the Mule container. I want mine to be completely external.
If you don't need to decompose message arguments use HTTP pass-through, which is more light-weight and a lot simpler. For the round-robin implementation you could use a filter router with a groovy-based filter expression.
See here:
Create pass through with Mule ESB 2.2.1
http://www.mulesoft.org/documentation/display/MULE2USER/Outbound+Routers#OutboundRouters-Filters
I am currently using the jaxws and apache CXF framework to create webservices using the top down approach.
I am using the SOAP interceptors to add remove SOAP header elements, using SAAJ, before the message gets to the container, and the container maps the SOAP action too the java method. I am doing this to create Security Token Services (STS) to facilitate a lite implementation of the SAML2 Profile - converting authentication details into portable identities (SAML Authentication Assertions).
I cannot help think there must be an easier way to do this. Is there a framework that will allow me to manipulate the message with more ease? and if so a tutorial would help.
Many thanks
To change things in SOAP messages you must use SOAP Handlers.
Maybe easier way to do it is changing the way you are securing your web service, if you use a WS-Security way of doing things, our container will work with it fine, and you don't need the handlers anymore.