use of org.apache.cxf.transports.http.configuration.HTTPServerPolicy in project cxf by apache.
the class UndertowHTTPDestinationTest method setUpDestination.
private UndertowHTTPDestination setUpDestination(boolean contextMatchOnStem, boolean mockedBus) throws Exception {
policy = new HTTPServerPolicy();
address = getEPR("bar/foo");
transportFactory = new HTTPTransportFactory();
final ConduitInitiator ci = new ConduitInitiator() {
public Conduit getConduit(EndpointInfo targetInfo, Bus b) throws IOException {
return decoupledBackChannel;
}
public Conduit getConduit(EndpointInfo localInfo, EndpointReferenceType target, Bus b) throws IOException {
return decoupledBackChannel;
}
public List<String> getTransportIds() {
return null;
}
public Set<String> getUriPrefixes() {
return new HashSet<>(Collections.singletonList("http"));
}
};
ConduitInitiatorManager mgr = new ConduitInitiatorManager() {
public void deregisterConduitInitiator(String name) {
}
public ConduitInitiator getConduitInitiator(String name) throws BusException {
return null;
}
public ConduitInitiator getConduitInitiatorForUri(String uri) {
return ci;
}
public void registerConduitInitiator(String name, ConduitInitiator factory) {
}
};
if (!mockedBus) {
bus = new ExtensionManagerBus();
bus.setExtension(mgr, ConduitInitiatorManager.class);
} else {
bus = EasyMock.createMock(Bus.class);
bus.getExtension(EndpointResolverRegistry.class);
EasyMock.expectLastCall().andReturn(null);
bus.getExtension(ContinuationProviderFactory.class);
EasyMock.expectLastCall().andReturn(null).anyTimes();
bus.getExtension(PolicyDataEngine.class);
EasyMock.expectLastCall().andReturn(null).anyTimes();
bus.hasExtensionByName("org.apache.cxf.ws.policy.PolicyEngine");
EasyMock.expectLastCall().andReturn(false);
bus.getExtension(ClassLoader.class);
EasyMock.expectLastCall().andReturn(this.getClass().getClassLoader());
EasyMock.replay(bus);
}
engine = EasyMock.createNiceMock(UndertowHTTPServerEngine.class);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setName(new QName("bla", "Service"));
endpointInfo = new EndpointInfo(serviceInfo, "");
endpointInfo.setName(new QName("bla", "Port"));
endpointInfo.setAddress(NOWHERE + "bar/foo");
endpointInfo.addExtensor(policy);
engine.addServant(EasyMock.eq(new URL(NOWHERE + "bar/foo")), EasyMock.isA(UndertowHTTPHandler.class));
EasyMock.expectLastCall();
engine.getContinuationsEnabled();
EasyMock.expectLastCall().andReturn(true);
EasyMock.replay(engine);
UndertowHTTPDestination dest = new EasyMockUndertowHTTPDestination(bus, transportFactory.getRegistry(), endpointInfo, null, engine);
dest.retrieveEngine();
policy = dest.getServer();
observer = new MessageObserver() {
public void onMessage(Message m) {
inMessage = m;
threadDefaultBus = BusFactory.getThreadDefaultBus();
}
};
dest.setMessageObserver(observer);
return dest;
}
use of org.apache.cxf.transports.http.configuration.HTTPServerPolicy 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;
}
use of org.apache.cxf.transports.http.configuration.HTTPServerPolicy in project cxf by apache.
the class PolicyLoggingInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
EndpointInfo ei = message.getExchange().getEndpoint().getEndpointInfo();
BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
LOG.fine("Getting effective server request policy for endpoint " + ei + " and binding operation " + boi);
EffectivePolicy ep = bus.getExtension(PolicyEngine.class).getEffectiveServerRequestPolicy(ei, boi, message);
for (Iterator<List<Assertion>> it = ep.getPolicy().getAlternatives(); it.hasNext(); ) {
Collection<Assertion> as = it.next();
LOG.fine("Checking alternative with " + as.size() + " assertions.");
for (Assertion a : as) {
LOG.fine("Assertion: " + a.getClass().getName());
HTTPServerPolicy p = (JaxbAssertion.cast(a, HTTPServerPolicy.class)).getData();
LOG.fine("server policy: " + ServerPolicyCalculator.toString(p));
}
}
}
use of org.apache.cxf.transports.http.configuration.HTTPServerPolicy in project cxf by apache.
the class PolicyUtilsTest method testAssertServerPolicy.
void testAssertServerPolicy(boolean outbound) {
Message message = control.createMock(Message.class);
HTTPServerPolicy ep = new HTTPServerPolicy();
HTTPServerPolicy mp = new HTTPServerPolicy();
HTTPServerPolicy cmp = new HTTPServerPolicy();
cmp.setReceiveTimeout(60000L);
HTTPServerPolicy icmp = new HTTPServerPolicy();
icmp.setSuppressClientSendErrors(true);
AssertionInfo eai = getServerPolicyAssertionInfo(ep);
AssertionInfo mai = getServerPolicyAssertionInfo(mp);
AssertionInfo cmai = getServerPolicyAssertionInfo(cmp);
AssertionInfo icmai = getServerPolicyAssertionInfo(icmp);
Collection<AssertionInfo> ais = new ArrayList<>();
ais.add(eai);
ais.add(mai);
ais.add(cmai);
ais.add(icmai);
AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
aim.put(new ServerPolicyCalculator().getDataClassName(), ais);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).atLeastOnce();
Exchange ex = control.createMock(Exchange.class);
EasyMock.expect(message.getExchange()).andReturn(ex).atLeastOnce();
EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null).atLeastOnce();
if (!outbound) {
EasyMock.expect(ex.getOutFaultMessage()).andReturn(null).atLeastOnce();
}
control.replay();
new PolicyDataEngineImpl(null).assertMessage(message, ep, new ServerPolicyCalculator());
assertTrue(eai.isAsserted());
assertTrue(mai.isAsserted());
assertTrue(outbound ? cmai.isAsserted() : !cmai.isAsserted());
assertTrue(outbound ? icmai.isAsserted() : !icmai.isAsserted());
control.verify();
}
use of org.apache.cxf.transports.http.configuration.HTTPServerPolicy in project cxf by apache.
the class UndertowHTTPDestination method doService.
protected void doService(ServletContext context, HttpServletRequest req, HttpServletResponse resp) throws IOException {
if (context == null) {
context = servletContext;
}
HTTPServerPolicy sp = getServer();
if (sp.isSetRedirectURL()) {
resp.sendRedirect(sp.getRedirectURL());
resp.flushBuffer();
return;
}
ClassLoaderHolder origLoader = null;
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
invoke(null, context, req, resp);
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
Aggregations