Search in sources :

Example 1 with MessageFactory

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

the class AddNumbersClient method invokeAsyncPollAddNumbers.

private void invokeAsyncPollAddNumbers(String msgString) throws RemoteException {
    SOAPMessage message = null;
    try {
        MessageFactory factory = MessageFactory.newInstance();
        message = factory.createMessage();
        message.getSOAPPart().setContent((Source) new StreamSource(new StringReader(msgString)));
        message.saveChanges();
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    Dispatch<SOAPMessage> smDispatch = null;
    smDispatch = service.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE);
    System.out.println("\nInvoking async poll message: " + msgString);
    Response<SOAPMessage> response = smDispatch.invokeAsync(message);
    while (!response.isDone()) {
    // go do some work
    }
    String xmlString = null;
    try {
        SOAPMessage result = response.get();
        Source sourceResult = (Source) result.getSOAPPart().getContent();
        xmlString = sourceToXMLString(sourceResult);
    } catch (SOAPException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    System.out.println("Received response: " + xmlString);
}
Also used : MessageFactory(jakarta.xml.soap.MessageFactory) StreamSource(javax.xml.transform.stream.StreamSource) SOAPException(jakarta.xml.soap.SOAPException) StringReader(java.io.StringReader) ExecutionException(java.util.concurrent.ExecutionException) SOAPMessage(jakarta.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 2 with MessageFactory

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

the class AddNumbersClient method invokeAsyncCallbackAddNumbers.

private void invokeAsyncCallbackAddNumbers(String msgString) throws RemoteException {
    SOAPMessage message = null;
    try {
        MessageFactory factory = MessageFactory.newInstance();
        message = factory.createMessage();
        message.getSOAPPart().setContent((Source) new StreamSource(new StringReader(msgString)));
        message.saveChanges();
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    Dispatch smDispatch = null;
    smDispatch = service.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE);
    System.out.println("\nInvoking async callback message: " + msgString);
    DispatchAsyncHandler handler = new DispatchAsyncHandler();
    Future<?> response = smDispatch.invokeAsync(message, handler);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    if (response.isDone()) {
        if (handler.isFailure()) {
            Throwable failure = handler.getFailure();
            System.out.println("Failure in DispatchAsyncHandler " + failure.getMessage());
        } else
            System.out.println("Success processing result!");
    }
}
Also used : MessageFactory(jakarta.xml.soap.MessageFactory) StreamSource(javax.xml.transform.stream.StreamSource) SOAPException(jakarta.xml.soap.SOAPException) StringReader(java.io.StringReader) Dispatch(jakarta.xml.ws.Dispatch) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 3 with MessageFactory

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

the class ReplaceAddressingHeaderTest method makeSOAPMessage.

private SOAPMessage makeSOAPMessage(String msg) throws Exception {
    MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage message = factory.createMessage();
    Source src = new StreamSource(new ByteArrayInputStream(msg.getBytes()));
    message.getSOAPPart().setContent(src);
    return message;
}
Also used : MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamSource(javax.xml.transform.stream.StreamSource) SOAPMessage(jakarta.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 4 with MessageFactory

use of jakarta.xml.soap.MessageFactory 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, ---&#3;&#7;&#20;---");
    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 5 with MessageFactory

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

the class SAAJMessageTest method test1.

public void test1() throws Exception {
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    Source src = new StreamSource(new ByteArrayInputStream(MESSAGE.getBytes()));
    message.getSOAPPart().setContent(src);
    SAAJMessage saajMsg = new SAAJMessage(message);
    assertEquals("addNumbers", saajMsg.getPayloadLocalPart());
    assertEquals("http://example.com/addNumbers", AddressingUtils.getAction(saajMsg.getHeaders(), AddressingVersion.W3C, SOAPVersion.SOAP_11));
    Header header = new StringHeader(new QName("urn:foo", "header1"), "test header  ");
    saajMsg.getHeaders().add(header);
    SOAPMessage newMsg = saajMsg.readAsSOAPMessage();
    newMsg.writeTo(System.out);
    SAAJMessage saajMsg2 = new SAAJMessage(newMsg);
    assertEquals(2, saajMsg2.getHeaders().asList().size());
    Message saajMsg3 = saajMsg2.copy();
    assertEquals("addNumbers", saajMsg3.getPayloadLocalPart());
    assertEquals("http://example.com/addNumbers", AddressingUtils.getAction(saajMsg3.getHeaders(), AddressingVersion.W3C, SOAPVersion.SOAP_11));
    assertEquals(2, saajMsg2.getHeaders().asList().size());
    XMLStreamWriter writer = XMLStreamWriterFactory.create(System.out);
    saajMsg3.writeTo(writer);
    writer.close();
}
Also used : StringHeader(com.sun.xml.ws.message.StringHeader) MessageFactory(jakarta.xml.soap.MessageFactory) StringHeader(com.sun.xml.ws.message.StringHeader) Header(com.sun.xml.ws.api.message.Header) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StreamSource(javax.xml.transform.stream.StreamSource) SOAPMessage(jakarta.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource)

Aggregations

MessageFactory (jakarta.xml.soap.MessageFactory)66 SOAPMessage (jakarta.xml.soap.SOAPMessage)66 ByteArrayInputStream (java.io.ByteArrayInputStream)36 StreamSource (javax.xml.transform.stream.StreamSource)22 Source (javax.xml.transform.Source)20 MimeHeaders (jakarta.xml.soap.MimeHeaders)19 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)16 Packet (com.sun.xml.ws.api.message.Packet)13 SOAPException (jakarta.xml.soap.SOAPException)12 Element (org.w3c.dom.Element)12 Message (com.sun.xml.ws.api.message.Message)10 SOAPBody (jakarta.xml.soap.SOAPBody)9 QName (javax.xml.namespace.QName)9 InputSource (org.xml.sax.InputSource)7 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)6 AttachmentPart (jakarta.xml.soap.AttachmentPart)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 SOAPElement (jakarta.xml.soap.SOAPElement)5 IOException (java.io.IOException)5 SOAPEnvelope (jakarta.xml.soap.SOAPEnvelope)4