Hi Resmy,

OMFactory fac = OMAbstractFactory.getOMFactory();
SOAPHeaderBlock block = 
msgCtx.getEnvelope().getHeader().addHeaderBlock("header-name", 
fac.createOMNamespace("namespace", "prefix"));
block.addChild(fac.createOMText("header-value"));

Hope this helps...

Thanks,
Ruwan

Schmilinsky, Remsy wrote:
> Hi, can you indicate how to add a custom soap header to an axis2 
> MessageContext object ? I have this web service called by esb:
>
>
> public OMElement getRspAttachment(OMElement request) throws Exception {
>    MessageContext inMessageContext = 
> MessageContext.getCurrentMessageContext();
>    OperationContext operationContext = inMessageContext.getOperationContext();
>    
>    DataSource rspDataSource = new ByteArrayDataSource(("<?xml version=\"1.0\" 
> encoding=\"UTF-8\"?><response>" + "a response..." +    
> "</response>").getBytes(), "text/xml; charset=UTF-8");
>
>    MessageContext outMessageContext = 
> operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
>    
> outMessageContext.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_SWA,
>  org.apache.axis2.Constants.VALUE_TRUE);
>               
>    DataHandler rspDataHandler = new DataHandler(rspDataSource);
>               
>    OMFactory factory = request.getOMFactory();
>         
>    OMNamespace ns = factory.createOMNamespace("http://services.samples/xsd";, 
> "m0");
>         
>    OMElement payload  = factory.createOMElement("transformResponse", ns);
>    OMElement msgId  = factory.createOMElement("xmlMsgId", ns);
>    OMElement response = factory.createOMElement("response", ns);        
>    String xmlRspID = outMessageContext.addAttachment(rspDataHandler);
>    msgId.setText(xmlRspID);
>    response.addChild(msgId);
>    payload.addChild(response);
>    return payload;
> }
>
> the resulting attachment will then be processed by esb, but I need to add 
> some values in the header.
>
> thanks
>
> _______________________________________________
> Esb-java-user mailing list
> [email protected]
> http://mailman.wso2.org/cgi-bin/mailman/listinfo/esb-java-user
>
>   


_______________________________________________
Esb-java-user mailing list
[email protected]
http://mailman.wso2.org/cgi-bin/mailman/listinfo/esb-java-user

Reply via email to