javaweb-servicesspringsoapsoaphandler

Using Spring to configure SOAP handlers


I have a custom SOAP handler that I am using for schema validation of the SOAP messages. It works for on web service, I'd like to be able to use it for others. The code that does the validation itself is quite generic - the only real input to it is the name of the schema to use for validation. I'm mentally stuck on how/if I can use Spring to configure different instances of the SOAP handler for different services.

The web service is declared as:

@WebService(name = "MyService", ...)
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@HandlerChain(file="handler-chain.xml")
public interface MyService
{
   ....
}

The handler-chain.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
  <handler-chain>
    <handler>
      <handler-name>com.ws.MyCustomSoapHandler</handler-name>
      <handler-class>com.ws.MyCustomSoapHandler</handler-class>
    </handler>
  </handler-chain>
</handler-chains>

Inside the custom SOAP handler, I have this:

public class MyCustomSoapHandler implements SOAPHandler<SOAPMessageContext>
{
    //assume getter/setter for this.
    private String schemaLocation = "schema/validation/service1.xsd";
    @Override
    public boolean handleMessage(SOAPMessageContext context)
    {
        ...
        //This is the only place where the schema needs to vary
        schema = schemaFactory.newSchema(this.getClass().getClassLoader().getResource(schemaLocation));

I know I could use Spring to create multiple beans based on MyCustomSoapHandler and give them different values for schemaLocation, but how do I connect those beans to the correct web services in my application? Would it be through handler-chain.xml? Or would I have to do it programmatically?


Solution

  • It doesn't look like this is possible (or if it is, I can't seem to get it working) because the SOAP handlers are created by the WebSphere container, and they are not managed by Spring. So I just created an abstract handler with most of the logic and used a .properties file to configure the details that were more specific to different handlers.