Question

I am looking to disable BSP Compliance (I dont want my message containing the elements ).

I have tried, to no avail:

OutflowConfiguration outflowConfig = new OutflowConfiguration();
outflowConfig.setBSPCompliant(false);

stub._getServiceClient().getOptions().setProperty(WSSHandlerConstants.OUTFLOW_SECURITY, outflowConfig.getProperty());

Does anyone else know of a way to remove the element(s) from my outgoing SOAP Message in Axis2/Rampart?

Was it helpful?

Solution

I figured out I can setup a new outgoing phase (via axis2.xml), which passes in a MessageContext to my customer Handler, and then I can get the SOAPEnvelope/Header via the MessageContext, traverse the elements and nodes, find the element(s) I want to remove, and then call removeChild.

For outgoing (OutFlow) Axis2 messages, WSS(4J) signing seems to happen in the "Security" Phase.

<phase name="Security"/>

So, I wanted to remove some XML Elements that got appended in the Security Phase. Specifically, the "ec:InclusiveNamespaces" elements. It seems to be from XML Exclusive Canonicalization, and I couldn't figure out any other way to disable this setting in WSS4J (apart from Re-Compiling Axis2/Rampart...)

So, we need to add our own, new, custom OutFlow Handler. After the Security Phase.

<phase name="PostSecurity">
        <handler name="MyOutHandler" class="com.yourcompany.YourSoapHandler"/> 
</phase>

Next, make your Custom Handler Class :

package com.yourcompany;

public class YourSoapHandler extends AbstractHandler {

    public InvocationResponse invoke(MessageContext ctx) throws AxisFault {

        SOAPEnvelope msgEnvelope = ctx.getEnvelope();
        SOAPHeader msgHeader = msgEnvelope.getHeader();

        Iterator theDescendants = msgHeader.getDescendants(true);
        while(theDescendants.hasNext()){

            Object o = theDescendants.next();

            if(o instanceof org.apache.axiom.om.impl.dom.ElementImpl){

                ElementImpl ele = (ElementImpl)o;
                String eleNodeName = ele.getNodeName();

                if("ds:CanonicalizationMethod".equals(eleNodeName) || "ds:Transform".equals(eleNodeName)){
                    Node aNode = ele.getElementsByTagName("ec:InclusiveNamespaces").item(0);
                    if(aNode != null){
                        ele.removeChild(aNode);
                    }
                }
            }
        }
        return InvocationResponse.CONTINUE;
    }
}

As long as you're passing in your updated Axis2.xml into your ConfigurationContext, which then gets passed into your service stub, you should be good to go.

Here are some references I used for learning about phases: http://www.packtpub.com/article/handler-and-phase-in-apache-axis http://wso2.com/library/777/

I hope this helps at least one other person out =D

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top