Package org.apache.servicemix.soap

Examples of org.apache.servicemix.soap.SoapFault


        Document doc = factory.newDocumentBuilder().parse(is);
        message.setDocument(doc);
        Element env = doc.getDocumentElement();
        QName envName = DOMUtil.getQName(env);
        if (!envName.getLocalPart().equals(SoapMarshaler.ENVELOPE)) {
            throw new SoapFault(SoapFault.SENDER, "Unrecognized element: "
                    + envName + ". Expecting 'Envelope'.");
        }
        message.setEnvelopeName(envName);
        // Check soap 1.1 or 1.2
        String soapUri = envName.getNamespaceURI();
        if (!SoapMarshaler.SOAP_11_URI.equals(soapUri) && !SoapMarshaler.SOAP_12_URI.equals(soapUri)) {
            throw new SoapFault(SoapFault.SENDER, "Unrecognized namespace: " + soapUri
                    + " for element 'Envelope'.");
        }
        // Check Headers
        Element child = DOMUtil.getFirstChildElement(env);
        if (DOMUtil.getQName(child).equals(new QName(soapUri, SoapMarshaler.HEADER))) {
            parseHeaders(message, child);
            child = DOMUtil.getNextSiblingElement(child);
        }
        // Check Body
        if (!DOMUtil.getQName(child).equals(new QName(soapUri, SoapMarshaler.BODY))) {
            throw new SoapFault(SoapFault.SENDER, "Unrecognized element: "
                    + DOMUtil.getQName(child) + ". Expecting 'Body'.");
        }
        // Create Source for content
        child = DOMUtil.getFirstChildElement(child);
        if (child != null) {
            QName childName = DOMUtil.getQName(child);
            message.setBodyName(childName);
            // Check for fault
            if (childName.equals(new QName(soapUri, SoapMarshaler.FAULT))) {
                message.setFault(readFaultUsingDom(child));
            } else {
                message.setSource(new DOMSource(child));
            }
        }
        child = DOMUtil.getNextSiblingElement(child);
        if (child != null) {
            throw new SoapFault(SoapFault.RECEIVER, "Body element has more than one child element.");
        }
        return message;
    }
View Full Code Here


    XMLStreamReader reader = marshaler.getInputFactory().createXMLStreamReader(is);
    reader = new ExtendedXMLStreamReader(reader);
    reader.nextTag();
    // Check Envelope tag
    if (!reader.getLocalName().equals(SoapMarshaler.ENVELOPE)) {
      throw new SoapFault(SoapFault.SENDER, "Unrecognized element: "
          + reader.getName() + " at ["
          + reader.getLocation().getLineNumber() + ","
          + reader.getLocation().getColumnNumber()
          + "]. Expecting 'Envelope'.");
    }
    message.setEnvelopeName(reader.getName());
    // Check soap 1.1 or 1.2
    String soapUri = reader.getNamespaceURI();
    if (!SoapMarshaler.SOAP_11_URI.equals(soapUri) && !SoapMarshaler.SOAP_12_URI.equals(soapUri)) {
      throw new SoapFault(SoapFault.SENDER, "Unrecognized namespace: " + soapUri
          + " for element 'Envelope' at ["
          + reader.getLocation().getLineNumber() + ","
          + reader.getLocation().getColumnNumber()
          + "]. Expecting 'Envelope'.");
    }
    // Check Headers
    reader.nextTag();
    if (reader.getName().equals(new QName(soapUri, SoapMarshaler.HEADER))) {
      parseHeaders(message, reader);
      reader.nextTag();
    }
    // Check Body
    if (!reader.getName().equals(new QName(soapUri, SoapMarshaler.BODY))) {
      throw new SoapFault(SoapFault.SENDER, "Unrecognized element: "
          + reader.getName() + " at ["
          + reader.getLocation().getLineNumber() + ","
          + reader.getLocation().getColumnNumber()
          + "]. Expecting 'Body'.");
    }
