use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class MAPAggregatorImpl method getDestination.
/**
* @param address the address
* @return a Destination for the address
*/
private Destination getDestination(Bus bus, String address, Message message) throws IOException {
Destination destination = null;
DestinationFactoryManager factoryManager = bus.getExtension(DestinationFactoryManager.class);
DestinationFactory factory = factoryManager.getDestinationFactoryForUri(address);
if (factory != null) {
Endpoint ep = message.getExchange().getEndpoint();
EndpointInfo ei = new EndpointInfo();
ei.setName(new QName(ep.getEndpointInfo().getName().getNamespaceURI(), ep.getEndpointInfo().getName().getLocalPart() + ".decoupled"));
ei.setAddress(address);
destination = factory.getDestination(ei, bus);
Conduit conduit = ContextUtils.getConduit(null, message);
if (conduit != null) {
MessageObserver ob = conduit.getMessageObserver();
ob = new InterposedMessageObserver(bus, ob);
destination.setMessageObserver(ob);
}
}
return destination;
}
use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class NettyHttpDestinationTest method setUpDestination.
private NettyHttpDestination 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(NettyHttpServerEngine.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(NettyHttpHandler.class));
EasyMock.expectLastCall();
EasyMock.replay(engine);
NettyHttpDestination dest = new EasyMockJettyHTTPDestination(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.transport.MessageObserver in project cxf by apache.
the class NettyHttpDestinationTest method testSuspendedException.
@Test
public void testSuspendedException() throws Exception {
destination = setUpDestination(false, false);
setUpDoService(false);
final RuntimeException ex = new RuntimeException();
observer = new MessageObserver() {
public void onMessage(Message m) {
throw new SuspendedInvocationException(ex);
}
};
destination.setMessageObserver(observer);
try {
destination.doService(request, response);
fail("Suspended invocation swallowed");
} catch (RuntimeException runtimeEx) {
assertSame("Original exception is not preserved", ex, runtimeEx);
}
}
use of org.apache.cxf.transport.MessageObserver 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.transport.MessageObserver in project cxf by apache.
the class UndertowHTTPDestinationTest method testSuspendedException.
@Test
public void testSuspendedException() throws Exception {
destination = setUpDestination(false, false);
setUpDoService(false);
final RuntimeException ex = new RuntimeException();
observer = new MessageObserver() {
public void onMessage(Message m) {
throw new SuspendedInvocationException(ex);
}
};
destination.setMessageObserver(observer);
try {
destination.doService(request, response);
fail("Suspended invocation swallowed");
} catch (RuntimeException runtimeEx) {
assertSame("Original exception is not preserved", ex, runtimeEx);
}
}
Aggregations