Search in sources :

Example 1 with PolicyException

use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.

the class DomainExpressionBuilderRegistryTest method testNoBuilder.

@Test
public void testNoBuilder() {
    DomainExpressionBuilderRegistry reg = new DomainExpressionBuilderRegistry();
    assertEquals(DomainExpressionBuilderRegistry.class, reg.getRegistrationType());
    Element e = control.createMock(Element.class);
    EasyMock.expect(e.getNamespaceURI()).andReturn("http://a.b.c");
    EasyMock.expect(e.getLocalName()).andReturn("x");
    control.replay();
    try {
        reg.build(e);
        fail("Expected PolicyException not thrown.");
    } catch (PolicyException ex) {
    // expected
    }
    control.verify();
}
Also used : PolicyException(org.apache.cxf.ws.policy.PolicyException) Element(org.w3c.dom.Element) Test(org.junit.Test)

Example 2 with PolicyException

use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.

the class Wsdl11AttachmentPolicyProviderTest method testResolveExternal.

@Test
public void testResolveExternal() {
    // service has one extension of type PolicyReference, reference is external
    Policy p = app.getElementPolicy(services[17]);
    verifyAssertionsOnly(p, 2);
    // referenced document does not contain policy with the required if
    try {
        app.getElementPolicy(endpoints[17]);
        fail("Expected PolicyException not thrown.");
    } catch (PolicyException ex) {
    // expected
    }
    // referenced document cannot be found
    try {
        app.getElementPolicy(endpoints[17].getBinding());
        fail("Expected PolicyException not thrown.");
    } catch (PolicyException ex) {
    // expected
    }
}
Also used : Policy(org.apache.neethi.Policy) PolicyException(org.apache.cxf.ws.policy.PolicyException) Test(org.junit.Test)

Example 3 with PolicyException

use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.

the class ExternalAttachmentProvider method readDocument.

void readDocument() {
    if (null != attachments) {
        return;
    }
    // read the document and build the attachments
    attachments = new ArrayList<>();
    Document doc = null;
    try {
        InputStream is = location.getInputStream();
        if (null == is) {
            throw new PolicyException(new org.apache.cxf.common.i18n.Message("COULD_NOT_OPEN_ATTACHMENT_DOC_EXC", BUNDLE, location));
        }
        doc = StaxUtils.read(is);
    } catch (Exception ex) {
        throw new PolicyException(ex);
    }
    for (Element ae : PolicyConstants.findAllPolicyElementsOfLocalName(doc, Constants.ELEM_POLICY_ATTACHMENT)) {
        PolicyAttachment attachment = new PolicyAttachment();
        for (Node nd = ae.getFirstChild(); nd != null; nd = nd.getNextSibling()) {
            if (Node.ELEMENT_NODE != nd.getNodeType()) {
                continue;
            }
            QName qn = new QName(nd.getNamespaceURI(), nd.getLocalName());
            if (Constants.isAppliesToElem(qn)) {
                Collection<DomainExpression> des = readDomainExpressions((Element) nd);
                if (des.isEmpty()) {
                    // forget about this attachment
                    continue;
                }
                attachment.setDomainExpressions(des);
            } else if (Constants.isPolicyElement(qn)) {
                Policy p = builder.getPolicy(nd);
                if (null != attachment.getPolicy()) {
                    p = p.merge(attachment.getPolicy());
                }
                attachment.setPolicy(p);
                // cache the element so it can be used when generating the wsdl
                attachment.setElement((Element) nd);
            } else if (Constants.isPolicyRef(qn)) {
                PolicyReference ref = builder.getPolicyReference(nd);
                if (null != ref) {
                    Policy p = resolveReference(ref, doc);
                    if (null != attachment.getPolicy()) {
                        p = p.merge(attachment.getPolicy());
                    }
                    attachment.setPolicy(p);
                }
            }
        // TODO: wsse:Security child element
        }
        if (null == attachment.getPolicy() || null == attachment.getDomainExpressions()) {
            continue;
        }
        attachments.add(attachment);
    }
}
Also used : Policy(org.apache.neethi.Policy) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) PolicyReference(org.apache.neethi.PolicyReference) PolicyException(org.apache.cxf.ws.policy.PolicyException) PolicyException(org.apache.cxf.ws.policy.PolicyException)

Example 4 with PolicyException

use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.

the class AbstractCommonBindingHandler method unassertPolicy.

protected void unassertPolicy(Assertion assertion, Exception reason) {
    if (assertion == null) {
        return;
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    }
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    Collection<AssertionInfo> ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason.getMessage());
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason.getMessage(), LOG), reason);
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.common.i18n.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) PolicyException(org.apache.cxf.ws.policy.PolicyException) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 5 with PolicyException

use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.

the class AbstractCommonBindingHandler method unassertPolicy.

protected void unassertPolicy(Assertion assertion, String reason) {
    if (assertion == null) {
        return;
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    }
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    Collection<AssertionInfo> ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason);
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason, LOG));
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.common.i18n.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) PolicyException(org.apache.cxf.ws.policy.PolicyException) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Aggregations

PolicyException (org.apache.cxf.ws.policy.PolicyException)21 AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)8 Test (org.junit.Test)8 AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)7 Message (org.apache.cxf.common.i18n.Message)6 Policy (org.apache.neethi.Policy)6 QName (javax.xml.namespace.QName)5 Element (org.w3c.dom.Element)4 URL (java.net.URL)3 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)3 Document (org.w3c.dom.Document)3 FileNotFoundException (java.io.FileNotFoundException)2 JAXBException (javax.xml.bind.JAXBException)2 UrlResource (org.springframework.core.io.UrlResource)2 Closeable (java.io.Closeable)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 JAXBElement (javax.xml.bind.JAXBElement)1 SOAPMessage (javax.xml.soap.SOAPMessage)1