[ 
https://issues.apache.org/jira/browse/AXIS2-3948?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12866540#action_12866540
 ] 

Olivier Vanekem edited comment on AXIS2-3948 at 5/12/10 7:02 AM:
-----------------------------------------------------------------

Hi,
We fell in the same issue.
The way we resolved it (though not clean) is by modifying the generated 
MessageReceiverInOut class that contains the invokeBusinessLogic method 
(dispatch calls to the skeleton).
Inside this method, we added this code:

// retrieve original envelope, this is because we want to copy/paste an element 
from the header of the request to the header of the response
SOAPEnvelope env = msgContext.getEnvelope();

// this creates our own structure that we want to add to the SOAP header
SyncHeader header = SyncHeader.Factory.newInstance();
header.setCMessageID(cMsgId);
SyncHeaderDocument headerDoc = SyncHeaderDocument.Factory.newInstance();
headerDoc.setSyncHeader(header);
                        
// here we generate an OMElement from our custom header structure       
org.apache.axiom.om.OMElement omElementsyncHeader = toOM(headerDoc);

// here we add the header to the new envelope (of the response)
addHeader(omElementsyncHeader, envelope);
// the new envelope is set on the newMsgContext which is the one of the response
newMsgContext.setEnvelope(envelope);

and to be complete, here the code of the addHeader private method that we also 
added to the ReceiverInOut:

        private void addHeader(OMElement omElementToadd, SOAPEnvelope envelop) {
                SOAPHeaderBlock soapHeaderBlock = 
envelop.getHeader().addHeaderBlock(
                                omElementToadd.getLocalName(), 
omElementToadd.getNamespace());
                // soapHeaderBlock.setMustUnderstand(mustUnderstand);
                OMNode omNode = null;

                // add child elements
                for (Iterator iter = omElementToadd.getChildren(); 
iter.hasNext();) {
                        omNode = (OMNode) iter.next();
                        soapHeaderBlock.addChild(omNode);
                }

                OMAttribute omatribute = null;
                // add attributes
                for (Iterator iter = omElementToadd.getAllAttributes(); 
iter.hasNext();) {
                        omatribute = (OMAttribute) iter.next();
                        soapHeaderBlock.addAttribute(omatribute);
                }
        }       


As I said, we are uncomfortable to need to modify generated code but this was 
the only way we found. Should this be done in a cleaner way (now or in a later 
release of Axis/2) we are keen on changing it in our application.

      was (Author: ovanekem):
    Hi,
We fell in the same issue.
The way we resolved it (though not clean) is by modifying the generated 
MessageReceiverInOut class that contains the invokeBusinessLogic method 
(dispatch calls to the skeleton).
Inside this method, we added this code:

{noformat}
// retrieve original envelope, this is because we want to copy/paste an element 
from the header of the request to the header of the response
SOAPEnvelope env = msgContext.getEnvelope();

// this creates our own structure that we want to add to the SOAP header
SyncHeader header = SyncHeader.Factory.newInstance();
header.setCMessageID(cMsgId);
SyncHeaderDocument headerDoc = SyncHeaderDocument.Factory.newInstance();
headerDoc.setSyncHeader(header);
                        
// here we generate an OMElement from our custom header structure       
org.apache.axiom.om.OMElement omElementsyncHeader = toOM(headerDoc);

// here we add the header to the new envelope (of the response)
addHeader(omElementsyncHeader, envelope);
// the new envelope is set on the newMsgContext which is the one of the response
newMsgContext.setEnvelope(envelope);
{noformat}

and to be complete, here the code of the addHeader private method that we also 
added to the ReceiverInOut:

{noformat}
        private void addHeader(OMElement omElementToadd, SOAPEnvelope envelop) {
                SOAPHeaderBlock soapHeaderBlock = 
envelop.getHeader().addHeaderBlock(
                                omElementToadd.getLocalName(), 
omElementToadd.getNamespace());
                // soapHeaderBlock.setMustUnderstand(mustUnderstand);
                OMNode omNode = null;

                // add child elements
                for (Iterator iter = omElementToadd.getChildren(); 
iter.hasNext();) {
                        omNode = (OMNode) iter.next();
                        soapHeaderBlock.addChild(omNode);
                }

                OMAttribute omatribute = null;
                // add attributes
                for (Iterator iter = omElementToadd.getAllAttributes(); 
iter.hasNext();) {
                        omatribute = (OMAttribute) iter.next();
                        soapHeaderBlock.addAttribute(omatribute);
                }
        }       

{noformat}

As I said, we are uncomfortable to need to modify generated code but this was 
the only way we found. Should this be done in a cleaner way (now or in a later 
release of Axis/2) we are keen on changing it in our application.
  
> WSDL2Java doesn't allow to add a custom header element through the Skeleton
> ---------------------------------------------------------------------------
>
>                 Key: AXIS2-3948
>                 URL: https://issues.apache.org/jira/browse/AXIS2-3948
>             Project: Axis2
>          Issue Type: Bug
>          Components: Tools
>    Affects Versions: 1.4, 1.3
>         Environment: OS: Microsoft Windows Server 2003/Mac OS X 10.5
> IDE: Eclipse 3.2/Eclipse 3.4 with plugin Axis2Codegen Wizard
> Tool: WSDL2java as command line or called by the Axis2Codegen Wizard
>            Reporter: Emidio Stani
>         Attachments: wsdlsoapheader.zip
>
>   Original Estimate: 168h
>  Remaining Estimate: 168h
>
> Hi all,
> I created a WSDL file WS-I compliant (Basic Profile 1.1) where I specify an 
> header. After that I generated stub and skeleton with the wsdl2java tool; 
> inside the stub I have the method to call the service which allows me to add 
> my custom header element but from the skeleton side the method allows only to 
> work on the object that will be included in the body and not on the header.
> It seems that the only way is to modify the MessageReceiverInOut java class  
> to add the header manually when it created a new soap message.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to