Search in sources :

Example 61 with SOAPException

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

Example 62 with SOAPException

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

the class HelloImpl method invoke.

public SOAPMessage invoke(SOAPMessage msg) {
    SOAPBody body;
    try {
        body = msg.getSOAPBody();
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    Node node = body.getFirstChild();
    if (!node.getLocalName().equals("Hello")) {
        throw new WebServiceException("Expecting localName=Hello but got=" + node.getLocalName());
    }
    if (!node.getNamespaceURI().equals("urn:test:types")) {
        throw new WebServiceException("Expecting NS=urn:test:types but got=" + node.getNamespaceURI());
    }
    MimeHeaders headers = msg.getMimeHeaders();
    /*
        Iterator i = headers.getAllHeaders();
        while(i.hasNext()) {
            MimeHeader header = (MimeHeader)i.next();
            System.out.println("name="+header.getName()+" value="+header.getValue());
        }
*/
    String[] action = headers.getHeader("SOAPAction");
    if (action == null || action.length > 1 || !action[0].equals("\"urn:test:hello\"")) {
        throw new WebServiceException("SOAPMessage doesn't contain transport header: SOAPAction");
    }
    String[] ct = headers.getHeader("Content-Type");
    if (ct == null || ct.length > 1 || !ct[0].startsWith("text/xml")) {
        throw new WebServiceException("SOAPMessage doesn't contain transport header: Content-Type");
    }
    return null;
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) SOAPBody(jakarta.xml.soap.SOAPBody) WebServiceException(jakarta.xml.ws.WebServiceException) SOAPException(jakarta.xml.soap.SOAPException) Node(org.w3c.dom.Node)

Example 63 with SOAPException

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

the class EndpointImpl method invoke.

public SOAPMessage invoke(SOAPMessage request) {
    System.out.println("Received request!");
    try {
        SOAPBody body = request.getSOAPBody();
        NodeList nl = body.getChildNodes();
        if (nl.getLength() != 2) {
            throw new WebServiceException("Expected two body got one");
        }
        for (int i = 0; i < nl.getLength(); i++) {
            Node n = nl.item(i);
            if (i == 0 && (!n.getLocalName().equals("first") || !n.getNamespaceURI().equals("http://first.body"))) {
                throw new WebServiceException("Invalid first body");
            }
            if (i == 1 && (!n.getLocalName().equals("second") || !n.getNamespaceURI().equals("http://second.body"))) {
                throw new WebServiceException("Invalid second body");
            }
        }
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    return request;
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) SOAPException(jakarta.xml.soap.SOAPException)

Example 64 with SOAPException

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

the class SimpleHandler method doSomeWork.

protected void doSomeWork(SOAPMessageContext context) {
    if (dosomething) {
        try {
            SOAPMessage message = context.getMessage();
            SOAPPart sp = message.getSOAPPart();
            SOAPEnvelope se = sp.getEnvelope();
            SOAPBody sb = se.getBody();
        } catch (SOAPException e) {
            e.printStackTrace();
        }
    }
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) SOAPException(jakarta.xml.soap.SOAPException) SOAPPart(jakarta.xml.soap.SOAPPart) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 65 with SOAPException

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

SOAPException (jakarta.xml.soap.SOAPException)71 SOAPMessage (jakarta.xml.soap.SOAPMessage)37 WebServiceException (jakarta.xml.ws.WebServiceException)30 SOAPBody (jakarta.xml.soap.SOAPBody)26 Node (org.w3c.dom.Node)20 QName (javax.xml.namespace.QName)13 MessageFactory (jakarta.xml.soap.MessageFactory)12 SOAPFault (jakarta.xml.soap.SOAPFault)12 SOAPElement (jakarta.xml.soap.SOAPElement)10 XMLStreamException (javax.xml.stream.XMLStreamException)8 DataHandler (jakarta.activation.DataHandler)6 StreamSource (javax.xml.transform.stream.StreamSource)6 SOAPHeader (jakarta.xml.soap.SOAPHeader)5 SOAPPart (jakarta.xml.soap.SOAPPart)5 StringReader (java.io.StringReader)5 Map (java.util.Map)5 Source (javax.xml.transform.Source)5 Message (com.sun.xml.ws.api.message.Message)4 SOAPFactory (jakarta.xml.soap.SOAPFactory)4 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)4