Search in sources :

Example 6 with HTTPServerPolicy

use of org.apache.cxf.transports.http.configuration.HTTPServerPolicy in project cxf by apache.

the class ServerPolicyCalculator method intersect.

/**
 * Returns a new HTTPServerPolicy that is compatible with the two specified
 * policies or null if no compatible policy can be determined.
 *
 * @param p1 one policy
 * @param p2 another policy
 * @return the compatible policy
 */
public HTTPServerPolicy intersect(HTTPServerPolicy p1, HTTPServerPolicy p2) {
    if (!compatible(p1, p2)) {
        return null;
    }
    HTTPServerPolicy p = new HTTPServerPolicy();
    if (p1.isSetCacheControl()) {
        p.setCacheControl(p1.getCacheControl());
    } else if (p2.isSetCacheControl()) {
        p.setCacheControl(p2.getCacheControl());
    }
    p.setContentEncoding(StringUtils.combine(p1.getContentEncoding(), p2.getContentEncoding()));
    p.setContentLocation(StringUtils.combine(p1.getContentLocation(), p2.getContentLocation()));
    if (p1.isSetContentType()) {
        p.setContentType(p1.getContentType());
    } else if (p2.isSetContentType()) {
        p.setContentType(p2.getContentType());
    }
    if (p1.isSetHonorKeepAlive()) {
        p.setHonorKeepAlive(p1.isHonorKeepAlive());
    } else if (p2.isSetHonorKeepAlive()) {
        p.setHonorKeepAlive(p2.isHonorKeepAlive());
    }
    if (p1.isSetKeepAliveParameters()) {
        p.setKeepAliveParameters(p1.getKeepAliveParameters());
    } else if (p2.isSetKeepAliveParameters()) {
        p.setKeepAliveParameters(p2.getKeepAliveParameters());
    }
    if (p1.isSetReceiveTimeout() || p2.isSetReceiveTimeout()) {
        p.setReceiveTimeout(Math.min(p1.getReceiveTimeout(), p2.getReceiveTimeout()));
    }
    p.setRedirectURL(StringUtils.combine(p1.getRedirectURL(), p2.getRedirectURL()));
    p.setServerType(StringUtils.combine(p1.getServerType(), p2.getServerType()));
    if (p1.isSetSuppressClientReceiveErrors()) {
        p.setSuppressClientReceiveErrors(p1.isSuppressClientReceiveErrors());
    } else if (p2.isSetSuppressClientReceiveErrors()) {
        p.setSuppressClientReceiveErrors(p2.isSuppressClientReceiveErrors());
    }
    if (p1.isSetSuppressClientSendErrors()) {
        p.setSuppressClientSendErrors(p1.isSuppressClientSendErrors());
    } else if (p2.isSetSuppressClientSendErrors()) {
        p.setSuppressClientSendErrors(p2.isSuppressClientSendErrors());
    }
    return p;
}
Also used : HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy)

Example 7 with HTTPServerPolicy

use of org.apache.cxf.transports.http.configuration.HTTPServerPolicy in project cxf by apache.

the class HTTPServerAssertionBuilderTest method testHTTPServerPolicyAssertionEqual.

@Test
public void testHTTPServerPolicyAssertionEqual() throws Exception {
    HTTPServerAssertionBuilder ab = new HTTPServerAssertionBuilder();
    JaxbAssertion<HTTPServerPolicy> a = ab.buildAssertion();
    a.setData(new HTTPServerPolicy());
    assertTrue(a.equal(a));
    JaxbAssertion<HTTPServerPolicy> b = ab.buildAssertion();
    b.setData(new HTTPServerPolicy());
    assertTrue(a.equal(b));
    HTTPServerPolicy pa = new HTTPServerPolicy();
    a.setData(pa);
    assertTrue(a.equal(a));
    HTTPServerPolicy pb = new HTTPServerPolicy();
    b.setData(pb);
    assertTrue(a.equal(b));
    pa.setSuppressClientSendErrors(true);
    assertTrue(!a.equal(b));
}
Also used : HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) Test(org.junit.Test)

Example 8 with HTTPServerPolicy

use of org.apache.cxf.transports.http.configuration.HTTPServerPolicy 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 9 with HTTPServerPolicy

use of org.apache.cxf.transports.http.configuration.HTTPServerPolicy 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 10 with HTTPServerPolicy

use of org.apache.cxf.transports.http.configuration.HTTPServerPolicy 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)

Aggregations

HTTPServerPolicy (org.apache.cxf.transports.http.configuration.HTTPServerPolicy)17 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)7 Test (org.junit.Test)7 QName (javax.xml.namespace.QName)6 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)6 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)6 Bus (org.apache.cxf.Bus)5 ServerPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator)5 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)4 Message (org.apache.cxf.message.Message)4 URL (java.net.URL)3 HashSet (java.util.HashSet)3 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)3 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)3 MessageObserver (org.apache.cxf.transport.MessageObserver)3 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)3 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)2 HttpString (io.undertow.util.HttpString)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1