Search in sources :

Example 1 with ServerPolicyCalculator

use of org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator in project cxf by apache.

the class PolicyUtilsTest method testAssertPolicyNoop.

void testAssertPolicyNoop(boolean isRequestor) {
    PolicyDataEngine pde = new PolicyDataEngineImpl(null);
    Message message = control.createMock(Message.class);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
    control.replay();
    pde.assertMessage(message, null, new ClientPolicyCalculator());
    control.verify();
    control.reset();
    Collection<PolicyAssertion> as = new ArrayList<>();
    AssertionInfoMap aim = new AssertionInfoMap(as);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
    control.replay();
    if (isRequestor) {
        pde.assertMessage(message, null, new ClientPolicyCalculator());
    } else {
        pde.assertMessage(message, null, new ServerPolicyCalculator());
    }
    control.verify();
}
Also used : PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) PolicyDataEngine(org.apache.cxf.policy.PolicyDataEngine) PolicyDataEngineImpl(org.apache.cxf.ws.policy.PolicyDataEngineImpl) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 2 with ServerPolicyCalculator

use of org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator in project cxf by apache.

the class ServerPolicyCalculatorTest method testEqualServerPolicies.

@Test
public void testEqualServerPolicies() {
    ServerPolicyCalculator spc = new ServerPolicyCalculator();
    HTTPServerPolicy p1 = new HTTPServerPolicy();
    assertTrue(spc.equals(p1, p1));
    HTTPServerPolicy p2 = new HTTPServerPolicy();
    assertTrue(spc.equals(p1, p2));
    p1.setContentEncoding("encoding");
    assertTrue(!spc.equals(p1, p2));
    p2.setContentEncoding("encoding");
    assertTrue(spc.equals(p1, p2));
    p1.setSuppressClientSendErrors(true);
    assertTrue(!spc.equals(p1, p2));
}
Also used : HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator) Test(org.junit.Test)

Example 3 with ServerPolicyCalculator

use of org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator in project cxf by apache.

the class ServerPolicyCalculatorTest method testCompatibleServerPolicies.

@Test
public void testCompatibleServerPolicies() {
    ServerPolicyCalculator spc = new ServerPolicyCalculator();
    HTTPServerPolicy p1 = new HTTPServerPolicy();
    assertTrue("Policy is not compatible with itself.", spc.compatible(p1, p1));
    HTTPServerPolicy p2 = new HTTPServerPolicy();
    assertTrue("Policies are not compatible.", spc.compatible(p1, p2));
    p1.setServerType("server");
    assertTrue("Policies are not compatible.", spc.compatible(p1, p2));
    p1.setServerType(null);
    p1.setReceiveTimeout(10000);
    assertTrue("Policies are not compatible.", spc.compatible(p1, p2));
    p1.setSuppressClientSendErrors(false);
    assertTrue("Policies are compatible.", spc.compatible(p1, p2));
    p1.setSuppressClientSendErrors(true);
    assertTrue("Policies are compatible.", !spc.compatible(p1, p2));
    p2.setSuppressClientSendErrors(true);
    assertTrue("Policies are compatible.", spc.compatible(p1, p2));
}
Also used : HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator) Test(org.junit.Test)

Example 4 with ServerPolicyCalculator

use of org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator in project cxf by apache.

the class ServerPolicyCalculatorTest method testIntersectServerPolicies.

@Test
public void testIntersectServerPolicies() {
    ServerPolicyCalculator spc = new ServerPolicyCalculator();
    HTTPServerPolicy p1 = new HTTPServerPolicy();
    HTTPServerPolicy p2 = new HTTPServerPolicy();
    HTTPServerPolicy p = null;
    p1.setServerType("server");
    p = spc.intersect(p1, p2);
    assertEquals("server", p.getServerType());
    p1.setServerType(null);
    p1.setReceiveTimeout(10000L);
    p = spc.intersect(p1, p2);
    assertEquals(10000L, p.getReceiveTimeout());
    p1.setSuppressClientSendErrors(true);
    p2.setSuppressClientSendErrors(true);
    p = spc.intersect(p1, p2);
    assertTrue(p.isSuppressClientSendErrors());
}
Also used : HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator) Test(org.junit.Test)

Example 5 with ServerPolicyCalculator

use of org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator in project cxf by apache.

the class AbstractHTTPDestination method calcServerPolicyInternal.

private synchronized HTTPServerPolicy calcServerPolicyInternal(Message m) {
    HTTPServerPolicy sp = serverPolicy;
    if (!serverPolicyCalced) {
        PolicyDataEngine pde = bus.getExtension(PolicyDataEngine.class);
        if (pde != null) {
            sp = pde.getServerEndpointPolicy(m, endpointInfo, this, new ServerPolicyCalculator());
        }
        if (null == sp) {
            sp = endpointInfo.getTraversedExtensor(new HTTPServerPolicy(), HTTPServerPolicy.class);
        }
        serverPolicy = sp;
        serverPolicyCalced = true;
    }
    return sp;
}
Also used : HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) PolicyDataEngine(org.apache.cxf.policy.PolicyDataEngine) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator)

Aggregations

ServerPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator)8 HTTPServerPolicy (org.apache.cxf.transports.http.configuration.HTTPServerPolicy)5 Test (org.junit.Test)4 PolicyDataEngine (org.apache.cxf.policy.PolicyDataEngine)3 ArrayList (java.util.ArrayList)2 Message (org.apache.cxf.message.Message)2 AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)2 PolicyAssertion (org.apache.cxf.ws.policy.PolicyAssertion)2 PolicyDataEngineImpl (org.apache.cxf.ws.policy.PolicyDataEngineImpl)2 Exchange (org.apache.cxf.message.Exchange)1 ClientPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)1 AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)1 JaxbAssertion (org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion)1 Assertion (org.apache.neethi.Assertion)1