use of org.apache.cxf.transport.MultipleEndpointObserver in project cxf by apache.
the class ServerImpl method stop.
public void stop() {
if (stopped) {
return;
}
LOG.fine("Server is stopping.");
for (Closeable c : endpoint.getCleanupHooks()) {
try {
c.close();
} catch (IOException e) {
// ignore
}
}
if (slcMgr != null) {
slcMgr.stopServer(this);
}
MessageObserver mo = getDestination().getMessageObserver();
if (mo instanceof MultipleEndpointObserver) {
((MultipleEndpointObserver) mo).getEndpoints().remove(endpoint);
if (((MultipleEndpointObserver) mo).getEndpoints().isEmpty()) {
getDestination().setMessageObserver(null);
}
} else {
getDestination().setMessageObserver(null);
}
stopped = true;
}
use of org.apache.cxf.transport.MultipleEndpointObserver in project cxf by apache.
the class SoapBindingFactory method addListener.
@Override
public synchronized void addListener(Destination d, Endpoint e) {
synchronized (d) {
MessageObserver mo = d.getMessageObserver();
if (d.getAddress() != null && d.getAddress().getAddress() != null && d.getAddress().getAddress().getValue() != null && d.getAddress().getAddress().getValue().startsWith("soap.udp")) {
// soap.udp REQUIRES usage of WS-Addressing... we need to turn this on
setupUDP(e, e.getEndpointInfo());
}
if (mo == null) {
super.addListener(d, e);
return;
}
if (mo instanceof ChainInitiationObserver) {
ChainInitiationObserver cio = (ChainInitiationObserver) mo;
Binding b = e.getBinding();
Binding b2 = cio.getEndpoint().getBinding();
if (b == b2) {
// re-registering the same endpoint?
return;
}
Object o = cio.getEndpoint().get("allow-multiplex-endpoint");
if (o instanceof String) {
o = Boolean.parseBoolean((String) o);
} else if (o == null) {
o = Boolean.FALSE;
}
if (b instanceof org.apache.cxf.binding.soap.SoapBinding && b2 instanceof org.apache.cxf.binding.soap.SoapBinding && ((org.apache.cxf.binding.soap.SoapBinding) b).getSoapVersion().equals(((org.apache.cxf.binding.soap.SoapBinding) b2).getSoapVersion()) && Boolean.FALSE.equals(o)) {
throw new RuntimeException("Soap " + ((org.apache.cxf.binding.soap.SoapBinding) b).getSoapVersion().getVersion() + " endpoint already registered on address " + e.getEndpointInfo().getAddress());
}
MultipleEndpointObserver newMO = new MultipleEndpointObserver(getBus()) {
@Override
protected Message createMessage(Message message) {
return new SoapMessage(message);
}
};
newMO.getBindingInterceptors().add(new AttachmentInInterceptor());
newMO.getBindingInterceptors().add(new StaxInInterceptor());
// This will not work if one of the endpoints disables message
// processing. But, if you've disabled message processing, you
// probably aren't going to use this feature.
newMO.getBindingInterceptors().add(new ReadHeadersInterceptor(getBus(), (SoapVersion) null));
newMO.getBindingInterceptors().add(new StartBodyInterceptor());
newMO.getBindingInterceptors().add(new CheckFaultInterceptor());
// Add in a default selection interceptor
newMO.getRoutingInterceptors().add(new EndpointSelectionInterceptor());
newMO.getEndpoints().add(cio.getEndpoint());
mo = newMO;
}
if (mo instanceof MultipleEndpointObserver) {
MultipleEndpointObserver meo = (MultipleEndpointObserver) mo;
meo.getEndpoints().add(e);
}
d.setMessageObserver(mo);
}
}
use of org.apache.cxf.transport.MultipleEndpointObserver in project cxf by apache.
the class Server method run.
protected void run() {
setBus(BusFactory.getDefaultBus());
getBus().getInInterceptors().add(new LoggingInInterceptor());
String address = "http://localhost:" + PORT + "/SoapContext/SoapPort";
Object implementor1 = new GreeterImplMixedStyle(" version1");
EndpointImpl ep1 = (EndpointImpl) Endpoint.publish(address, implementor1);
ep1.getServer().getEndpoint().put("version", "1");
ep1.getServer().getEndpoint().put("allow-multiplex-endpoint", Boolean.TRUE);
// Register a MediatorInInterceptor on this dummy service
Object implementor2 = new GreeterImplMixedStyle(" version2");
EndpointImpl ep2 = (EndpointImpl) Endpoint.publish(address, implementor2);
ep2.getServer().getEndpoint().put("version", "2");
MultipleEndpointObserver meo = (MultipleEndpointObserver) ep1.getServer().getDestination().getMessageObserver();
meo.getRoutingInterceptors().clear();
meo.getRoutingInterceptors().add(new MediatorInInterceptor());
}
use of org.apache.cxf.transport.MultipleEndpointObserver in project cxf by apache.
the class SoapBindingSelectionTest method testMultipleSoapBindings.
@Test
public void testMultipleSoapBindings() throws Exception {
ServerFactoryBean svrBean1 = new ServerFactoryBean();
svrBean1.setAddress("http://localhost/Hello");
svrBean1.setServiceClass(HelloService.class);
svrBean1.setServiceBean(new HelloServiceImpl());
svrBean1.setBus(getBus());
svrBean1.getInInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.USER_LOGICAL) {
public void handleMessage(Message message) throws Fault {
service1Invoked = true;
}
});
svrBean1.create();
ServerFactoryBean svrBean2 = new ServerFactoryBean();
svrBean2.setAddress("http://localhost/Hello");
svrBean2.setServiceClass(HelloService.class);
svrBean2.setServiceBean(new HelloServiceImpl());
svrBean2.setBus(getBus());
svrBean2.getInInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.USER_LOGICAL) {
public void handleMessage(Message message) throws Fault {
service2Invoked = true;
}
});
SoapBindingConfiguration config = new SoapBindingConfiguration();
config.setVersion(Soap12.getInstance());
svrBean2.setBindingConfig(config);
ServerImpl server2 = (ServerImpl) svrBean2.create();
Destination d = server2.getDestination();
MessageObserver mo = d.getMessageObserver();
assertTrue(mo instanceof MultipleEndpointObserver);
MultipleEndpointObserver meo = (MultipleEndpointObserver) mo;
assertEquals(2, meo.getEndpoints().size());
Node nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap11.xml");
assertEquals("http://schemas.xmlsoap.org/soap/envelope/", getNs(nd));
assertTrue(service1Invoked);
assertFalse(service2Invoked);
service1Invoked = false;
nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap12.xml");
assertEquals("http://www.w3.org/2003/05/soap-envelope", getNs(nd));
assertFalse(service1Invoked);
assertTrue(service2Invoked);
server2.stop();
server2.start();
nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap12.xml");
assertEquals("http://www.w3.org/2003/05/soap-envelope", getNs(nd));
assertFalse(service1Invoked);
assertTrue(service2Invoked);
}
Aggregations