Search in sources :

Example 6 with SOAPProcessingException

use of org.apache.axiom.soap.SOAPProcessingException in project webservices-axiom by apache.

the class SOAP11BuilderHelper method handleEvent.

@Override
public Class<? extends AxiomElement> handleEvent(OMElement parent, int elementLevel, String namespaceURI, String localName) throws SOAPProcessingException {
    Class<? extends AxiomElement> elementType = null;
    if (elementLevel == 4) {
        if (SOAP_FAULT_CODE_LOCAL_NAME.equals(localName)) {
            elementType = AxiomSOAP11FaultCode.class;
            faultcodePresent = true;
        } else if (SOAP_FAULT_STRING_LOCAL_NAME.equals(localName)) {
            elementType = AxiomSOAP11FaultReason.class;
            faultstringPresent = true;
        } else if (SOAP_FAULT_ACTOR_LOCAL_NAME.equals(localName)) {
            elementType = AxiomSOAP11FaultRole.class;
        } else if (SOAP_FAULT_DETAIL_LOCAL_NAME.equals(localName)) {
            elementType = AxiomSOAP11FaultDetail.class;
        } else {
            elementType = AxiomElement.class;
        }
    } else if (elementLevel == 5) {
        String parentTagName = "";
        if (parent instanceof Element) {
            parentTagName = ((Element) parent).getTagName();
        } else {
            parentTagName = parent.getLocalName();
        }
        if (parentTagName.equals(SOAP_FAULT_CODE_LOCAL_NAME)) {
            throw new SOAPProcessingException("faultcode element should not have children");
        } else if (parentTagName.equals(SOAP_FAULT_STRING_LOCAL_NAME)) {
            throw new SOAPProcessingException("faultstring element should not have children");
        } else if (parentTagName.equals(SOAP_FAULT_ACTOR_LOCAL_NAME)) {
            throw new SOAPProcessingException("faultactor element should not have children");
        } else {
            elementType = AxiomElement.class;
        }
    } else if (elementLevel > 5) {
        elementType = AxiomElement.class;
    }
    return elementType;
}
Also used : AxiomSOAP11FaultDetail(org.apache.axiom.soap.impl.intf.AxiomSOAP11FaultDetail) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) AxiomSOAP11FaultReason(org.apache.axiom.soap.impl.intf.AxiomSOAP11FaultReason)

Example 7 with SOAPProcessingException

use of org.apache.axiom.soap.SOAPProcessingException in project webservices-axiom by apache.

the class SOAPModel method determineElementType.

@Override
public Class<? extends CoreNSAwareElement> determineElementType(CoreParentNode parent, int elementLevel, String namespaceURI, String localName) {
    Class<? extends AxiomElement> elementType;
    if (elementLevel == 1) {
        if (!localName.equals(SOAPConstants.SOAPENVELOPE_LOCAL_NAME)) {
            throw new SOAPProcessingException("First Element must contain the local name, " + SOAPConstants.SOAPENVELOPE_LOCAL_NAME + " , but found " + localName, SOAPConstants.FAULT_CODE_SENDER);
        }
        // determine SOAP version and from that determine a proper factory here.
        if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceURI)) {
            soapHelper = SOAPHelper.SOAP12;
            log.debug("Starting to process SOAP 1.2 message");
        } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceURI)) {
            soapHelper = SOAPHelper.SOAP11;
            log.debug("Starting to process SOAP 1.1 message");
        } else {
            throw new SOAPProcessingException("Only SOAP 1.1 or SOAP 1.2 messages are supported in the" + " system", SOAPConstants.FAULT_CODE_VERSION_MISMATCH);
        }
        elementType = soapHelper.getEnvelopeClass();
    } else if (elementLevel == 2) {
        if (soapHelper.getEnvelopeURI().equals(namespaceURI)) {
            // this is either a header or a body
            if (localName.equals(SOAPConstants.HEADER_LOCAL_NAME)) {
                if (headerPresent) {
                    throw new SOAPProcessingException("Multiple headers encountered!", getSenderFaultCode());
                }
                if (bodyPresent) {
                    throw new SOAPProcessingException("Header Body wrong order!", getSenderFaultCode());
                }
                headerPresent = true;
                elementType = soapHelper.getHeaderClass();
            } else if (localName.equals(SOAPConstants.BODY_LOCAL_NAME)) {
                if (bodyPresent) {
                    throw new SOAPProcessingException("Multiple body elements encountered", getSenderFaultCode());
                }
                bodyPresent = true;
                elementType = soapHelper.getBodyClass();
            } else {
                throw new SOAPProcessingException(localName + " is not supported here.", getSenderFaultCode());
            }
        } else if (soapHelper == SOAPHelper.SOAP11 && bodyPresent) {
            elementType = AxiomElement.class;
        } else {
            throw new SOAPProcessingException("Disallowed element found inside Envelope : {" + namespaceURI + "}" + localName);
        }
    } else if ((elementLevel == 3) && ((OMElement) parent).getLocalName().equals(SOAPConstants.HEADER_LOCAL_NAME)) {
        // this is a headerblock
        try {
            elementType = soapHelper.getHeaderBlockClass();
        } catch (SOAPProcessingException e) {
            throw new SOAPProcessingException("Can not create SOAPHeader block", getReceiverFaultCode(), e);
        }
    } else if ((elementLevel == 3) && ((OMElement) parent).getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME) && localName.equals(SOAPConstants.BODY_FAULT_LOCAL_NAME) && soapHelper.getEnvelopeURI().equals(namespaceURI)) {
        // this is a SOAP fault
        elementType = soapHelper.getFaultClass();
        processingFault = true;
        if (soapHelper == SOAPHelper.SOAP12) {
            builderHelper = new SOAP12BuilderHelper();
        } else if (soapHelper == SOAPHelper.SOAP11) {
            builderHelper = new SOAP11BuilderHelper();
        }
    } else if (elementLevel > 3 && processingFault) {
        elementType = builderHelper.handleEvent((OMElement) parent, elementLevel, namespaceURI, localName);
    } else {
        // this is neither of above. Just create an element
        elementType = AxiomElement.class;
    }
    return elementType;
}
Also used : SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) OMElement(org.apache.axiom.om.OMElement)

