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

Reply via email to