Search in sources :

Example 1 with ConduitInitiator

use of org.apache.cxf.transport.ConduitInitiator in project cxf by apache.

the class TestUtilities method invokeBytes.

public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception {
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress(address);
    ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
    ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport);
    Conduit conduit = conduitInit.getConduit(ei, getBus());
    TestMessageObserver obs = new TestMessageObserver();
    conduit.setMessageObserver(obs);
    Message m = new MessageImpl();
    conduit.prepare(m);
    OutputStream os = m.getContent(OutputStream.class);
    os.write(message);
    // TODO: shouldn't have to do this. IO caching needs cleaning
    // up or possibly removal...
    os.flush();
    os.close();
    return obs.getResponseStream().toByteArray();
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 2 with ConduitInitiator

use of org.apache.cxf.transport.ConduitInitiator in project cxf by apache.

the class TestUtilities method invokeBytes.

public byte[] invokeBytes(String address, String transport, String message) throws Exception {
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress(address);
    ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
    ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport);
    Conduit conduit = conduitInit.getConduit(ei, getBus());
    TestMessageObserver obs = new TestMessageObserver();
    conduit.setMessageObserver(obs);
    Message m = new MessageImpl();
    conduit.prepare(m);
    OutputStream os = m.getContent(OutputStream.class);
    InputStream is = getResourceAsStream(message);
    if (is == null) {
        throw new RuntimeException("Could not find resource " + message);
    }
    IOUtils.copy(is, os);
    // TODO: shouldn't have to do this. IO caching needs cleaning
    // up or possibly removal...
    os.flush();
    is.close();
    os.close();
    return obs.getResponseStream().toByteArray();
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 3 with ConduitInitiator

use of org.apache.cxf.transport.ConduitInitiator in project cxf by apache.

the class AbstractConduitSelector method getSelectedConduit.

/**
 * Mechanics to actually get the Conduit from the ConduitInitiator
 * if necessary.
 *
 * @param message the current Message
 */
protected Conduit getSelectedConduit(Message message) {
    Conduit c = findCompatibleConduit(message);
    if (c == null) {
        Exchange exchange = message.getExchange();
        EndpointInfo ei = endpoint.getEndpointInfo();
        String transportID = ei.getTransportId();
        try {
            ConduitInitiatorManager conduitInitiatorMgr = exchange.getBus().getExtension(ConduitInitiatorManager.class);
            if (conduitInitiatorMgr != null) {
                ConduitInitiator conduitInitiator = conduitInitiatorMgr.getConduitInitiator(transportID);
                if (conduitInitiator != null) {
                    c = createConduit(message, exchange, conduitInitiator);
                } else {
                    getLogger().warning("ConduitInitiator not found: " + ei.getAddress());
                }
            } else {
                getLogger().warning("ConduitInitiatorManager not found");
            }
        } catch (BusException ex) {
            throw new Fault(ex);
        } catch (IOException ex) {
            throw new Fault(ex);
        }
    }
    if (c != null && c.getTarget() != null && c.getTarget().getAddress() != null) {
        replaceEndpointAddressPropertyIfNeeded(message, c.getTarget().getAddress().getValue(), c);
    }
    // the search for the conduit could cause extra properties to be reset/loaded.
    message.resetContextCache();
    message.put(Conduit.class, c);
    return c;
}
Also used : Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) Fault(org.apache.cxf.interceptor.Fault) IOException(java.io.IOException) BusException(org.apache.cxf.BusException)

Example 4 with ConduitInitiator

use of org.apache.cxf.transport.ConduitInitiator in project cxf by apache.

the class JettyHTTPDestinationTest method setUpDestination.

private JettyHTTPDestination 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(JettyHTTPServerEngine.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(JettyHTTPHandler.class));
    EasyMock.expectLastCall();
    engine.getContinuationsEnabled();
    EasyMock.expectLastCall().andReturn(true);
    EasyMock.replay(engine);
    JettyHTTPDestination 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 5 with ConduitInitiator

use of org.apache.cxf.transport.ConduitInitiator 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)

Aggregations

ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)24 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)21 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)18 Message (org.apache.cxf.message.Message)12 Conduit (org.apache.cxf.transport.Conduit)11 Bus (org.apache.cxf.Bus)8 IOException (java.io.IOException)7 QName (javax.xml.namespace.QName)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 OutputStream (java.io.OutputStream)6 Exchange (org.apache.cxf.message.Exchange)6 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)6 MessageObserver (org.apache.cxf.transport.MessageObserver)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InputStream (java.io.InputStream)5 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Destination (org.apache.cxf.transport.Destination)4 DestinationFactory (org.apache.cxf.transport.DestinationFactory)4 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)4