Search in sources :

Example 11 with PolicyException

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

the class ExternalAttachmentProviderTest method testReadDocumentNotExisting.

@Test
public void testReadDocumentNotExisting() throws MalformedURLException {
    ExternalAttachmentProvider eap = new ExternalAttachmentProvider();
    URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments1.xml");
    String uri = url.toExternalForm();
    uri = uri.replaceAll("attachments1.xml", "attachments0.xml");
    eap.setLocation(new UrlResource(uri));
    try {
        eap.readDocument();
        fail("Expected PolicyException not thrown.");
    } catch (PolicyException ex) {
        assertTrue(ex.getCause() instanceof FileNotFoundException);
    }
}
Also used : UrlResource(org.springframework.core.io.UrlResource) PolicyException(org.apache.cxf.ws.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) Test(org.junit.Test)

Example 12 with PolicyException

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

the class Wsdl11AttachmentPolicyProviderTest method testElementPolicies.

@Test
public void testElementPolicies() throws WSDLException {
    Policy p;
    // no extensions
    p = app.getElementPolicy(services[0]);
    assertTrue(p == null || p.isEmpty());
    // extensions not of type Policy or PolicyReference
    p = app.getElementPolicy(services[1]);
    assertTrue(p == null || p.isEmpty());
    // one extension of type Policy, without assertion builder
    try {
        p = app.getElementPolicy(services[2]);
        fail("Expected PolicyException not thrown.");
    } catch (PolicyException ex) {
    // expected
    }
    // one extension of type Policy
    p = app.getElementPolicy(services[3]);
    assertNotNull(p);
    assertTrue(!p.isEmpty());
    verifyAssertionsOnly(p, 2);
    // two extensions of type Policy
    p = app.getElementPolicy(services[4]);
    assertNotNull(p);
    assertTrue(!p.isEmpty());
    verifyAssertionsOnly(p, 3);
    EndpointInfo ei = new EndpointInfo();
    assertTrue(app.getElementPolicy(ei) == null);
}
Also used : Policy(org.apache.neethi.Policy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) PolicyException(org.apache.cxf.ws.policy.PolicyException) Test(org.junit.Test)

Example 13 with PolicyException

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

the class Wsdl11AttachmentPolicyProviderTest method testResolveLocal.

@Test
public void testResolveLocal() {
    Policy ep;
    // service has one extension of type PolicyReference, reference can be resolved locally
    ep = app.getElementPolicy(services[16]);
    assertNotNull(ep);
    verifyAssertionsOnly(ep, 2);
    // port has one extension of type PolicyReference, reference cannot be resolved locally
    try {
        app.getElementPolicy(endpoints[16]);
        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 14 with PolicyException

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

the class Wsdl11AttachmentPolicyProviderTest method testEffectiveServicePolicies.

@Test
public void testEffectiveServicePolicies() throws WSDLException {
    Policy p;
    Policy ep;
    // no extensions
    ep = app.getEffectivePolicy(services[0], null);
    assertTrue(ep == null || ep.isEmpty());
    p = app.getElementPolicy(services[0]);
    assertTrue(p == null || p.isEmpty());
    // extensions not of type Policy or PolicyReference
    ep = app.getEffectivePolicy(services[1], null);
    assertTrue(ep == null || ep.isEmpty());
    // one extension of type Policy, without assertion builder
    try {
        ep = app.getEffectivePolicy(services[2], null);
        fail("Expected PolicyException not thrown.");
    } catch (PolicyException ex) {
    // expected
    }
    // one extension of type Policy
    ep = app.getEffectivePolicy(services[3], null);
    assertNotNull(ep);
    assertTrue(!ep.isEmpty());
    verifyAssertionsOnly(ep, 2);
    p = app.getElementPolicy(services[3]);
    assertTrue(PolicyComparator.compare(p, ep));
    // two extensions of type Policy
    ep = app.getEffectivePolicy(services[4], null);
    assertNotNull(ep);
    assertTrue(!ep.isEmpty());
    verifyAssertionsOnly(ep, 3);
    p = app.getElementPolicy(services[4]);
    assertTrue(PolicyComparator.compare(p, ep));
}
Also used : Policy(org.apache.neethi.Policy) PolicyException(org.apache.cxf.ws.policy.PolicyException) Test(org.junit.Test)

Example 15 with PolicyException

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

the class AbstractTokenInterceptor method policyNotAsserted.

protected void policyNotAsserted(AbstractToken assertion, Exception reason, SoapMessage message) {
    if (assertion == null) {
        return;
    }
    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());
            }
        }
    }
    throw new PolicyException(reason);
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) 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