Example 8 with SOAPProcessingException

use of org.apache.axiom.soap.SOAPProcessingException in project webservices-axiom by apache.

the class TestWrongParent3 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPFaultDetail parent = soapFactory.createSOAPFaultDetail();
    OMElement child1 = soapFactory.createOMElement("child1", null, parent);
    SOAPHeaderBlock hb = soapFactory.createSOAPHeaderBlock("MyHeader", soapFactory.createOMNamespace("urn:test", "p"));
    try {
        child1.insertSiblingBefore(hb);
        fail("Expected SOAPProcessingException");
    } catch (SOAPProcessingException ex) {
    // Expected
    }
}
Also used : SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) OMElement(org.apache.axiom.om.OMElement) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock)

Example 9 with SOAPProcessingException

use of org.apache.axiom.soap.SOAPProcessingException in project webservices-axiom by apache.

the class TestDTD method runTest.

@Override
protected void runTest() throws Throwable {
    String message = "<!DOCTYPE test []>" + soapFactory.getDefaultEnvelope();
    XMLStreamReader parser = StAXUtils.createXMLStreamReader(new StringReader(message));
    ;
    try {
        SOAPModelBuilder builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(metaFactory, parser);
        // The processing must fail before we can get the SOAPEnvelope
        builder.getSOAPEnvelope();
        fail("Expected SOAPProcessingException");
    } catch (SOAPProcessingException ex) {
    // Expected
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) StringReader(java.io.StringReader) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder)

Example 10 with SOAPProcessingException

use of org.apache.axiom.soap.SOAPProcessingException in project webservices-axiom by apache.

the class TestWrongParent2 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope parent = soapFactory.createSOAPEnvelope();
    OMElement child1 = soapFactory.createSOAPHeader(parent);
    SOAPFault fault = soapFactory.createSOAPFault();
    try {
        child1.insertSiblingAfter(fault);
        fail("Expected SOAPProcessingException");
    } catch (SOAPProcessingException ex) {
    // Expected
    }
}
Also used : SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) OMElement(org.apache.axiom.om.OMElement) SOAPFault(org.apache.axiom.soap.SOAPFault) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Aggregations

SOAPProcessingException (org.apache.axiom.soap.SOAPProcessingException)16 OMElement (org.apache.axiom.om.OMElement)8 SOAPFault (org.apache.axiom.soap.SOAPFault)4 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)4 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 QName (javax.xml.namespace.QName)2 AxiomElement (org.apache.axiom.om.impl.intf.AxiomElement)2 SOAPHeader (org.apache.axiom.soap.SOAPHeader)2 SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)2 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1 Vector (java.util.Vector)1 DataHandler (javax.activation.DataHandler)1 DataSource (javax.activation.DataSource)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 MimeMessage (javax.mail.internet.MimeMessage)1 MimeMultipart (javax.mail.internet.MimeMultipart)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 MemoryBlob (org.apache.axiom.blob.MemoryBlob)1 ContentType (org.apache.axiom.mime.ContentType)1