View Full Code Here

                Element subchild = DOMUtil.getFirstChildElement(child);
                if (subchild != null) {
                    details = new DOMSource(subchild);
                    subchild = DOMUtil.getNextSiblingElement(subchild);
                    if (subchild != null) {
                        throw new SoapFault(SoapFault.RECEIVER, "Multiple elements are not supported in Detail");
                    }
                }
                child = DOMUtil.getNextSiblingElement(child);
                childname = DOMUtil.getQName(child);
            }
            // Nothing should be left
            if (childname != null) {
                throw new SoapFault(SoapFault.SENDER, "Unexpected element: " + childname);
            }
        // Parse soap 1.2 faults
        } else {
            // Fault code
            Element child = DOMUtil.getFirstChildElement(element);
            checkElementName(child, SoapMarshaler.SOAP_12_FAULTCODE);
            Element subchild = DOMUtil.getFirstChildElement(child);
            checkElementName(subchild, SoapMarshaler.SOAP_12_FAULTVALUE);
            code = DOMUtil.createQName(subchild, DOMUtil.getElementText(subchild));
            if (!SoapMarshaler.SOAP_12_CODE_DATAENCODINGUNKNOWN.equals(code) &&
                !SoapMarshaler.SOAP_12_CODE_MUSTUNDERSTAND.equals(code) &&
                !SoapMarshaler.SOAP_12_CODE_RECEIVER.equals(code) &&
                !SoapMarshaler.SOAP_12_CODE_SENDER.equals(code) &&
                !SoapMarshaler.SOAP_12_CODE_VERSIONMISMATCH.equals(code)) {
                throw new SoapFault(SoapFault.SENDER, "Unexpected fault code: " + code);
            }
            subchild = DOMUtil.getNextSiblingElement(subchild);
            if (subchild != null) {
                checkElementName(subchild, SoapMarshaler.SOAP_12_FAULTSUBCODE);
                Element subsubchild = DOMUtil.getFirstChildElement(subchild);
                checkElementName(subsubchild, SoapMarshaler.SOAP_12_FAULTVALUE);
                subcode = DOMUtil.createQName(subsubchild, DOMUtil.getElementText(subsubchild));
                subsubchild = DOMUtil.getNextSiblingElement(subsubchild);
                if (subsubchild != null) {
                    checkElementName(subsubchild, SoapMarshaler.SOAP_12_FAULTSUBCODE);
                    throw new SoapFault(SoapFault.RECEIVER, "Unsupported nested subcodes");
                }
            }
            // Fault reason
            child = DOMUtil.getNextSiblingElement(child);
            checkElementName(child, SoapMarshaler.SOAP_12_FAULTREASON);
            subchild = DOMUtil.getFirstChildElement(child);
            checkElementName(subchild, SoapMarshaler.SOAP_12_FAULTTEXT);
            reason = DOMUtil.getElementText(subchild);
            subchild = DOMUtil.getNextSiblingElement(subchild);
            if (subchild != null) {
                throw new SoapFault(SoapFault.RECEIVER, "Unsupported multiple reasons");
            }
            // Fault node
            child = DOMUtil.getNextSiblingElement(child);
            QName childname = DOMUtil.getQName(child);
            if (SoapMarshaler.SOAP_12_FAULTNODE.equals(childname)) {
                node = URI.create(DOMUtil.getElementText(child));
                child = DOMUtil.getNextSiblingElement(child);
                childname = DOMUtil.getQName(child);
            }
            // Fault role
            if (SoapMarshaler.SOAP_12_FAULTROLE.equals(childname)) {
                role = URI.create(DOMUtil.getElementText(child));
                child = DOMUtil.getNextSiblingElement(child);
                childname = DOMUtil.getQName(child);
            }
            // Fault details
            if (SoapMarshaler.SOAP_12_FAULTDETAIL.equals(childname)) {
                subchild = DOMUtil.getFirstChildElement(child);
                if (subchild != null) {
                    details = new DOMSource(subchild);
                    subchild = DOMUtil.getNextSiblingElement(subchild);
                    if (subchild != null) {
                        throw new SoapFault(SoapFault.RECEIVER, "Multiple elements are not supported in Detail");
                    }
                }
                child = DOMUtil.getNextSiblingElement(child);
                childname = DOMUtil.getQName(child);
            }
            // Nothing should be left
            if (childname != null) {
                throw new SoapFault(SoapFault.SENDER, "Unexpected element: " + childname);
            }
        }
        SoapFault fault = new SoapFault(code, subcode, reason, node, role, details);
        return fault;
    }
