Search in sources :

Example 21 with SOAPBody

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

the class SaajMessageTest method testBodyAttr.

public void testBodyAttr() throws Exception {
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    Source src = new StreamSource(new ByteArrayInputStream(MESSAGE_535.getBytes()));
    message.getSOAPPart().setContent(src);
    SAAJMessage saajMsg = new SAAJMessage(message);
    // breaks the underlying SOAPMessage
    saajMsg.hasHeaders();
    Source source = saajMsg.readEnvelopeAsSource();
    SOAPMessage newMsg = factory.createMessage();
    newMsg.getSOAPPart().setContent(source);
    SOAPBody body = newMsg.getSOAPBody();
    assertEquals("value", body.getAttribute("attr"));
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) StreamSource(javax.xml.transform.stream.StreamSource) SOAPMessage(jakarta.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 22 with SOAPBody

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

the class SaajMessageTest method testBodyAttr.

/**
 * Test for body attribute after SAAJMessage.copy()
 *
 * @throws Exception - error
 */
public void testBodyAttr() throws Exception {
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage soapMessage = factory.createMessage();
    Source src = new StreamSource(new ByteArrayInputStream(MESSAGE.getBytes()));
    soapMessage.getSOAPPart().setContent(src);
    SAAJMessage saajMsg = new SAAJMessage(soapMessage);
    // breaks the underlying SOAPMessage
    saajMsg.hasHeaders();
    saajMsg = (SAAJMessage) saajMsg.copy();
    SOAPBody soapBody = saajMsg.readAsSOAPMessage().getSOAPBody();
    assertEquals("value", soapBody.getAttribute("attr"));
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) StreamSource(javax.xml.transform.stream.StreamSource) SOAPMessage(jakarta.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 23 with SOAPBody

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

the class NonAnonymousClientTest method test1150.

/**
 * SOAP 1.1 two-way message with a non-anonymous ReplyTo address.
 */
public void test1150() throws Exception {
    invokeAsync(createDispatchForNonAnonymousWithWSDLWithoutAddressing(), MESSAGES.getNonAnonymousReplyToMessage(), S11_NS, getNonAnonymousEndpointAddress(), clientAddress, ECHO_IN_ACTION, "test1150");
    // Lets see we get a response in 60 s
    SOAPMessage m = respMsgExchanger.exchange(null, TestConstants.CLIENT_MAX_TIMEOUT, TimeUnit.SECONDS);
    // System.out.println("****************************");
    // m.writeTo(System.out);
    // System.out.println("\n****************************");
    SOAPBody sb = m.getSOAPBody();
    Iterator itr = sb.getChildElements(new QName("http://example.org/echo", "echoOut"));
    assertTrue(itr.hasNext());
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 24 with SOAPBody

use of jakarta.xml.soap.SOAPBody 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 25 with SOAPBody

use of jakarta.xml.soap.SOAPBody in project tomee by apache.

the class Inflate method handleMessage.

public boolean handleMessage(SOAPMessageContext mc) {
    try {
        final SOAPMessage message = mc.getMessage();
        final SOAPBody body = message.getSOAPBody();
        final String localName = body.getFirstChild().getLocalName();
        if ("sumResponse".equals(localName) || "multiplyResponse".equals(localName)) {
            final Node responseNode = body.getFirstChild();
            final Node returnNode = responseNode.getFirstChild();
            final Node intNode = returnNode.getFirstChild();
            final int value = new Integer(intNode.getNodeValue());
            intNode.setNodeValue(Integer.toString(value * 1000));
        }
        return true;
    } catch (SOAPException e) {
        return false;
    }
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) Node(org.w3c.dom.Node) SOAPException(jakarta.xml.soap.SOAPException) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Aggregations

SOAPBody (jakarta.xml.soap.SOAPBody)52 SOAPMessage (jakarta.xml.soap.SOAPMessage)46 SOAPException (jakarta.xml.soap.SOAPException)27 Node (org.w3c.dom.Node)22 QName (javax.xml.namespace.QName)17 WebServiceException (jakarta.xml.ws.WebServiceException)14 MessageFactory (jakarta.xml.soap.MessageFactory)11 SOAPElement (jakarta.xml.soap.SOAPElement)9 NodeList (org.w3c.dom.NodeList)9 Iterator (java.util.Iterator)8 DataHandler (jakarta.activation.DataHandler)6 SOAPEnvelope (jakarta.xml.soap.SOAPEnvelope)6 Service (jakarta.xml.ws.Service)6 StringReader (java.io.StringReader)6 Document (org.w3c.dom.Document)6 SOAPFault (jakarta.xml.soap.SOAPFault)5 Test (org.junit.Test)5 SOAPPart (jakarta.xml.soap.SOAPPart)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Map (java.util.Map)4