You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wss4j-dev@ws.apache.org by Cristian Opincaru <cr...@gmail.com> on 2006/06/09 11:14:04 UTC

org.w3c.Documnet <-> SOAPEnvelope

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.

I googled a bit, and ended up with two ways of doing this. This one is:

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);
    }
This is where the AXIS classes are used (I guess).

The second one is:

   public static SOAPMessage toSOAPMessage(Document doc) throws Exception {
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage m = (SOAPMessage) factory.createMessage();
        m.getSOAPPart().setContent(new DOMSource(doc));
        return m;
    }

This is where the SUN implementetion is used (aganin, not really sure).

Anyway, both seem to work in some cases, while in others I get some wierd
SAX Exceptions (like documents must start and end with the same entity).

Since I assume this is a pretty standard thingm, can anyone indicate me
how's the right way to do it? Also I think there might be a problem because
of the libraries that I'm using (perhaps I'm using the wrong versions / or
simply mixing SOAP implementations). Can anyone tell me what libraries (and
versions) I should use in order to avoid problems?

Thanks!
Cristian


-- 
Cristian OPINCARU
University of the Federal Armed Forces Munich
http://www.unibw.de/cristian.opincaru

Re: org.w3c.Documnet <-> SOAPEnvelope

Posted by Cristian Opincaru <cr...@gmail.com>.
Well,

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);
    }

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 <jg...@alumni.princeton.edu> 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 <cr...@gmail.com> 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 <jg...@alumni.princeton.edu> 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 < cristian.opincaru@gmail.com> 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: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Cristian OPINCARU
University of the Federal Armed Forces Munich
http://www.unibw.de/cristian.opincaru

Re: org.w3c.Documnet <-> SOAPEnvelope

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
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 <cr...@gmail.com> 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 <jg...@alumni.princeton.edu> 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 < cristian.opincaru@gmail.com> 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: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: org.w3c.Documnet <-> SOAPEnvelope

Posted by Cristian Opincaru <cr...@gmail.com>.
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 <jg...@alumni.princeton.edu> 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 <cr...@gmail.com> 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: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Cristian OPINCARU
University of the Federal Armed Forces Munich
http://www.unibw.de/cristian.opincaru

Re: org.w3c.Documnet <-> SOAPEnvelope

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
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 <cr...@gmail.com> 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: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org