Search in sources :

Example 81 with SOAPException

use of javax.xml.soap.SOAPException in project jbossws-cxf by jbossws.

the class SOAPHandler method handleInbound.

@Override
protected boolean handleInbound(final SOAPMessageContext msgContext) {
    log.info("handleInbound()");
    try {
        SOAPMessage message = msgContext.getMessage();
        SOAPBody body = message.getSOAPBody();
        Document document = body.extractContentAsDocument();
        Node node = document;
        log.info(DOMWriter.printNode(node, true));
        NodeList nodes = node.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node current = nodes.item(i);
            NodeList childNodes = current.getChildNodes();
            for (int j = 0; j < childNodes.getLength(); j++) {
                Node currentChildNode = childNodes.item(j);
                if ("result".equals(currentChildNode.getLocalName())) {
                    currentChildNode.setTextContent(currentChildNode.getTextContent() + " modified in handler");
                }
            }
        }
        log.info(DOMWriter.printNode(node, true));
        // Add document back as removed by call to 'extractContentAsDocument()'
        body.addDocument(document);
        message.saveChanges();
    } catch (SOAPException e) {
        throw new RuntimeException("Error in Handler", e);
    }
    log.info("Finished");
    return true;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) SOAPException(javax.xml.soap.SOAPException) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 82 with SOAPException

use of javax.xml.soap.SOAPException in project jbossws-cxf by jbossws.

the class EndpointHandler method handleOutbound.

@Override
protected boolean handleOutbound(SOAPMessageContext msgContext) {
    log.info("handleOutbound");
    try {
        SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
        soapMessage.getSOAPHeader();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        // SOAPFactory soapFactory = SOAPFactory.newInstance();
        // Name headerName = soapFactory.createName("EndpointHandlerOutbound", "ns1", "http://somens");
        // SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
        // she.setValue("true");
        SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
        SOAPElement soapElement = (SOAPElement) soapBodyElement.getChildElements().next();
        String value = soapElement.getValue();
        soapElement.setValue(value + "|EpOut");
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    return true;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) WebServiceException(javax.xml.ws.WebServiceException) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 83 with SOAPException

use of javax.xml.soap.SOAPException in project jbossws-cxf by jbossws.

the class RoutingHandler method handleInbound.

@Override
protected boolean handleInbound(SOAPMessageContext msgContext) {
    log.info("handleInbound");
    try {
        SOAPMessage soapMessage = msgContext.getMessage();
        soapMessage.getSOAPHeader();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        // SOAPFactory soapFactory = SOAPFactory.newInstance();
        // Name headerName = soapFactory.createName("RoutingHandlerInbound", "ns1", "http://somens");
        // SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
        // she.setValue("true");
        SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
        SOAPElement soapElement = (SOAPElement) soapBodyElement.getChildElements().next();
        String value = soapElement.getValue();
        soapElement.setValue(value + "|RoutIn");
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    return true;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 84 with SOAPException

use of javax.xml.soap.SOAPException in project jbossws-cxf by jbossws.

the class ServerHandler method appendContentToRequestElement.

private void appendContentToRequestElement(SOAPMessage message, boolean wsaEnabled) {
    try {
        Iterator<?> ite = message.getSOAPBody().getChildElements(new QName("http://TestEndpoint.org/xsd", "MtomRequest"));
        SOAPElement element = (SOAPElement) ite.next();
        SOAPElement requestElement = (SOAPElement) element.getChildElements(new QName("", "request")).next();
        if (wsaEnabled) {
            requestElement.setTextContent("--ClientAddressingEnabled");
        } else {
            requestElement.setTextContent("--ClientAddressingNotEnabled");
        }
    } catch (SOAPException e) {
    }
}
Also used : QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement)

Example 85 with SOAPException

use of javax.xml.soap.SOAPException in project jbossws-cxf by jbossws.

the class CustomHandler method handleInbound.

@Override
protected boolean handleInbound(SOAPMessageContext msgContext) {
    try {
        SOAPMessage soapMessage = msgContext.getMessage();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
        if (soapBodyElement.getChildElements().hasNext()) {
            SOAPElement payload = (SOAPElement) soapBodyElement.getChildElements().next();
            String value = payload.getValue();
            payload.setValue(value + "World");
        }
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    return true;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Aggregations

SOAPException (javax.xml.soap.SOAPException)225 SOAPMessage (javax.xml.soap.SOAPMessage)135 SOAPElement (javax.xml.soap.SOAPElement)71 SOAPBody (javax.xml.soap.SOAPBody)62 WebServiceException (javax.xml.ws.WebServiceException)57 IOException (java.io.IOException)53 Element (org.w3c.dom.Element)36 QName (javax.xml.namespace.QName)33 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)33 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)28 SOAPFault (javax.xml.soap.SOAPFault)27 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)25 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)24 Node (org.w3c.dom.Node)23 SOAPFactory (javax.xml.soap.SOAPFactory)22 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)20 SOAPHeader (javax.xml.soap.SOAPHeader)19 SOAPPart (javax.xml.soap.SOAPPart)19 Iterator (java.util.Iterator)17 Fault (org.apache.cxf.interceptor.Fault)16