Search in sources :

Example 1 with SOAPEnvelope

use of jakarta.xml.soap.SOAPEnvelope in project openmq by eclipse-ee4j.

the class SOAPtoJMSServlet method generateResponseMessage.

/**
 * Add a MessageStatus element with the value of "published" to
 * the soapMessage.
 */
public SOAPMessage generateResponseMessage(SOAPMessage soapMessage) {
    try {
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody soapBody = envelope.getBody();
        soapBody.addChildElement("MessageStatus").addTextNode("published");
        soapMessage.saveChanges();
    } catch (SOAPException soape) {
        soape.printStackTrace();
    }
    return soapMessage;
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) SOAPException(jakarta.xml.soap.SOAPException) SOAPPart(jakarta.xml.soap.SOAPPart) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope)

Example 2 with SOAPEnvelope

use of jakarta.xml.soap.SOAPEnvelope in project metro-jax-ws by eclipse-ee4j.

the class SAAJMessageTester method testDOMLevel1WriteTo.

public void testDOMLevel1WriteTo() throws Exception {
    DocumentBuilderFactory builderFactory = null;
    DocumentBuilder builder = null;
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
    soapEnvelope.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    soapEnvelope.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
    SOAPBody soapBody = soapEnvelope.getBody();
    Name elementName = soapEnvelope.createName("addNumbers", "", "http://duke.org");
    SOAPBodyElement bodyElement = soapBody.addBodyElement(elementName);
    SAAJMessage msg = new SAAJMessage(soapMessage);
    ByteArrayBuffer baos = new ByteArrayBuffer();
    XMLStreamWriter writer = XMLStreamWriterFactory.createXMLStreamWriter(baos);
    msg.writeTo(writer);
    writer.flush();
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) MessageFactory(jakarta.xml.soap.MessageFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope) SOAPMessage(jakarta.xml.soap.SOAPMessage) Name(jakarta.xml.soap.Name) QName(javax.xml.namespace.QName) SOAPBodyElement(jakarta.xml.soap.SOAPBodyElement) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 3 with SOAPEnvelope

use of jakarta.xml.soap.SOAPEnvelope in project openmq by eclipse-ee4j.

the class SendSOAPMessage method sendMessage.

/**
 * send a simple soap message with JAXM API.
 */
public void sendMessage(String url) {
    try {
        /**
         * Construct a default SOAP message factory.
         */
        MessageFactory mf = MessageFactory.newInstance();
        /**
         * Create a SOAP message object.
         */
        SOAPMessage soapMessage = mf.createMessage();
        /**
         * Get SOAP part.
         */
        SOAPPart soapPart = soapMessage.getSOAPPart();
        /**
         * Get SOAP envelope.
         */
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
        /**
         * Get SOAP body.
         */
        SOAPBody soapBody = soapEnvelope.getBody();
        /**
         * Add child element with the specified name.
         */
        SOAPElement element = soapBody.addChildElement("HelloWorld");
        /**
         * Add text message
         */
        element.addTextNode("Welcome to SunOne Web Services!");
        soapMessage.saveChanges();
        /**
         * Construct a default SOAP connection factory.
         */
        SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
        /**
         * Get SOAP connection.
         */
        SOAPConnection soapConnection = connectionFactory.createConnection();
        /**
         * Send SOAP message.
         */
        SOAPMessage resp = soapConnection.call(soapMessage, url);
        /**
         * Print response to the std output.
         */
        resp.writeTo(System.out);
        /**
         * close the connection
         */
        soapConnection.close();
    } catch (java.io.IOException ioe) {
        ioe.printStackTrace();
    } catch (SOAPException soape) {
        soape.printStackTrace();
    }
}
Also used : SOAPConnectionFactory(jakarta.xml.soap.SOAPConnectionFactory) SOAPBody(jakarta.xml.soap.SOAPBody) MessageFactory(jakarta.xml.soap.MessageFactory) SOAPException(jakarta.xml.soap.SOAPException) SOAPPart(jakarta.xml.soap.SOAPPart) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPConnection(jakarta.xml.soap.SOAPConnection) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 4 with SOAPEnvelope

use of jakarta.xml.soap.SOAPEnvelope in project openmq by eclipse-ee4j.

the class SendSOAPMessageWithJMS method send.

/**
 * Send SOAP message with JMS API.
 */
