Search in sources :

Example 6 with SOAPElement

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

the class SOAPTestHandler method handleMessage.

public boolean handleMessage(SOAPMessageContext smc) {
    try {
        SOAPMessage message = smc.getMessage();
        SOAPBody body = message.getSOAPBody();
        SOAPElement paramElement = (SOAPElement) body.getFirstChild().getFirstChild();
        int number = Integer.parseInt(paramElement.getValue());
        if (number == THROW_RUNTIME_EXCEPTION) {
            throw new RuntimeException("EXPECTED EXCEPTION");
        } else if (number == THROW_PROTOCOL_EXCEPTION) {
            throw new ProtocolException("EXPECTED EXCEPTION");
        } else if (number == THROW_SOAPFAULT_EXCEPTION) {
        // todo
        }
        paramElement.setValue(String.valueOf(++number));
    } catch (SOAPException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    return true;
}
Also used : ProtocolException(jakarta.xml.ws.ProtocolException) SOAPBody(jakarta.xml.soap.SOAPBody) SOAPException(jakarta.xml.soap.SOAPException) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 7 with SOAPElement

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

the class ProviderImpl method invoke.

/* 
     */
public Source invoke(Source msg) {
    if (!isInjectionDone()) {
        throw new WebServiceException("Injection is not done");
    }
    // Test if we got the correct SOAPMessage that has handler changes
    try {
        MessageFactory fact = MessageFactory.newInstance();
        SOAPMessage soap = fact.createMessage();
        soap.getSOAPPart().setContent(msg);
        SOAPBody body = soap.getSOAPBody();
        Iterator i = body.getChildElements();
        SOAPElement elem = (SOAPElement) i.next();
        QName name = elem.getElementQName();
        QName exp = new QName("urn:test:types", "MyVoidTest");
        if (!exp.equals(name)) {
            throw new WebServiceException("Handler changes aren't reflected");
        }
    } catch (SOAPException e) {
        throw new WebServiceException("Got Incorrect Source");
    }
    printContext();
    String content = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body>  <VoidTestResponse xmlns=\"urn:test:types\"></VoidTestResponse></soapenv:Body></soapenv:Envelope>";
    Source source = new StreamSource(new ByteArrayInputStream(content.getBytes()));
    return source;
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) WebServiceException(jakarta.xml.ws.WebServiceException) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) SOAPException(jakarta.xml.soap.SOAPException) StreamSource(javax.xml.transform.stream.StreamSource) Iterator(java.util.Iterator) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPMessage(jakarta.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource)

Example 8 with SOAPElement

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

the class JAXBTest method createFault.

private static SOAPFault createFault() throws Exception {
    SOAPFactory fac = SOAPFactory.newInstance();
    SOAPFault sf = fac.createFault("This is a fault.", new QName("http://schemas.xmlsoap.org/wsdl/soap/http", "Client"));
    Detail d = sf.addDetail();
    SOAPElement de = d.addChildElement(DETAIL1_QNAME);
    de.addAttribute(new QName("", "msg1"), "This is the first detail message.");
    return sf;
}
Also used : QName(javax.xml.namespace.QName) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPFactory(jakarta.xml.soap.SOAPFactory) Detail(jakarta.xml.soap.Detail)

Example 9 with SOAPElement

use of jakarta.xml.soap.SOAPElement 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 10 with SOAPElement

use of jakarta.xml.soap.SOAPElement 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)

Aggregations

SOAPElement (jakarta.xml.soap.SOAPElement)24 SOAPMessage (jakarta.xml.soap.SOAPMessage)12 SOAPException (jakarta.xml.soap.SOAPException)10 SOAPBody (jakarta.xml.soap.SOAPBody)9 Name (jakarta.xml.soap.Name)7 SOAPHeaderElement (jakarta.xml.soap.SOAPHeaderElement)6 MessageFactory (jakarta.xml.soap.MessageFactory)5 QName (javax.xml.namespace.QName)5 Detail (jakarta.xml.soap.Detail)3 SOAPEnvelope (jakarta.xml.soap.SOAPEnvelope)3 SOAPFault (jakarta.xml.soap.SOAPFault)3 Iterator (java.util.Iterator)3 SAAJFactory (com.sun.xml.ws.api.message.saaj.SAAJFactory)2 StreamMessage (com.sun.xml.ws.message.stream.StreamMessage)2 SOAPFactory (jakarta.xml.soap.SOAPFactory)2 SOAPPart (jakarta.xml.soap.SOAPPart)2 ProtocolException (jakarta.xml.ws.ProtocolException)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringReader (java.io.StringReader)2