I encountered this same issue, and used the individual elements produced by WSS4J to append into the axis message.
 
Not sure if this is the best approach (i am only prototyping), but this is what I did:
 
       // Get soap message and convert to a document
       Message message = MessageContext.getCurrentContext().getResponseMessage();
       Document messageDoc = message.getSOAPEnvelope().getAsDocument();
 
       // WSS4J - build SAML assertion
       SAMLIssuer saml = SAMLIssuerFactory.getInstance("saml.properties");
       saml.setInstanceDoc(messageDoc);
       saml.setUserCrypto(crypto);
       saml.setUsername("mykey");
       SAMLAssertion assertion = saml.newAssertion();
 
       // WSS4J - build wsse security header
       WSSecHeader wsHeader = new WSSecHeader();
       wsHeader.setMustUnderstand(true);
 
       // Get the wsse security header as an element and append the assertion
       Element wsHeader = shead.insertSecurityHeader(messageDoc);
       wsHeader.appendChild(assertion.toDOM(messageDoc));
 
       // append the wsse header and saml token into the soap response message
       message.getSOAPHeader().appendChild(wsHeader);

Raul Flores



From: Cristian Opincaru [mailto:[EMAIL PROTECTED]
Sent: Friday, June 09, 2006 4:14 AM
To: [email protected]; [email protected]
Subject: 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

Reply via email to