Hello,

I managed to fixe the problem by overriding the addHeader function of 
org.apache.axis2.client.Stub

By default, Axis2 will not create the mustUnderstand attribute (as Amila 
says). This is controlled by SOAPHeaderBlock.
Now, SOAPHeaderBlock says that it will create the mustUnderstand attribute 
if this one has been previously
set to true or false. So basically, if one doesn't set the attribute, 
nothing should happen. Unfortunately,
the org.apache.axis2.client.Stub class (in particular, the addHeader 
method) makes a call to setMustUnderstand everytime, even if
one does never sets the attribute. So whatever the configuration you set, 
the mustUnderstand attribute
will appear (as far as I can understand, I may be wrong here).

So my << fix >> is to never call the setMustUnderstand unless one 
explicitely wants the "true" value. 

Here's the code :



// AlineBackendServiceStub is the stub generated by Wsdl2Java, I just 
extend it to replace the addHeader method

public class MyStub extends AlineBackendServiceStub {

    protected void addHeader(OMElement omElementToadd, SOAPEnvelope 
envelop, boolean mustUnderstand)
    {
        SOAPHeaderBlock soapHeaderBlock = 
envelop.getHeader().addHeaderBlock(omElementToadd.getLocalName(), 
omElementToadd.getNamespace());
 
        // My fix. 
        if(mustUnderstand) {
            soapHeaderBlock.setMustUnderstand(mustUnderstand);
        }
 
        OMNode omNode = null;
        for(Iterator iter = omElementToadd.getChildren(); iter.hasNext(); 
soapHeaderBlock.addChild(omNode))
            omNode = (OMNode)iter.next();

        OMAttribute omatribute = null;
        for(Iterator iter = omElementToadd.getAllAttributes(); 
iter.hasNext(); soapHeaderBlock.addAttribute(omatribute))
            omatribute = (OMAttribute)iter.next();

    }
 
 
 
Stefan.

Amila Suriarachchi <[EMAIL PROTECTED]> wrote on 17/06/2008 
15:45:39:

> Axis2 by default does not add the mustunderstand attribute. 
> 
> thanks,
> Amila.

> On Tue, Jun 17, 2008 at 5:22 PM, <[EMAIL PROTECTED]> wrote:
> 
> Hello, 
> 
> 
> I uses Axis2-1.4's wsdl2java to generate a client to a web service 
> that does *not* accept the "mustUnderstand" attribute in headers. 
> Obviously, sending it headers with mustUnderstand attribute set to 
> something (true or fals or 0 or 1) fails. So, I want to make sure 
> that the generated client doesn't add the dreaded attribute. I've 
> checked this ML and there are several people who contributed 
> information on how to achieve that. But none of the proposed 
> solutions seem to work for me. Here's an excerpt of my code, with 
> all the solutions I've tested : 
> 
>     public static void main(String[] inArgs) throws AxisFault,
> AlineFault,RemoteException,Exception { 
> 
>         AlineBackendServiceStub ws = new 
AlineBackendServiceStub("http://..
> ."); // address hidden for privacy; that's the stub, coming right 
> from wsdl2java 
> 
>         Map m = ws._getServiceClient().getOptions().getProperties(); 
>         m.remove(AddressingConstants.
> ADD_MUST_UNDERSTAND_TO_ADDRESSING_HEADERS); 
>         ws._getServiceClient().getOptions().setProperties(m); 
> 
>         //ws._getServiceClient().getOptions().
> setProperty(AddressingConstants.
> ADD_MUST_UNDERSTAND_TO_ADDRESSING_HEADERS, Boolean.FALSE); 
>         ws._getServiceClient().getServiceContext().
> getConfigurationContext().setProperty(AddressingConstants.
> ADD_MUST_UNDERSTAND_TO_ADDRESSING_HEADERS, Boolean.FALSE); 
>         ws._getServiceClient().getServiceContext().
> getConfigurationContext().createMessageContext().
> setProperty(AddressingConstants.
> ADD_MUST_UNDERSTAND_TO_ADDRESSING_HEADERS, Boolean.FALSE); 
> 
> ... 
> 
> } 
> 
> None of these work : the mustUnderstand attribute kept written in my
> header (with value "0"). 
> 
> I've also tried to interfere with message context in the generated 
> stub, like this : 
> 
>               // create a message context 
>               _messageContext = new 
org.apache.axis2.context.MessageContext();
> 
>               _messageContext.setProperty(AddressingConstants.
> ADD_MUST_UNDERSTAND_TO_ADDRESSING_HEADERS, Boolean.FALSE); // Added by 
me !!!
> 
> 
> Then, I 'depserately) looked at the source code of Axis, and the 
> only thing I've seen is this (in WSDLSerializationUtil.java): 
> 
> 
>     /** 
>      * Adds a soap header element to a given OMElement 
>      * @param omFactory - An OMFactory 
>      * @param list - The arraylist of soapHeaderMessages 
>      * @param wsoap - The WSDL 2.0 SOAP namespace 
>      * @param element - The element that the header should be added to 
>      * @param nameSpaceMap - The namespaceMap 
>      */ 
>     public static void addSOAPHeaderElements(OMFactory omFactory, 
> ArrayList list, OMNamespace wsoap, 
>                                              OMElement element, Map 
> nameSpaceMap) { 
>         for (int i = 0; i < list.size(); i++) { 
>             SOAPHeaderMessage soapHeaderMessage = 
> (SOAPHeaderMessage) list.get(i); 
>             OMElement soapHeaderElement = 
>                     omFactory.createOMElement(WSDL2Constants.
> ATTRIBUTE_HEADER, wsoap); 
>             QName qName = soapHeaderMessage.getElement(); 
>             soapHeaderElement.addAttribute(omFactory.createOMAttribute( 
>                     WSDL2Constants.ATTRIBUTE_ELEMENT, null, 
>                     getPrefix(qName.getNamespaceURI(), nameSpaceMap)
> + ":" + qName.getLocalPart())); 
>             soapHeaderElement.addAttribute(omFactory.createOMAttribute( 
>                     WSDL2Constants.ATTRIBUTE_MUST_UNDERSTAND, null, 
> Boolean.toString(soapHeaderMessage.isMustUnderstand())));
>             soapHeaderElement.addAttribute(omFactory.createOMAttribute( 
>                     WSDL2Constants.ATTRIBUTE_REQUIRED, null, 
>                     Boolean.toString(soapHeaderMessage.isRequired()))); 
>             element.addChild(soapHeaderElement); 
>         } 
>     } 
> 
> 
> I've no idea if this is the place where the serialization does 
> happen, but if it is, then I believe the mustUnderstand attribute 
> will always be set (to true or false) and never removed. 
> 
> I know this question has been posted several times and I hope that 
> some of you will have enough patience to look at it... 
> 
> Thanks, 
> 
> Stefan 
> 
> 
> 
> 
> 
> 
> -- 
> Amila Suriarachchi,
> WSO2 Inc. 

Reply via email to