package wssec;

import org.apache.xml.security.c14n.Canonicalizer;
import org.w3c.dom.Document;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.dom.DOMSource;
import java.io.ByteArrayInputStream;

public class SOAPUtil {

    /**
     * Convert a DOM Document into a soap message.
     * <p/>
     *
     * @param doc
     * @return
     * @throws Exception
     */
    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);
        MessageFactory factory = MessageFactory.newInstance();
        return factory.createMessage(null, in);
    }

    /**
     * Update soap message.
     * <p/>
     *
     * @param doc
     * @param message
     * @return
     * @throws Exception
     */
    public static SOAPMessage updateSOAPMessage(Document doc,
                                                SOAPMessage message)
            throws Exception {
        DOMSource domSource = new DOMSource(doc);
        message.getSOAPPart().setContent(domSource);
        return message;
    }
}

@@ -90,16 +90,49 @@
 ument;%0A%0A
+import org.apache.axis.Message;%0A%0A
 import j
@@ -897,16 +897,530 @@
 %0A    %7D%0A%0A
+    /**%0A     * Convert a DOM Document into an Axis message.%0A     * %3Cp/%3E%0A     *%0A     * @param doc%0A     * @return%0A     * @throws Exception%0A     */%0A    public static Message toAxisMessage(Document doc) throws Exception %7B%0A        Canonicalizer c14n =%0A                Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);%0A        byte%5B%5D canonicalMessage = c14n.canonicalizeSubtree(doc);%0A        ByteArrayInputStream in = new ByteArrayInputStream(canonicalMessage);%0A        return new Message(in);%0A    %7D%0A%0A
     /**%0A

Introduce new "toAxisMessage()" to create a Axis message from a DOM document. Use this new function instead of "toSOAPMessage()". This resolves a problem in Java 6 which has a built-in xml.SOAPMessage implementation. This implementation is in conflict with the previous used Axis implementation. Previously the MessageFactory returned an Axis message that implements a SOAPMessage interface. The test cases (TestWS*) used this internal know-how and cast the SOAPMessage into an Axis message directly. This fails in Java 6 and was bad programming style anyhow. The TestWS* test cases will be modified to use the new function.