Search in sources :

Example 96 with SOAPMessage

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

the class SOAPMsgProvider method invoke.

public SOAPMessage invoke(SOAPMessage msg) {
    Iterator it = msg.getAttachments();
    if (!it.hasNext()) {
        throw new WebServiceException("Service didn't receive any attachments.");
    }
    AttachmentPart part = (AttachmentPart) it.next();
    if (!part.getContentId().equals("<SOAPTestHandler@example.jaxws.sun.com>")) {
        throw new WebServiceException("Attachment Content-ID expected=" + "SOAPTestHandler@example.jaxws.sun.com got=" + part.getContentId());
    }
    try {
        // keeping white space in the string is intentional
        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()));
        MessageFactory fact = MessageFactory.newInstance();
        SOAPMessage soap = fact.createMessage();
        soap.getSOAPPart().setContent(source);
        soap.getMimeHeaders().addHeader("foo", "bar");
        return soap;
    } catch (Exception e) {
        throw new WebServiceException(e);
    }
}
Also used : MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamSource(javax.xml.transform.stream.StreamSource) Iterator(java.util.Iterator) AttachmentPart(jakarta.xml.soap.AttachmentPart) SOAPMessage(jakarta.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 97 with SOAPMessage

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

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

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

the class EchoClientTest method test1170.

/**
 * SOAP 1.1 two-way message with wsa:From.
 */
public void test1170() throws Exception {
    SOAPMessage response = invoke(createDispatchWithWSDLWithoutAddressing(), MESSAGES.getFromMustUnderstandEchoMessage(), S11_NS, getAddress(), ECHO_IN_ACTION, "test1170");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    response.writeTo(baos);
    assertXpathExists(ENVELOPE_HEADER, baos.toString());
    assertXpathExists(ACTION_HEADER, baos.toString());
    assertXpathEvaluatesTo(ACTION_HEADER, baos.toString(), ECHO_OUT_ACTION);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 100 with SOAPMessage

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

the class NonAnonymousClientTest method test1194.

/**
 * SOAP 1.1 two-way message with a non-anonymous ReplyTo and FaultTo address.
 */
public void test1194() throws Exception {
    invokeAsync(createDispatchForNonAnonymousWithWSDLWithoutAddressing(), MESSAGES.getNonAnonymousReplyToMessage(), S11_NS, getNonAnonymousEndpointAddress(), clientAddress, ECHO_IN_ACTION, "fault-test1194");
    // 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****************************");
    SOAPFault f = m.getSOAPBody().getFault();
    assertNotNull(f);
    assertEquals(USER_FAULT_CODE, f.getFaultCodeAsQName());
}
Also used : SOAPFault(jakarta.xml.soap.SOAPFault) SOAPMessage(jakarta.xml.soap.SOAPMessage)

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