Search in sources :

Example 1 with ClientPolicyCalculator

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

the class ClientPolicyCalculatorTest method testLongTimeouts.

@Test
public void testLongTimeouts() {
    ClientPolicyCalculator calc = new ClientPolicyCalculator();
    HTTPClientPolicy p1 = new HTTPClientPolicy();
    HTTPClientPolicy p2 = new HTTPClientPolicy();
    p2.setReceiveTimeout(120000);
    p2.setConnectionTimeout(60000);
    HTTPClientPolicy p = calc.intersect(p1, p2);
    assertEquals(120000, p.getReceiveTimeout());
    assertEquals(60000, p.getConnectionTimeout());
    p1 = new HTTPClientPolicy();
    p2 = new HTTPClientPolicy();
    p1.setReceiveTimeout(120000);
    p1.setConnectionTimeout(60000);
    p = calc.intersect(p1, p2);
    assertEquals(120000, p.getReceiveTimeout());
    assertEquals(60000, p.getConnectionTimeout());
    p2.setReceiveTimeout(50000);
    p2.setConnectionTimeout(20000);
    p = calc.intersect(p1, p2);
    // p1 should have priority
    assertEquals(120000, p.getReceiveTimeout());
    assertEquals(60000, p.getConnectionTimeout());
    // reverse intersect
    p = calc.intersect(p2, p1);
    // p2 should have priority
    assertEquals(50000, p.getReceiveTimeout());
    assertEquals(20000, p.getConnectionTimeout());
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator) Test(org.junit.Test)

Example 2 with ClientPolicyCalculator

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

the class ClientPolicyCalculatorTest method testCompatibleClientPolicies.

@Test
public void testCompatibleClientPolicies() {
    ClientPolicyCalculator calc = new ClientPolicyCalculator();
    HTTPClientPolicy p1 = new HTTPClientPolicy();
    assertTrue("Policy is not compatible with itself.", calc.compatible(p1, p1));
    HTTPClientPolicy p2 = new HTTPClientPolicy();
    assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
    p1.setBrowserType("browser");
    assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
    p1.setBrowserType(null);
    p1.setConnectionTimeout(10000);
    assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
    p1.setAllowChunking(false);
    p2.setAllowChunking(true);
    assertTrue("Policies are compatible.", !calc.compatible(p1, p2));
    p2.setAllowChunking(false);
    assertTrue("Policies are compatible.", calc.compatible(p1, p2));
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator) Test(org.junit.Test)

Example 3 with ClientPolicyCalculator

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

the class HTTPClientAssertionBuilderTest method testBuildAssertion.

@Test
public void testBuildAssertion() throws Exception {
    HTTPClientAssertionBuilder ab = new HTTPClientAssertionBuilder();
    Assertion a = ab.buildAssertion();
    assertTrue(a instanceof JaxbAssertion);
    assertTrue(a instanceof HTTPClientAssertionBuilder.HTTPClientPolicyAssertion);
    assertEquals(new ClientPolicyCalculator().getDataClassName(), a.getName());
    assertTrue(!a.isOptional());
}
Also used : JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) Assertion(org.apache.neethi.Assertion) JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator) Test(org.junit.Test)

Example 4 with ClientPolicyCalculator

use of org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator 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 5 with ClientPolicyCalculator

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

the class HTTPConduit method getClient.

public HTTPClientPolicy getClient(Message message) {
    ClientPolicyCalculator cpc = new ClientPolicyCalculator();
    HTTPClientPolicy pol = message.get(HTTPClientPolicy.class);
    updateClientPolicy(message);
    if (pol != null) {
        pol = cpc.intersect(pol, clientSidePolicy);
    } else {
        pol = clientSidePolicy;
    }
    PolicyDataEngine policyDataEngine = bus.getExtension(PolicyDataEngine.class);
    if (policyDataEngine == null) {
        return pol;
    }
    return policyDataEngine.getPolicy(message, pol, cpc);
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) PolicyDataEngine(org.apache.cxf.policy.PolicyDataEngine) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)

Aggregations

ClientPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)13 PolicyDataEngine (org.apache.cxf.policy.PolicyDataEngine)8 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)7 Test (org.junit.Test)5 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 ServerPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator)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