You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Xinjun Chen <xj...@gmail.com> on 2006/03/24 14:02:45 UTC

[Axis2][0.95] How to add a HeaderBlock

Hi,

I am trying to add a HeaderBlock to a SOAPEnvelope in Axis2.
It seems that Axis2 0.95 changed much from 0.94. So many package names
and classes are changed. Will this happen in Axis2 1.0? Should I
proceed with Axis2 0.95 or wait for Axis2 1.0?

The OM module in 0.94 seems have been moved to Axiom API and Axiom-Impl.

How can I add a HeaderBlock using Axis2 0.95? Take the following code
for an example. Currently, I have already get the original
SOAPEnvelope object "envelope" with only "Body" part, and I have got
the document object representation of the header block as the
following,

<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Username xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
xinjun</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>

How can I add this header correctly?
I tried envelope.getHeader().addHeaderBlock(String, OMNamesapce). But
How should I use it? How to set the parameters?

Regards,
Xinjun

Re: [Axis2][0.95] How to add a HeaderBlock

Posted by Xinjun Chen <xj...@gmail.com>.
Hi Eran,

Thank you very much for your clarification.
Maybe I will use 0.94 temporarily and later upgrade to version 1.0.

As for adding SOAPHeader, maybe I didn't make my question clear. What
I want to do is to manipulate an SOAPEnvelope, adding SOAPHeader to
the SOAPEnvelope in a handler but not inside a client.

Finally I managed to do that in the following way:

public void execute(final SOAPEnvelope envelope) {
// envelope contains body only initially
...
org.w3c.dom.Document domDoc = ... // document of the SOAPEnvelope with
security header.

org.w3c.dom.Element headerElm =
(Element)(domDoc.getElementsByTagName("wsse:Security").item(0));

OMElement header = Axis2Util.toOM(headerElm);

SOAPFactory factory = null;
String soapNSURI = envelope.getNamespace().getName();
if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapNSURI)) {
	factory = OMAbstractFactory.getSOAP11Factory();
} else {
	factory = OMAbstractFactory.getSOAP12Factory();
}
factory.createSOAPHeader(envelope);
envelope.getHeader().addChild(header);
...
}

The factory will append an empty header to the envelope. But the
header is after the body. This does no harm to the operation of
accessing header and body. Just the printing is not so nice. Can you
developers revise the SOAPFactory createSOAPHeader() method so that
Header is always before the Body?


Regards,
Xinjun

On 3/26/06, Eran Chinthaka <ch...@opensource.lk> wrote:
> Xinjun Chen wrote:
> > Hi,
> >
> > I am trying to add a HeaderBlock to a SOAPEnvelope in Axis2.
> > It seems that Axis2 0.95 changed much from 0.94. So many package names
> > and classes are changed. Will this happen in Axis2 1.0? Should I
> > proceed with Axis2 0.95 or wait for Axis2 1.0?
> >
> We **may** do some api changes before 1.0, but by 1.0 the externally
> visible api will definitely be finalized. So do not worry about it.
> Even now, we haven't change much since last release. We introduced the
> service client api, during 0.94 version.
> > The OM module in 0.94 seems have been moved to Axiom API and Axiom-Impl.
> >
> Yeah, but this doesn't affect the api at all.
> > How can I add a HeaderBlock using Axis2 0.95?
> Depends on which API you use.
>
> If you are using ServiceClient api then;
>        ServiceClient.addHeader(OMElement); will do.
>
> If you are using OperationClient api, then directly set the header to
> envelope and set envlope to the message context which you add to the
> operation client.
>
> -- Chinthaka
>
>
>
>

Re: [Axis2][0.95] How to add a HeaderBlock

Posted by Eran Chinthaka <ch...@opensource.lk>.
Xinjun Chen wrote:
> Hi,
>
> I am trying to add a HeaderBlock to a SOAPEnvelope in Axis2.
> It seems that Axis2 0.95 changed much from 0.94. So many package names
> and classes are changed. Will this happen in Axis2 1.0? Should I
> proceed with Axis2 0.95 or wait for Axis2 1.0?
>   
We **may** do some api changes before 1.0, but by 1.0 the externally
visible api will definitely be finalized. So do not worry about it.
Even now, we haven't change much since last release. We introduced the
service client api, during 0.94 version.
> The OM module in 0.94 seems have been moved to Axiom API and Axiom-Impl.
>   
Yeah, but this doesn't affect the api at all.
> How can I add a HeaderBlock using Axis2 0.95? 
Depends on which API you use.

If you are using ServiceClient api then;
        ServiceClient.addHeader(OMElement); will do.

If you are using OperationClient api, then directly set the header to
envelope and set envlope to the message context which you add to the
operation client.

-- Chinthaka