use of org.apache.cxf.transport.Destination in project cxf by apache.
the class ServerPolicyOutFaultInterceptor method handle.
protected void handle(Message msg) {
if (MessageUtils.isRequestor(msg)) {
LOG.fine("Is a requestor.");
return;
}
Exchange exchange = msg.getExchange();
assert null != exchange;
BindingOperationInfo boi = exchange.getBindingOperationInfo();
if (null == boi) {
LOG.fine("No binding operation info.");
return;
}
Endpoint e = exchange.getEndpoint();
if (null == e) {
LOG.fine("No endpoint.");
return;
}
EndpointInfo ei = e.getEndpointInfo();
Bus bus = exchange.getBus();
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
if (null == pe) {
return;
}
Destination destination = exchange.getDestination();
Exception ex = exchange.get(Exception.class);
List<Interceptor<? extends Message>> faultInterceptors = new ArrayList<Interceptor<? extends Message>>();
Collection<Assertion> assertions = new ArrayList<>();
// 1. Check overridden policy
Policy p = (Policy) msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
if (p != null) {
EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
effectivePolicy.initialise(endpi, pe, false, true, msg);
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
faultInterceptors.addAll(effectivePolicy.getInterceptors());
assertions.addAll(effectivePolicy.getChosenAlternative());
} else {
// 2. Process effective server policy
BindingFaultInfo bfi = getBindingFaultInfo(msg, ex, boi);
if (bfi == null && msg.get(FaultMode.class) != FaultMode.UNCHECKED_APPLICATION_FAULT && msg.get(FaultMode.class) != FaultMode.CHECKED_APPLICATION_FAULT) {
return;
}
EffectivePolicy effectivePolicy = pe.getEffectiveServerFaultPolicy(ei, boi, bfi, destination, msg);
if (effectivePolicy != null) {
faultInterceptors.addAll(effectivePolicy.getInterceptors());
assertions.addAll(effectivePolicy.getChosenAlternative());
}
}
// add interceptors into message chain
for (Interceptor<? extends Message> oi : faultInterceptors) {
msg.getInterceptorChain().add(oi);
LOG.log(Level.FINE, "Added interceptor of type {0}", oi.getClass().getSimpleName());
}
// insert assertions of the chosen alternative into the message
if (null != assertions && !assertions.isEmpty()) {
msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
}
}
use of org.apache.cxf.transport.Destination in project cxf by apache.
the class PolicyEngineTest method testEndpointPolicyWithEqualPolicies.
@Test
public void testEndpointPolicyWithEqualPolicies() throws Exception {
engine = new PolicyEngineImpl();
EndpointInfo ei = createMockEndpointInfo();
ServiceInfo si = control.createMock(ServiceInfo.class);
ei.setService(si);
si.getExtensor(Policy.class);
EasyMock.expectLastCall().andReturn(null).times(2);
EndpointPolicyImpl epi = control.createMock(EndpointPolicyImpl.class);
control.replay();
engine.setServerEndpointPolicy(ei, epi);
engine.setClientEndpointPolicy(ei, epi);
assertSame(epi, engine.getClientEndpointPolicy(ei, (Conduit) null, msg));
assertSame(epi, engine.getServerEndpointPolicy(ei, (Destination) null, msg));
control.reset();
ei.setService(si);
Policy p = new Policy();
si.getExtensor(Policy.class);
EasyMock.expectLastCall().andReturn(p).times(2);
epi.getPolicy();
EasyMock.expectLastCall().andReturn(p).times(2);
control.replay();
assertSame(epi, engine.getServerEndpointPolicy(ei, (Destination) null, msg));
}
use of org.apache.cxf.transport.Destination in project cxf by apache.
the class ApplicationContextTest method checkContext.
private void checkContext(TestApplicationContext ctx) throws Exception {
ConfigurerImpl cfg = new ConfigurerImpl(ctx);
EndpointInfo info = getEndpointInfo("bla", "Foo", "http://localhost:9000");
Bus bus = (Bus) ctx.getBean(Bus.DEFAULT_BUS_ID);
bus.setExtension(cfg, Configurer.class);
DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
DestinationFactory factory = dfm.getDestinationFactory("http://cxf.apache.org/transports/http");
Destination d = factory.getDestination(info, bus);
assertTrue(d instanceof UndertowHTTPDestination);
UndertowHTTPDestination jd = (UndertowHTTPDestination) d;
assertEquals("foobar", jd.getServer().getContentEncoding());
UndertowHTTPServerEngine engine = (UndertowHTTPServerEngine) jd.getEngine();
assertEquals(111, engine.getThreadingParameters().getMinThreads());
assertEquals(120, engine.getThreadingParameters().getMaxThreads());
ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class);
ConduitInitiator ci = cim.getConduitInitiator("http://cxf.apache.org/transports/http");
HTTPConduit conduit = (HTTPConduit) ci.getConduit(info, bus);
assertEquals(97, conduit.getClient().getConnectionTimeout());
info.setName(new QName("urn:test:ns", "Bar"));
conduit = (HTTPConduit) ci.getConduit(info, bus);
assertEquals(79, conduit.getClient().getConnectionTimeout());
UndertowHTTPDestination jd2 = (UndertowHTTPDestination) factory.getDestination(getEndpointInfo("foo", "bar", "http://localhost:9001"), bus);
engine = (UndertowHTTPServerEngine) jd2.getEngine();
assertEquals(40000, engine.getMaxIdleTime());
assertEquals(99, engine.getThreadingParameters().getMinThreads());
assertEquals(777, engine.getThreadingParameters().getMaxThreads());
assertNotNull("The handlers should not be null", engine.getHandlers());
assertEquals(1, engine.getHandlers().size());
UndertowHTTPDestination jd3 = (UndertowHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo", "https://localhost:9002"), bus);
engine = (UndertowHTTPServerEngine) jd3.getEngine();
assertEquals(111, engine.getThreadingParameters().getMinThreads());
assertEquals(120, engine.getThreadingParameters().getMaxThreads());
assertEquals(engine.getTlsServerParameters().getClientAuthentication().isWant(), true);
assertEquals(engine.getTlsServerParameters().getClientAuthentication().isRequired(), true);
UndertowHTTPDestination jd4 = (UndertowHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo2", "https://localhost:9003"), bus);
engine = (UndertowHTTPServerEngine) jd4.getEngine();
assertEquals(engine.getTlsServerParameters().getClientAuthentication().isWant(), false);
assertEquals(engine.getTlsServerParameters().getClientAuthentication().isRequired(), false);
UndertowHTTPDestination jd5 = (UndertowHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo", "http://localhost:9100"), bus);
engine = (UndertowHTTPServerEngine) jd5.getEngine();
String r = "expected fallback thread parameters configured for port 0";
assertNotNull(r, engine.getThreadingParameters());
assertEquals(r, 21, engine.getThreadingParameters().getMinThreads());
assertEquals(r, 389, engine.getThreadingParameters().getMaxThreads());
}
use of org.apache.cxf.transport.Destination in project cxf by apache.
the class UndertowHTTPDestinationTest method testGetMultiple.
@Test
public void testGetMultiple() throws Exception {
bus = BusFactory.getDefaultBus(true);
transportFactory = new HTTPTransportFactory();
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setName(new QName("bla", "Service"));
EndpointInfo ei = new EndpointInfo(serviceInfo, "");
ei.setName(new QName("bla", "Port"));
ei.setAddress("http://foo");
Destination d1 = transportFactory.getDestination(ei, bus);
Destination d2 = transportFactory.getDestination(ei, bus);
// Second get should not generate a new destination. It should just retrieve the existing one
assertEquals(d1, d2);
d2.shutdown();
Destination d3 = transportFactory.getDestination(ei, bus);
// Now a new destination should have been created
assertNotSame(d1, d3);
}
use of org.apache.cxf.transport.Destination in project cxf by apache.
the class CorbaBindingFactoryTest method testGetDestination.
@Test
public void testGetDestination() throws Exception {
setupServiceInfo("http://cxf.apache.org/bindings/corba/simple", "/wsdl_corbabinding/simpleIdl.wsdl", "SimpleCORBAService", "SimpleCORBAPort");
Destination destination = factory.getDestination(endpointInfo, bus);
assertNotNull(destination);
target = destination.getAddress();
assertNotNull(target);
}
Aggregations