WSS4J expects a Document object, and SOAPEnvelope is not a Document -> you therefore need to call the getAsDocument method to get a Document.
I'm not familiar with the implementation of this method, but I think it returns a new DOM tree, because if I don't convert the document back to a SOAPEnvelope the message appears unchanged.
Anyway, after some more debugging, it seems that this method works fine:
public static SOAPMessage toSOAPMessage(Document doc) throws Exception {
Canonicalizer c14n =
Canonicalizer.getInstance (Canonicalizer.ALGO_ID_C14N
_WITH_COMMENTS);
byte[] canonicalMessage = c14n.canonicalizeSubtree(doc);
ByteArrayInputStream in = new ByteArrayInputStream(canonicalMessage);
factory = org.apache.axis.soap.MessageFactoryImpl.newInstance ();
return (SOAPMessage) factory.createMessage(null, in);
}
byte[] canonicalMessage = c14n.canonicalizeSubtree(doc);
ByteArrayInputStream in = new ByteArrayInputStream(canonicalMessage);
factory = org.apache.axis.soap.MessageFactoryImpl.newInstance ();
return (SOAPMessage) factory.createMessage(null, in);
}
My exceptions were caused because I was not calling message.saveChanges() after calling the method above. This had somehow some strage effects ...
Cheers,
C.
On 6/10/06, Jeff Greif <[EMAIL PROTECTED]> wrote:
If your SOAPEnvelope is an Element (which will be true if you use the
correct version of saaj.jar), could you not process any subtree in
place with WSS4J and the result will still be a SOAPEnvelope? I don't
think you need to convert anything in either direction. I'm presuming
that the DOMImplementation that creates child elements etc from
SOAPElements creates SOAPElements, not some other subclass of Element.
That DOMImplementation will be used for all modifications to a DOM it
created.
Jeff
On 6/10/06, Cristian Opincaru <[EMAIL PROTECTED]> wrote:
> Jeff,
>
> SOAPEnvelope -> Document there's no problem since there is a method
> getAsDocument.
>
> However, converting a Document into a SOAPEnvelope is not trivial (since not
> all DOM objects are SOAP envelopes).
>
> Greets,
> C.
>
> On 6/9/06, Jeff Greif < [EMAIL PROTECTED]> wrote:
> > Using saaj.jar that is distributed with all axis versions since (at
> > least) 1.2, the javax.xml.soap.SoapEnvelope class implements
> > SOAPElement which extends org.w3c.dom.Element. It's not clear that
> > any conversion is necessary.
> >
> > I believe older versions of the SAAJ classes (conforming to an older
> > version of the SOAP with Attachements spec) require conversion to Dom.
> >
> > Jeff
> >
> > On 6/9/06, Cristian Opincaru < [EMAIL PROTECTED]> wrote:
> > > Hi,
> > >
> > > I want to use WSS4J to do some encryption / decryption with SOAP and for
> > > this I have to convert the SOPA message in DOM (the WSS4J API does all
> > > processing with Document objects). After using the WSS4J routines, I
> must
> > > convert the message from Document back to SOAPEnvelope, and this is
> where my
> > > problems start.
...
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Cristian OPINCARU
University of the Federal Armed Forces Munich
http://www.unibw.de/cristian.opincaru
