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;
}
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));
}
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));
}
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));
}
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());
}
Aggregations