开发者

Axis2: Disable MustUnderstand Header Check

I'm writing a web service using the Axis2 framework. The service is going to act as a proxy in a DMZ. It is really just a relay to the real service which is in our local lan.

The service uses headers which have the mustUnderstand flag set. But since the proxy service is rather simple, it cannot understand these headers, it is just supposed to relay the request into our lan, where all headers can be processed.

The probl开发者_C百科em is, that Axis2 checks the headers and throws a fault, since the module which normally reads and understands the header is not present.

Is there a way to configure Axis2 so, that it does ignore the mustUnderstand flag?

Alternatively a way to handle that from code would be apreciated too.


We had to do something similar, so this should get you close to what you want.

What you need is an org.apache.axis2.handlers.AbstractHandler

In the Invoke(MessageContext msgContext) function, you can do something like this

SOAPHeader header = msgContext.getEnvelope().getHeader();
if( header != null )
{
    Iterator<?> blocks = soapHeader.examineAllHeaderBlocks();
    while( blocks.hasNext() )
    {
        SOAPHeaderBlock block = (SOAPHeaderBlock)blocks.next();
        if( ... some check to see if this is one of your headers ... )
            block.setProcessed();
    }
}


What i did, based on the response of @karoberts is:

  • Modify the "Inflow" section in axis2.xml and add the following

    <phase name="PreDispatch">
        <handler name="WSQinHandler"
                 class="com.qin.utils.post.WSQinHandler"/>
    </phase>
    
  • Create a new class with the name of the handler. the magic comes with SOAPBlock object that have the setMustUnderstand. When this method is set to false, Axis don't check the header.

    package com.qin.utils.post;
    
    import java.util.Iterator;
    import org.apache.axiom.soap.SOAPEnvelope;
    import org.apache.axiom.soap.SOAPHeader;
    import org.apache.axiom.soap.SOAPHeaderBlock;
    import org.apache.axis2.AxisFault;
    import org.apache.axis2.context.MessageContext;
    import org.apache.axis2.handlers.AbstractHandler;
    
    public class WSQinHandler extends AbstractHandler {
    
        @Override
        public InvocationResponse invoke(MessageContext ctx) throws AxisFault {
    
            SOAPEnvelope envelop = (SOAPEnvelope) ctx.getEnvelope(); 
            SOAPHeader header = envelop.getHeader();
            if( header != null )
            {
                Iterator<?> blocks = header.examineAllHeaderBlocks();
                while( blocks.hasNext() )
                {
                    SOAPHeaderBlock block = (SOAPHeaderBlock)blocks.next();
                    block.setMustUnderstand(false);
                }
            }
            return InvocationResponse.CONTINUE;
        }
    
    }
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