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;
}
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;
}
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
}
}
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
}
}
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
}
}
Aggregations