Search in sources :

Example 1 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 2 with SOAPBody

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

the class SAAJMessageTest method testWhiteSpaceCharacters.

public void testWhiteSpaceCharacters() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage message = messageFactory.createMessage();
    SOAPBody body = message.getSOAPBody();
    QName name = new QName("testString1");
    SOAPBodyElement bodyElement = body.addBodyElement(name);
    bodyElement.addTextNode("Hello World, ---\003\007\024---");
    name = new QName("testString2");
    bodyElement = body.addBodyElement(name);
    bodyElement.addTextNode("Hello \t\n\r World");
    SAAJMessage saajMsg = new SAAJMessage(message);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
    saajMsg.writeTo(writer);
    writer.close();
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(baos.toString())));
    NodeList nodeList = doc.getElementsByTagName("testString1");
    assertEquals(nodeList.item(0).getFirstChild().getNodeValue(), "Hello World, ------");
    nodeList = doc.getElementsByTagName("testString2");
    assertEquals(nodeList.item(0).getFirstChild().getNodeValue(), "Hello \t\n\r World");
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) InputSource(org.xml.sax.InputSource) MessageFactory(jakarta.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) NodeList(org.w3c.dom.NodeList) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) SOAPMessage(jakarta.xml.soap.SOAPMessage) SOAPBodyElement(jakarta.xml.soap.SOAPBodyElement)

Example 3 with SOAPBody

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

the class SOAPActionTest method testUnquotedSOAPAction1.

public void testUnquotedSOAPAction1() throws Exception {
    TestEndpoint port = new TestEndpointService().getTestEndpointPort1();
    String address = (String) ((BindingProvider) port).getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
    HTTPResponseInfo rInfo = ClientServerTestUtil.sendPOSTRequest(address, s11_request, "text/xml", "http://example.com/action/echo");
    String resp = rInfo.getResponseBody();
    SOAPMessage respMesg = getSOAPMessage(makeStreamSource(resp));
    SOAPBody body = respMesg.getSOAPPart().getEnvelope().getBody();
    Element e = (Element) body.getElementsByTagName("return").item(0);
    // make sure it is dispatched to echo() using SoapAction
    assertEquals("Hello Duke", e.getTextContent());
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) Element(org.w3c.dom.Element) BindingProvider(jakarta.xml.ws.BindingProvider) HTTPResponseInfo(testutil.HTTPResponseInfo) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 4 with SOAPBody

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

the class Client method testMultipleBodies.

public void testMultipleBodies() throws SOAPException {
    if (ClientServerTestUtil.useLocal()) {
        System.out.println("Runs only in HTTP!");
        return;
    }
    Service service = Service.create(new QName("urn:test", "Endpoint"));
    service.addPort(new QName("urn:test", "EndpointPort"), SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:8080/jaxrpc-provider_tests_multiple_body/endpoint");
    Dispatch<SOAPMessage> disp = service.createDispatch(new QName("urn:test", "EndpointPort"), SOAPMessage.class, Service.Mode.MESSAGE);
    SOAPMessage sm = SOAPVersion.SOAP_11.saajMessageFactory.createMessage();
    SOAPBody sb = sm.getSOAPBody();
    sb.addBodyElement(new QName("http://first.body", "first"));
    sb.addBodyElement(new QName("http://second.body", "second"));
    SOAPMessage resp = disp.invoke(sm);
    SOAPBody body = resp.getSOAPBody();
    NodeList nl = body.getChildNodes();
    assertTrue(nl.getLength() == 2);
    Node n = nl.item(0);
    assertTrue(n.getLocalName().equals("first") && n.getNamespaceURI().equals("http://first.body"));
    n = nl.item(1);
    assertTrue(n.getLocalName().equals("second") && n.getNamespaceURI().equals("http://second.body"));
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Service(jakarta.xml.ws.Service) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 5 with SOAPBody

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

Aggregations

SOAPBody (jakarta.xml.soap.SOAPBody)43 SOAPMessage (jakarta.xml.soap.SOAPMessage)37 SOAPException (jakarta.xml.soap.SOAPException)24 Node (org.w3c.dom.Node)15 WebServiceException (jakarta.xml.ws.WebServiceException)14 QName (javax.xml.namespace.QName)11 MessageFactory (jakarta.xml.soap.MessageFactory)9 SOAPElement (jakarta.xml.soap.SOAPElement)9 Iterator (java.util.Iterator)8 SOAPEnvelope (jakarta.xml.soap.SOAPEnvelope)6 DataHandler (jakarta.activation.DataHandler)5 SOAPFault (jakarta.xml.soap.SOAPFault)5 SOAPPart (jakarta.xml.soap.SOAPPart)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Map (java.util.Map)4 Source (javax.xml.transform.Source)4 StreamSource (javax.xml.transform.stream.StreamSource)4 NodeList (org.w3c.dom.NodeList)4 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)3 Name (jakarta.xml.soap.Name)3