Created
October 22, 2014 06:23
-
-
Save zeroows/a1a32fa2c2fc0152b9ee to your computer and use it in GitHub Desktop.
Removing SoapAction from CXF by using InInterceptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
import java.util.Map; | |
import org.apache.commons.logging.Log; | |
import org.apache.commons.logging.LogFactory; | |
import org.apache.cxf.binding.soap.Soap11; | |
import org.apache.cxf.binding.soap.Soap12; | |
import org.apache.cxf.binding.soap.SoapMessage; | |
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor; | |
import org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor; | |
import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor; | |
import org.apache.cxf.helpers.CastUtils; | |
import org.apache.cxf.interceptor.Fault; | |
import org.apache.cxf.message.Message; | |
import org.apache.cxf.phase.Phase; | |
public class CustomSoapActionInInterceptor extends AbstractSoapInterceptor { | |
private static final Log LOG = LogFactory.getLog(CustomSoapActionInInterceptor.class); | |
public CustomSoapActionInInterceptor() { | |
super(Phase.READ); | |
addAfter(ReadHeadersInterceptor.class.getName()); | |
addAfter(EndpointSelectionInterceptor.class.getName()); | |
} | |
public void handleMessage(SoapMessage message) throws Fault { | |
if (message.getVersion() instanceof Soap11) { | |
Map<String, List<String>> headers = CastUtils.cast((Map)message.get(Message.PROTOCOL_HEADERS)); | |
if (headers != null) { | |
List<String> sa = headers.get("SOAPAction"); | |
if (sa != null && sa.size() > 0) { | |
String action = sa.get(0); | |
LOG.debug(String.format("[CustomSoapActionInInterceptor] --------- \nThe Soap Action recieved: %s", action)); | |
} | |
LOG.debug(String.format("[CustomSoapActionInInterceptor] --------- Removing SoapAction Header ")); | |
headers.remove("SOAPAction"); | |
} | |
} else if (message.getVersion() instanceof Soap12) { | |
LOG.debug("Soap12 is not supported now"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment