Search in sources :

Example 6 with SOAPMessage

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

use of jakarta.xml.soap.SOAPMessage 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 8 with SOAPMessage

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

the class PacketTest method testEncodeDecodedPacketMtom.

/**
 * Tests that a server response Packet with MTOM feature, but
 * decoded from an InputStream with a user specified non-MTOM
 * content type, does NOT use MTOM when re-encoded
 */
public void testEncodeDecodedPacketMtom() throws Exception {
    String msg = "<?xml version='1.0' encoding='UTF-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soapenv:Body><soapenv:Fault>" + "<faultcode>soapenv:Server</faultcode>" + "<faultstring>ABC-380001:Internal Server Error</faultstring>" + "<detail><con:fault xmlns:con=\"http://www.bea.com/wli/sb/context\">" + "<con:errorCode>ABC-380001</con:errorCode>" + "<con:reason>Internal Server Error</con:reason>" + "<con:location><con:node>RouteNode1</con:node><con:path>response-pipeline</con:path></con:location>" + "</con:fault></detail>" + "</soapenv:Fault></soapenv:Body></soapenv:Envelope>";
    WebServiceFeature[] features = { new MTOMFeature(true, 0) };
    MessageContextFactory mcf = new MessageContextFactory(features);
    Packet fakeRequest = (Packet) mcf.createContext();
    Packet p = (Packet) mcf.createContext(new ByteArrayInputStream(msg.getBytes()), "text/xml");
    fakeRequest.relateServerResponse(p, null, null, BindingImpl.create(BindingID.SOAP11_HTTP, features));
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    p.writeTo(bos);
    String writtenMsg = new String(bos.toByteArray());
    System.out.println(writtenMsg);
    assertEquals("text/xml", p.getContentType().getContentType());
    // try reading the message as a soap message with text/xml - this should succeed
    // in parsing the message
    Packet reReadPacket = (Packet) mcf.createContext(new ByteArrayInputStream(writtenMsg.getBytes()), "text/xml");
    SOAPMessage soap = reReadPacket.getAsSOAPMessage();
    Node bodyChild = soap.getSOAPBody().getFirstChild();
    assertEquals("Fault", bodyChild.getLocalName());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) Node(org.w3c.dom.Node) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 9 with SOAPMessage

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

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

the class SAAJFactory method readAsSOAPMessageSax2Dom.

public SOAPMessage readAsSOAPMessageSax2Dom(final SOAPVersion soapVersion, final Message message) throws SOAPException {
    SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
    SAX2DOMEx s2d = new SAX2DOMEx(msg.getSOAPPart());
    try {
        message.writeTo(s2d, XmlUtil.DRACONIAN_ERROR_HANDLER);
    } catch (SAXException e) {
        throw new SOAPException(e);
    }
    addAttachmentsToSOAPMessage(msg, message);
    if (msg.saveRequired())
        msg.saveChanges();
    return msg;
}
Also used : SOAPException(jakarta.xml.soap.SOAPException) SAX2DOMEx(org.glassfish.jaxb.core.marshaller.SAX2DOMEx) SOAPMessage(jakarta.xml.soap.SOAPMessage) SAXException(org.xml.sax.SAXException)

Aggregations

SOAPMessage (jakarta.xml.soap.SOAPMessage)181 MessageFactory (jakarta.xml.soap.MessageFactory)66 ByteArrayInputStream (java.io.ByteArrayInputStream)51 SOAPBody (jakarta.xml.soap.SOAPBody)37 SOAPException (jakarta.xml.soap.SOAPException)36 QName (javax.xml.namespace.QName)31 MimeHeaders (jakarta.xml.soap.MimeHeaders)27 Source (javax.xml.transform.Source)25 StreamSource (javax.xml.transform.stream.StreamSource)25 WebServiceException (jakarta.xml.ws.WebServiceException)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)19 Element (org.w3c.dom.Element)18 Node (org.w3c.dom.Node)18 Packet (com.sun.xml.ws.api.message.Packet)17 Message (com.sun.xml.ws.api.message.Message)16 Iterator (java.util.Iterator)14 SOAPElement (jakarta.xml.soap.SOAPElement)12 AttachmentPart (jakarta.xml.soap.AttachmentPart)11 Dispatch (jakarta.xml.ws.Dispatch)10