Search in sources :

Example 11 with SOAPFaultDetail

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

the class TestGetException method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPFault fault = soapFactory.createSOAPFault();
    SOAPFaultDetail detail = soapFactory.createSOAPFaultDetail(fault);
    OMElement detailEntry = soapFactory.createOMElement(new QName(SOAPConstants.SOAP_FAULT_DETAIL_EXCEPTION_ENTRY));
    detailEntry.setText("This is an exception message");
    detail.addDetailEntry(detailEntry);
    Exception exception = fault.getException();
    assertNotNull(exception);
    assertEquals("This is an exception message", exception.getMessage());
}
Also used : QName(javax.xml.namespace.QName) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) SOAPFault(org.apache.axiom.soap.SOAPFault) OMElement(org.apache.axiom.om.OMElement)

Example 12 with SOAPFaultDetail

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

the class TestBuilder method runTest.

@Override
protected void runTest() throws Throwable {
    String soap11Message = "<?xml version='1.0' ?>" + "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" + "   <env:Header>\n" + "       <test:echoOk xmlns:test=\"http://example.org/ts-tests\"\n" + "                    env:actor=\"http://schemas.xmlsoap.org/soap/actor/next\"\n" + "                    env:mustUnderstand=\"1\"" + "       >\n" + "                       foo\n" + "       </test:echoOk>\n" + "   </env:Header>\n" + "   <env:Body>\n" + "       <env:Fault>\n" + "           <faultcode>\n" + "               env:Sender\n" + "           </faultcode>\n" + "           <faultstring>\n" + "               Sender Timeout\n" + "           </faultstring>\n" + "           <faultactor>\n" + "               http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver\n" + "           </faultactor>\n" + "           <detail xmlns:m=\"http:www.sample.org\">\n" + "               Details of error\n" + "               <m:MaxTime m:detail=\"This is only a test\">\n" + "                   P5M\n" + "               </m:MaxTime>\n" + "               <m:AveTime>\n" + "                   <m:Time>\n" + "                       P3M\n" + "                   </m:Time>\n" + "               </m:AveTime>\n" + "           </detail>\n" + "           <n:Test xmlns:n=\"http:www.Test.org\">\n" + "               <n:TestElement>\n" + "                   This is only a test\n" + "               </n:TestElement>\n" + "           </n:Test>\n" + "       </env:Fault>\n" + "   </env:Body>\n" + "</env:Envelope>";
    OMXMLParserWrapper soap11Builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(soap11Message));
    SOAPEnvelope soap11Envelope = (SOAPEnvelope) soap11Builder.getDocumentElement();
    //            soap11Envelope.build();
    //            writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
    //            soap11Envelope.internalSerializeAndConsume(writer);
    //          writer.flush();
    assertTrue("SOAP 1.1 :- envelope local name mismatch", soap11Envelope.getLocalName().equals(SOAPConstants.SOAPENVELOPE_LOCAL_NAME));
    assertTrue("SOAP 1.1 :- envelope namespace uri mismatch", soap11Envelope.getNamespace().getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    SOAPHeader header = soap11Envelope.getHeader();
    assertTrue("SOAP 1.1 :- Header local name mismatch", header.getLocalName().equals(SOAPConstants.HEADER_LOCAL_NAME));
    assertTrue("SOAP 1.1 :- Header namespace uri mismatch", header.getNamespace().getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) header.getFirstElement();
    assertTrue("SOAP 1.1 :- Header block name mismatch", headerBlock.getLocalName().equals("echoOk"));
    assertTrue("SOAP 1.1 :- Header block name space uri mismatch", headerBlock.getNamespace().getNamespaceURI().equals("http://example.org/ts-tests"));
    assertTrue("SOAP 1.1 :- Headaer block text mismatch", headerBlock.getText().trim().equals("foo"));
    // Attribute iteration is not in any guaranteed order.
    // Use QNames to get the OMAttributes.
    QName actorQName = new QName(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI, SOAP11Constants.ATTR_ACTOR);
    QName mustUnderstandQName = new QName(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI, SOAP11Constants.ATTR_MUSTUNDERSTAND);
    OMAttribute actorAttribute = headerBlock.getAttribute(actorQName);
    OMAttribute mustUnderstandAttribute = headerBlock.getAttribute(mustUnderstandQName);
    assertTrue("SOAP 1.1 :- Mustunderstand attribute not found", mustUnderstandAttribute != null);
    assertTrue("SOAP 1.1 :- Mustunderstand value mismatch", mustUnderstandAttribute.getAttributeValue().equals(SOAPConstants.ATTR_MUSTUNDERSTAND_1));
    assertTrue("SOAP 1.1 :- Mustunderstand attribute namespace uri mismatch", mustUnderstandAttribute.getNamespace().getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    assertTrue("SOAP 1.1 :- Actor attribute name not found", actorAttribute != null);
    assertTrue("SOAP 1.1 :- Actor value mismatch", actorAttribute.getAttributeValue().trim().equals("http://schemas.xmlsoap.org/soap/" + SOAP11Constants.ATTR_ACTOR + "/" + "next"));
    assertTrue("SOAP 1.1 :- Actor attribute namespace uri mismatch", actorAttribute.getNamespace().getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    SOAPBody body = soap11Envelope.getBody();
    assertTrue("SOAP 1.1 :- Body local name mismatch", body.getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME));
    assertTrue("SOAP 1.1 :- Body namespace uri mismatch", body.getNamespace().getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    SOAPFault fault = body.getFault();
    assertTrue("SOAP 1.1 :- Fault namespace uri mismatch", fault.getNamespace().getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    Iterator<OMNode> iteratorInFault = fault.getChildren();
    iteratorInFault.next();
    SOAPFaultCode code = (SOAPFaultCode) iteratorInFault.next();
    assertEquals("SOAP Fault code local name mismatch", code.getLocalName(), (SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME));
    assertEquals("SOAP 1.1 :- Fault code value mismatch", code.getText().trim(), "env:Sender");
    iteratorInFault.next();
    SOAPFaultReason reason = (SOAPFaultReason) iteratorInFault.next();
    assertTrue("SOAP 1.1 :- Fault string local name mismatch", reason.getLocalName().equals(SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME));
    assertTrue("SOAP 1.1 :- Fault string value mismatch", reason.getText().trim().equals("Sender Timeout"));
    iteratorInFault.next();
    SOAPFaultRole role = (SOAPFaultRole) iteratorInFault.next();
    assertTrue("SOAP 1.1 :- Fault actor local name mismatch", role.getLocalName().equals(SOAP11Constants.SOAP_FAULT_ACTOR_LOCAL_NAME));
    assertTrue("SOAP 1.1 :- Actor value mismatch", role.getText().trim().equals("http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver"));
    iteratorInFault.next();
    SOAPFaultDetail detail = (SOAPFaultDetail) iteratorInFault.next();
    assertTrue("SOAP 1.1 :- Fault detail local name mismatch", detail.getLocalName().equals(SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Text in detail mismatch", detail.getText().trim().equals("Details of error"));
    Iterator<OMNode> iteratorInDetail = detail.getChildren();
    iteratorInDetail.next();
    OMElement element1 = (OMElement) iteratorInDetail.next();
    assertTrue("SOAP 1.1 :- MaxTime element mismatch", element1.getLocalName().equals("MaxTime"));
    assertTrue("SOAP 1.1 :- MaxTime element namespace mismatch", element1.getNamespace().getNamespaceURI().equals("http:www.sample.org"));
    assertTrue("SOAP 1.1 :- Text value in MaxTime element mismatch", element1.getText().trim().equals("P5M"));
    Iterator<OMAttribute> attributeIterator = element1.getAllAttributes();
    OMAttribute attributeInMaxTime = attributeIterator.next();
    assertTrue("SOAP 1.1 :- Attribute local name mismatch", attributeInMaxTime.getLocalName().equals("detail"));
    assertTrue("SOAP 1.1 :- Attribute namespace mismatch", attributeInMaxTime.getNamespace().getNamespaceURI().equals("http:www.sample.org"));
    assertTrue("SOAP 1.1 :- Attribute value mismatch", attributeInMaxTime.getAttributeValue().equals("This is only a test"));
    iteratorInDetail.next();
    OMElement element2 = (OMElement) iteratorInDetail.next();
    assertTrue("SOAP 1.1 :- AveTime element mismatch", element2.getLocalName().equals("AveTime"));
    assertTrue("SOAP 1.1 :- AveTime element namespace mismatch", element2.getNamespace().getNamespaceURI().equals("http:www.sample.org"));
    Iterator<OMNode> iteratorInAveTimeElement = element2.getChildren();
    iteratorInAveTimeElement.next();
    OMElement element21 = (OMElement) iteratorInAveTimeElement.next();
    assertTrue("SOAP 1.1 :- Time element mismatch", element21.getLocalName().equals("Time"));
    assertTrue("SOAP 1.1 :- Time element namespace mismatch", element21.getNamespace().getNamespaceURI().equals("http:www.sample.org"));
    assertTrue("SOAP 1.1 :- Text value in Time element mismatch", element21.getText().trim().equals("P3M"));
    iteratorInFault.next();
    OMElement testElement = (OMElement) iteratorInFault.next();
    assertTrue("SOAP 1.1 :- Test element mismatch", testElement.getLocalName().equals("Test"));
    assertTrue("SOAP 1.1 :- Test element namespace mismatch", testElement.getNamespace().getNamespaceURI().equals("http:www.Test.org"));
    OMElement childOfTestElement = testElement.getFirstElement();
    assertTrue("SOAP 1.1 :- Test element child local name mismatch", childOfTestElement.getLocalName().equals("TestElement"));
    assertTrue("SOAP 1.1 :- Test element child namespace mismatch", childOfTestElement.getNamespace().getNamespaceURI().equals("http:www.Test.org"));
    assertTrue("SOAP 1.1 :- Test element child value mismatch", childOfTestElement.getText().trim().equals("This is only a test"));
    soap11Builder.close();
}
Also used : SOAPFaultCode(org.apache.axiom.soap.SOAPFaultCode) SOAPFaultRole(org.apache.axiom.soap.SOAPFaultRole) QName(javax.xml.namespace.QName) SOAPFaultReason(org.apache.axiom.soap.SOAPFaultReason) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMNode(org.apache.axiom.om.OMNode) SOAPBody(org.apache.axiom.soap.SOAPBody) StringReader(java.io.StringReader) SOAPFault(org.apache.axiom.soap.SOAPFault) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper) OMAttribute(org.apache.axiom.om.OMAttribute) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 13 with SOAPFaultDetail

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

the class SOAPElementTypeAdapterFactory method createAdapters.

@Override
public void createAdapters(SOAPElementType type, Adapters adapters) {
    if (type == SOAPElementType.ENVELOPE) {
        adapters.add(new SOAPElementTypeAdapter(SOAPEnvelope.class, null, null) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPEnvelope();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                throw new UnsupportedOperationException();
            }
        });
    } else if (type == SOAPElementType.HEADER) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPEnvelope) parent).getHeader();
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPHeader.class, getter, null) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPHeader();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPHeader((SOAPEnvelope) parent);
            }
        });
    } else if (type == SOAPElementType.BODY) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPEnvelope) parent).getBody();
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPBody.class, getter, null) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPBody();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPBody((SOAPEnvelope) parent);
            }
        });
    } else if (type == SOAPElementType.FAULT) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPBody) parent).getFault();
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFault.class, getter, null) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFault();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFault((SOAPBody) parent);
            }
        });
    } else if (type == SOAPFaultChild.CODE) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFault) parent).getCode();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFault) parent).setCode((SOAPFaultCode) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultCode.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultCode();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultCode((SOAPFault) parent);
            }
        });
    } else if (type == SOAPElementType.VALUE) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFaultClassifier) parent).getValue();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFaultClassifier) parent).setValue((SOAPFaultValue) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultValue.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultValue();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                if (parentType == SOAPFaultChild.CODE) {
                    return factory.createSOAPFaultValue((SOAPFaultCode) parent);
                } else {
                    return factory.createSOAPFaultValue((SOAPFaultSubCode) parent);
                }
            }
        });
    } else if (type == SOAPElementType.SUB_CODE) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFaultClassifier) parent).getSubCode();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFaultClassifier) parent).setSubCode((SOAPFaultSubCode) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultSubCode.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultSubCode();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                if (parentType == SOAPFaultChild.CODE) {
                    return factory.createSOAPFaultSubCode((SOAPFaultCode) parent);
                } else {
                    return factory.createSOAPFaultSubCode((SOAPFaultSubCode) parent);
                }
            }
        });
    } else if (type == SOAPFaultChild.REASON) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFault) parent).getReason();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFault) parent).setReason((SOAPFaultReason) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultReason.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultReason();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultReason((SOAPFault) parent);
            }
        });
    } else if (type == SOAPElementType.TEXT) {
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultText.class, null, null) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultText();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultText((SOAPFaultReason) parent);
            }
        });
    } else if (type == SOAPFaultChild.NODE) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFault) parent).getNode();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFault) parent).setNode((SOAPFaultNode) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultNode.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultNode();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultNode((SOAPFault) parent);
            }
        });
    } else if (type == SOAPFaultChild.ROLE) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFault) parent).getRole();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFault) parent).setRole((SOAPFaultRole) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultRole.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultRole();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultRole((SOAPFault) parent);
            }
        });
    } else if (type == SOAPFaultChild.DETAIL) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFault) parent).getDetail();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFault) parent).setDetail((SOAPFaultDetail) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultDetail.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultDetail();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultDetail((SOAPFault) parent);
            }
        });
    }
}
Also used : SOAPFaultCode(org.apache.axiom.soap.SOAPFaultCode) SOAPFaultRole(org.apache.axiom.soap.SOAPFaultRole) Getter(org.apache.axiom.ts.soap.SOAPElementTypeAdapter.Getter) SOAPFaultReason(org.apache.axiom.soap.SOAPFaultReason) SOAPFaultValue(org.apache.axiom.soap.SOAPFaultValue) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFaultText(org.apache.axiom.soap.SOAPFaultText) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SOAPFaultSubCode(org.apache.axiom.soap.SOAPFaultSubCode) SOAPBody(org.apache.axiom.soap.SOAPBody) Setter(org.apache.axiom.ts.soap.SOAPElementTypeAdapter.Setter) SOAPFaultClassifier(org.apache.axiom.soap.SOAPFaultClassifier) SOAPFault(org.apache.axiom.soap.SOAPFault) SOAPFaultNode(org.apache.axiom.soap.SOAPFaultNode)

Aggregations

SOAPFaultDetail (org.apache.axiom.soap.SOAPFaultDetail)13 OMElement (org.apache.axiom.om.OMElement)12 SOAPFault (org.apache.axiom.soap.SOAPFault)9 SOAPBody (org.apache.axiom.soap.SOAPBody)7 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 QName (javax.xml.namespace.QName)4 OMNamespace (org.apache.axiom.om.OMNamespace)4 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)3 SOAPFaultReason (org.apache.axiom.soap.SOAPFaultReason)3 SOAPFaultRole (org.apache.axiom.soap.SOAPFaultRole)3 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)3 StringReader (java.io.StringReader)2 OMAttribute (org.apache.axiom.om.OMAttribute)2 OMNode (org.apache.axiom.om.OMNode)2 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)2 SOAPFaultNode (org.apache.axiom.soap.SOAPFaultNode)2 SOAPFaultSubCode (org.apache.axiom.soap.SOAPFaultSubCode)2 SOAPFaultText (org.apache.axiom.soap.SOAPFaultText)2 SOAPFaultValue (org.apache.axiom.soap.SOAPFaultValue)2 SOAPHeader (org.apache.axiom.soap.SOAPHeader)2