Search in sources :

Example 1 with MultipleEndpointObserver

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;
}
Also used : MessageObserver(org.apache.cxf.transport.MessageObserver) MultipleEndpointObserver(org.apache.cxf.transport.MultipleEndpointObserver) Closeable(java.io.Closeable) IOException(java.io.IOException)

Example 2 with MultipleEndpointObserver

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);
    }
}
Also used : SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) Binding(org.apache.cxf.binding.Binding) ReadHeadersInterceptor(org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor) CheckFaultInterceptor(org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) StaxInInterceptor(org.apache.cxf.interceptor.StaxInInterceptor) EndpointSelectionInterceptor(org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor) StartBodyInterceptor(org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor) ChainInitiationObserver(org.apache.cxf.transport.ChainInitiationObserver) MultipleEndpointObserver(org.apache.cxf.transport.MultipleEndpointObserver) AttachmentInInterceptor(org.apache.cxf.interceptor.AttachmentInInterceptor)

Example 3 with MultipleEndpointObserver

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());
}
Also used : MultipleEndpointObserver(org.apache.cxf.transport.MultipleEndpointObserver) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) GreeterImplMixedStyle(org.apache.hello_world_mixedstyle.GreeterImplMixedStyle)

Example 4 with MultipleEndpointObserver

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);
}
Also used : Destination(org.apache.cxf.transport.Destination) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) ServerImpl(org.apache.cxf.endpoint.ServerImpl) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) MultipleEndpointObserver(org.apache.cxf.transport.MultipleEndpointObserver) Node(org.w3c.dom.Node) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) HelloServiceImpl(org.apache.cxf.service.factory.HelloServiceImpl) Fault(org.apache.cxf.interceptor.Fault) Test(org.junit.Test) AbstractSimpleFrontendTest(org.apache.cxf.service.factory.AbstractSimpleFrontendTest)

Aggregations

MultipleEndpointObserver (org.apache.cxf.transport.MultipleEndpointObserver)4 MessageObserver (org.apache.cxf.transport.MessageObserver)3 Message (org.apache.cxf.message.Message)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 Binding (org.apache.cxf.binding.Binding)1 SoapBindingConfiguration (org.apache.cxf.binding.soap.SoapBindingConfiguration)1 CheckFaultInterceptor (org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor)1 EndpointSelectionInterceptor (org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor)1 ReadHeadersInterceptor (org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor)1 StartBodyInterceptor (org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor)1 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)1 ServerImpl (org.apache.cxf.endpoint.ServerImpl)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1 ServerFactoryBean (org.apache.cxf.frontend.ServerFactoryBean)1 AttachmentInInterceptor (org.apache.cxf.interceptor.AttachmentInInterceptor)1 Fault (org.apache.cxf.interceptor.Fault)1 StaxInInterceptor (org.apache.cxf.interceptor.StaxInInterceptor)1 EndpointImpl (org.apache.cxf.jaxws.EndpointImpl)1 AbstractSimpleFrontendTest (org.apache.cxf.service.factory.AbstractSimpleFrontendTest)1