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

package wssec;

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

import org.apache.axis.Message;

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

    /**
     * Convert a DOM Document into an Axis message.
     * <p/>
     *
     * @param doc
     * @return
     * @throws Exception
     */
    public static Message toAxisMessage(Document doc) throws Exception {
        Canonicalizer c14n =
                Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
        byte[] canonicalMessage = c14n.canonicalizeSubtree(doc);
        ByteArrayInputStream in = new ByteArrayInputStream(canonicalMessage);
        return new Message(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;
    }
}

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.
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.

git-svn-id: 10bc45916fe30ae642aa5037c9a4b05727bba413@533031 13f79535-47bb-0310-9956-ffa450edef68