public void send() throws Exception {
    /**
     * Construct a default SOAP message factory.
     */
    MessageFactory mf = MessageFactory.newInstance();
    /**
     * Create a SOAP message object.
     */
    SOAPMessage soapMessage = mf.createMessage();
    /**
     * Get SOAP part.
     */
    SOAPPart soapPart = soapMessage.getSOAPPart();
    /**
     * Get SOAP envelope.
     */
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    /**
     * Get SOAP body.
     */
    SOAPBody soapBody = soapEnvelope.getBody();
    /**
     * Create a name object. with name space http://www.sun.com/imq.
     */
    Name name = soapEnvelope.createName("HelloWorld", "hw", "http://www.sun.com/imq");
    /**
     * Add child element with the above name.
     */
    SOAPElement element = soapBody.addChildElement(name);
    /**
     * Add another child element.
     */
    element.addTextNode("Welcome to SunOne Web Services.");
    /**
     * Create an atachment with activation API.
     */
    URL url = new URL("https://projects.eclipse.org/projects/ee4j.openmq/contact");
    DataHandler dh = new DataHandler(url);
    AttachmentPart ap = soapMessage.createAttachmentPart(dh);
    /**
     * set content type/ID.
     */
    ap.setContentType("text/html");
    ap.setContentId("cid-001");
    /**
     *  add the attachment to the SOAP message.
     */
    soapMessage.addAttachmentPart(ap);
    soapMessage.saveChanges();
    /**
     * Convert SOAP to JMS message.
     */
    Message message = MessageTransformer.SOAPMessageIntoJMSMessage(soapMessage, session);
    /**
     * publish JMS message.
     */
    msgProducer.send(message);
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) MessageFactory(jakarta.xml.soap.MessageFactory) Message(jakarta.jms.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) SOAPPart(jakarta.xml.soap.SOAPPart) SOAPElement(jakarta.xml.soap.SOAPElement) AttachmentPart(jakarta.xml.soap.AttachmentPart) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope) DataHandler(jakarta.activation.DataHandler) SOAPMessage(jakarta.xml.soap.SOAPMessage) URL(java.net.URL) Name(jakarta.xml.soap.Name)

Example 5 with SOAPEnvelope

use of jakarta.xml.soap.SOAPEnvelope in project openmq by eclipse-ee4j.

the class UMSService method createSOAPFaultMessage.

/**
 * Create a soap fault message and set its error code and error string as specified in the parameter.
 */
public static SOAPMessage createSOAPFaultMessage(Throwable t, String faultCode, String faultString) {
    SOAPMessage soapFault = null;
    try {
        MessageFactory mf = MessageFactory.newInstance();
        soapFault = mf.createMessage();
        SOAPEnvelope env = soapFault.getSOAPPart().getEnvelope();
        SOAPBody body = env.getBody();
        SOAPFault faultElement = body.addFault();
        String soapNs = env.getElementName().getPrefix();
        String fcode = soapNs + ":" + faultCode;
        faultElement.setFaultCode(fcode);
        faultElement.setFaultString(faultString);
        Detail detail = faultElement.getDetail();
        if (detail == null) {
            detail = faultElement.addDetail();
        }
        Name stname = MessageUtil.createJMSName("StackTrace");
        SOAPElement entryEle = detail.addDetailEntry(stname);
        // get stack trace
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);
        t.printStackTrace(ps);
        ps.close();
        String trace = baos.toString("utf8");
        entryEle.setValue(trace);
        soapFault.saveChanges();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return soapFault;
}
Also used : PrintStream(java.io.PrintStream) SOAPBody(jakarta.xml.soap.SOAPBody) MessageFactory(jakarta.xml.soap.MessageFactory) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage) Detail(jakarta.xml.soap.Detail) SOAPException(jakarta.xml.soap.SOAPException) Name(jakarta.xml.soap.Name)

Aggregations

SOAPBody (jakarta.xml.soap.SOAPBody)6 SOAPEnvelope (jakarta.xml.soap.SOAPEnvelope)6 SOAPMessage (jakarta.xml.soap.SOAPMessage)5 MessageFactory (jakarta.xml.soap.MessageFactory)4 SOAPException (jakarta.xml.soap.SOAPException)4 SOAPPart (jakarta.xml.soap.SOAPPart)4 Name (jakarta.xml.soap.Name)3 SOAPElement (jakarta.xml.soap.SOAPElement)3 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)1 ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)1 DataHandler (jakarta.activation.DataHandler)1 Message (jakarta.jms.Message)1 AttachmentPart (jakarta.xml.soap.AttachmentPart)1 Detail (jakarta.xml.soap.Detail)1 SOAPBodyElement (jakarta.xml.soap.SOAPBodyElement)1 SOAPConnection (jakarta.xml.soap.SOAPConnection)1 SOAPConnectionFactory (jakarta.xml.soap.SOAPConnectionFactory)1 SOAPFault (jakarta.xml.soap.SOAPFault)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1