Search in sources :

Example 16 with SOAPBody

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

the class ServerHandler method handleMessage.

public boolean handleMessage(SOAPMessageContext context) {
    SOAPMessage sm = context.getMessage();
    try {
        System.out.println("Inside ServerHandler...");
        SOAPBody sb = sm.getSOAPBody();
        Node n = sb.getFirstChild();
        if (n != null) {
            if ((Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
                if (n.getLocalName().equals("echo3Response")) {
                    if (!n.getNamespaceURI().equals("http://example.com/echo3"))
                        throw new WebServiceException("Expected: \"http://example.com/echo3\", got: " + n.getNamespaceURI());
                    else
                        return true;
                }
                if (!n.getNamespaceURI().equals("http://example.com/")) {
                    throw new WebServiceException("Expected: \"http://example.com/\", got: " + n.getNamespaceURI());
                }
            } else {
                if (n.getLocalName().equals("echo3")) {
                    if (!n.getNamespaceURI().equals("http://tempuri.org/wsdl"))
                        throw new WebServiceException("Expected: \"http://tempuri.org/wsdl\", got: " + n.getNamespaceURI());
                    else
                        return true;
                }
                if (!n.getNamespaceURI().equals("http://tempuri.org/")) {
                    throw new WebServiceException("Expected: \"http://tempuri.org/\", got: " + n.getNamespaceURI());
                }
            }
        } else {
            return true;
        }
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    return true;
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) WebServiceException(jakarta.xml.ws.WebServiceException) Node(org.w3c.dom.Node) SOAPException(jakarta.xml.soap.SOAPException) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 17 with SOAPBody

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

the class NonAnonymousResponsesTest method testNonAnonymousReplyTo.

public void testNonAnonymousReplyTo() throws Exception {
    invokeAsync(createDispatchWithoutAddressing(), TestMessages.NON_ANONYMOUS_REPLY_TO_COMPLETE_MESSAGE, S11_NS, nonAnonAddress, action, endpointAddress, "testNonAnonymousReplyTo");
    // Lets see we get a response in 60 s
    SOAPMessage m = respMsgExchanger.exchange(null, TestMessages.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://server.responses.wsa.fromjava/", "addNumbersResponse"));
    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 18 with SOAPBody

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

the class NonAnonymousResponsesTest method testNonAnonymousFaultTo2.

/**
 * Fault response case
 *
 * @throws Exception
 */
public void testNonAnonymousFaultTo2() throws Exception {
    invokeAsync(createDispatchWithoutAddressing(), TestMessages.NON_ANONYMOUS_REPLY_TO_NON_ANONYMOUS_FAULT_TO_COMPLETE_FAULTY_MESSAGE, S11_NS, nonAnonAddress, nonAnonAddress, action, endpointAddress, "testNonAnonymousReplyTo");
    // Lets see we get a response in 60 s
    SOAPMessage m = respMsgExchanger.exchange(null, TestMessages.CLIENT_MAX_TIMEOUT, TimeUnit.SECONDS);
    // System.out.println("****************************");
    // m.writeTo(System.out);
    // System.out.println("\n****************************");
    SOAPBody sb = m.getSOAPBody();
    assertTrue(sb.hasFault());
    SOAPFault fault = sb.getFault();
    assertEquals(fault.getFaultString(), "Negative numbers can't be added!");
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 19 with SOAPBody

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

the class SAAJMessageTester method testDOMLevel1WriteTo.

public void testDOMLevel1WriteTo() throws Exception {
    DocumentBuilderFactory builderFactory = null;
    DocumentBuilder builder = null;
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
    soapEnvelope.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    soapEnvelope.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
    SOAPBody soapBody = soapEnvelope.getBody();
    Name elementName = soapEnvelope.createName("addNumbers", "", "http://duke.org");
    SOAPBodyElement bodyElement = soapBody.addBodyElement(elementName);
    SAAJMessage msg = new SAAJMessage(soapMessage);
    ByteArrayBuffer baos = new ByteArrayBuffer();
    XMLStreamWriter writer = XMLStreamWriterFactory.createXMLStreamWriter(baos);
    msg.writeTo(writer);
    writer.flush();
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) MessageFactory(jakarta.xml.soap.MessageFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope) SOAPMessage(jakarta.xml.soap.SOAPMessage) Name(jakarta.xml.soap.Name) QName(javax.xml.namespace.QName) SOAPBodyElement(jakarta.xml.soap.SOAPBodyElement) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 20 with SOAPBody

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

the class ProviderImpl method invoke.

/* 
     */
public Source invoke(Source msg) {
    if (!isInjectionDone()) {
        throw new WebServiceException("Injection is not done");
    }
    // Test if we got the correct SOAPMessage that has handler changes
    try {
        MessageFactory fact = MessageFactory.newInstance();
        SOAPMessage soap = fact.createMessage();
        soap.getSOAPPart().setContent(msg);
        SOAPBody body = soap.getSOAPBody();
        Iterator i = body.getChildElements();
        SOAPElement elem = (SOAPElement) i.next();
        QName name = elem.getElementQName();
        QName exp = new QName("urn:test:types", "MyVoidTest");
        if (!exp.equals(name)) {
            throw new WebServiceException("Handler changes aren't reflected");
        }
    } catch (SOAPException e) {
        throw new WebServiceException("Got Incorrect Source");
    }
    printContext();
    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()));
    return source;
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) WebServiceException(jakarta.xml.ws.WebServiceException) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) SOAPException(jakarta.xml.soap.SOAPException) StreamSource(javax.xml.transform.stream.StreamSource) Iterator(java.util.Iterator) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPMessage(jakarta.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource)

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