View Full Code Here

                    new StaxSource(rh));
            return readFaultUsingDom(doc.getDocumentElement());
        } catch (SoapFault e) {
            throw e;
        } catch (Exception e) {
            throw new SoapFault(e);
        }
    }
View Full Code Here

    }
   
    private void checkElementName(Element element, QName expected) throws SoapFault {
        QName name= DOMUtil.getQName(element);
        if (!expected.equals(name)) {
            throw new SoapFault(SoapFault.SENDER, "Expected element: " + expected + " but found " + name);
        }           
    }
View Full Code Here

          Object value = headers.get(qname);
                if (isWSANamespace(qname.getNamespaceURI())) {
            if (nsUri == null) {
              nsUri = qname.getNamespaceURI();
            } else if (!nsUri.equals(qname.getNamespaceURI())) {
              throw new SoapFault(SoapFault.SENDER, "Inconsistent use of wsa namespaces");
            }
            if (EL_ACTION.equals(qname.getLocalPart())) {
              action = getHeaderText(value);
                String[] parts = split(action);
                context.setProperty(Context.INTERFACE, new QName(parts[0], parts[1]));
View Full Code Here

                wsResult = secEngine.processSecurityHeader(
                                doc, actor, handler,
                                reqData.getSigCrypto(),
                                reqData.getDecCrypto());
            } catch (WSSecurityException ex) {
                throw new SoapFault(ex);
            }

            if (wsResult == null) { // no security header found
                if (doAction == WSConstants.NO_SECURITY) {
                    return;
                } else {
                    throw new SoapFault(new WSSecurityException(
                                    "WSSecurityHandler: Request does not contain required Security header"));
                }
            }

            if (reqData.getWssConfig().isEnableSignatureConfirmation()) {
                checkSignatureConfirmation(reqData, wsResult);
            }

            /*
             * Now we can check the certificate used to sign the message. In the
             * following implementation the certificate is only trusted if
             * either it itself or the certificate of the issuer is installed in
             * the keystore.
             *
             * Note: the method verifyTrust(X509Certificate) allows custom
             * implementations with other validation algorithms for subclasses.
             */

            // Extract the signature action result from the action vector
            WSSecurityEngineResult actionResult = WSSecurityUtil.fetchActionResult(wsResult, WSConstants.SIGN);

            if (actionResult != null) {
                X509Certificate returnCert = actionResult.getCertificate();

                if (returnCert != null) {
                    if (!verifyTrust(returnCert, reqData)) {
                        throw new SoapFault(new WSSecurityException(
                                        "WSSecurityHandler: the certificate used for the signature is not trusted"));
                    }
                }
            }

            /*
             * Perform further checks on the timestamp that was transmitted in
             * the header. In the following implementation the timestamp is
             * valid if it was created after (now-ttl), where ttl is set on
             * server side, not by the client.
             *
             * Note: the method verifyTimestamp(Timestamp) allows custom
             * implementations with other validation algorithms for subclasses.
             */

            // Extract the timestamp action result from the action vector
            actionResult = WSSecurityUtil.fetchActionResult(wsResult, WSConstants.TS);

            if (actionResult != null) {
                Timestamp timestamp = actionResult.getTimestamp();

                if (timestamp != null) {
                    if (!verifyTimestamp(timestamp, decodeTimeToLive(reqData))) {
                        throw new SoapFault(new WSSecurityException(
                                        "WSSecurityHandler: the timestamp could not be validated"));
                    }
                }
            }

            /*
             * now check the security actions: do they match, in right order?
             */
            if (!checkReceiverResults(wsResult, actions)) {
                throw new SoapFault(new WSSecurityException(
                                "WSSecurityHandler: security processing failed (actions mismatch)"));

            }
            /*
             * All ok up to this point. Now construct and setup the security
View Full Code Here

            }
           
            doSenderAction(doAction, doc, reqData, actions, true);
        }
        catch (WSSecurityException e) {
            throw new SoapFault(e);
        }
        finally {
            reqData.clear();
            reqData = null;
        }
View Full Code Here

    private void writeSoap11Fault(XMLStreamWriter writer) throws Exception {
        QName envelope = getEnvelopeName();
        String soapUri = envelope.getNamespaceURI();
        String soapPrefix = envelope.getPrefix();
        writer.setPrefix(soapPrefix, soapUri);
        SoapFault fault = message.getFault();
        fault.translateCodeTo11();

        writer.writeStartElement(soapPrefix, SoapMarshaler.FAULT, soapUri);
        QName code = fault.getCode();
        if (code != null) {
            XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_11_FAULTCODE);
            XMLStreamHelper.writeTextQName(writer, code);
            writer.writeEndElement();
        }
        String reason = fault.getReason();
        if (reason == null && fault.getCause() != null) {
            reason = fault.getCause().toString();
        }
        XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_11_FAULTSTRING);
        if (reason != null) {
            writer.writeCharacters(reason);
        }
        writer.writeEndElement();
        URI node = fault.getNode();
        if (node != null) {
            XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_11_FAULTACTOR);
            writer.writeCharacters(node.toString());
            writer.writeEndElement();
        }
        Source details = fault.getDetails();
        if (details != null) {
            XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_11_FAULTDETAIL);
            XMLStreamReader reader = marshaler.getSourceTransformer().toXMLStreamReader(details);
            XMLStreamHelper.copy(reader, writer);
            writer.writeEndElement();
View Full Code Here

    private void writeSoap12Fault(XMLStreamWriter writer) throws Exception {
        QName envelope = getEnvelopeName();
        String soapUri = envelope.getNamespaceURI();
        String soapPrefix = envelope.getPrefix();
        writer.setPrefix(soapPrefix, soapUri);
        SoapFault fault = message.getFault();
        fault.translateCodeTo12();
       
        writer.writeStartElement(soapPrefix, SoapMarshaler.FAULT, soapUri);
        QName code = fault.getCode();
        if (code != null) {
            XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTCODE);
            XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTVALUE);
            XMLStreamHelper.writeTextQName(writer, code);
            writer.writeEndElement();
            QName subcode = fault.getSubcode();
            if (subcode != null) {
                XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTSUBCODE);
                XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTVALUE);
                XMLStreamHelper.writeTextQName(writer, subcode);
                writer.writeEndElement();
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
        String reason = fault.getReason();
        if (reason == null && fault.getCause() != null) {
            reason = fault.getCause().toString();
        }
        XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTREASON);
        XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTTEXT);
        writer.writeAttribute(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI, "lang", "en");
        if (reason != null) {
            writer.writeCharacters(reason);
        }
        writer.writeEndElement();
        writer.writeEndElement();
        URI node = fault.getNode();
        if (node != null) {
            XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTNODE);
            writer.writeCharacters(node.toString());
            writer.writeEndElement();
        }

        URI role = fault.getRole();
        if (role != null) {
            XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTROLE);
            writer.writeCharacters(role.toString());
            writer.writeEndElement();
        }

        Source details = fault.getDetails();
        if (details != null) {
            XMLStreamHelper.writeStartElement(writer, SoapMarshaler.SOAP_12_FAULTDETAIL);
            XMLStreamReader reader = marshaler.getSourceTransformer().toXMLStreamReader(details);
            XMLStreamHelper.copy(reader, writer);
            writer.writeEndElement();
View Full Code Here

TOP

Related Classes of org.apache.servicemix.soap.SoapFault

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.