Search in sources :

Example 21 with MessageObserver

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;
}
Also used : Destination(org.apache.cxf.transport.Destination) DestinationFactory(org.apache.cxf.transport.DestinationFactory) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) MessageObserver(org.apache.cxf.transport.MessageObserver) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) Endpoint(org.apache.cxf.endpoint.Endpoint) QName(javax.xml.namespace.QName) Conduit(org.apache.cxf.transport.Conduit)

Example 22 with MessageObserver

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;
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HashSet(java.util.HashSet)

Example 23 with MessageObserver

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);
    }
}
Also used : MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) Test(org.junit.Test)

Example 24 with MessageObserver

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;
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) HttpString(io.undertow.util.HttpString) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HashSet(java.util.HashSet)

Example 25 with MessageObserver

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);
    }
}
Also used : MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) Test(org.junit.Test)

Aggregations

MessageObserver (org.apache.cxf.transport.MessageObserver)43 Message (org.apache.cxf.message.Message)34 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)21 Conduit (org.apache.cxf.transport.Conduit)14 IOException (java.io.IOException)13 Exchange (org.apache.cxf.message.Exchange)12 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)11 Test (org.junit.Test)11 MessageImpl (org.apache.cxf.message.MessageImpl)10 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)10 Bus (org.apache.cxf.Bus)8 QName (javax.xml.namespace.QName)7 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)6 Fault (org.apache.cxf.interceptor.Fault)5 Destination (org.apache.cxf.transport.Destination)5 URISyntaxException (java.net.URISyntaxException)4 URL (java.net.URL)4 HashMap (java.util.HashMap)4 List (java.util.List)4 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)4