Search in sources :

Example 11 with ConduitInitiator

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

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

the class SOAPConnectionImpl method getConduitInitiator.

private ConduitInitiator getConduitInitiator(String address) throws SOAPException {
    ConduitInitiator ci = null;
    try {
        // do not use getThreadDefaultBus(true) in order to avoid getting the default bus
        Bus bus = BusFactory.getThreadDefaultBus(false);
        if (bus == null) {
            bus = BusFactory.newInstance().createBus();
        }
        ConduitInitiatorManager mgr = bus.getExtension(ConduitInitiatorManager.class);
        if (address.startsWith("http")) {
            ci = mgr.getConduitInitiator("http://cxf.apache.org/transports/http");
        }
        if (ci == null) {
            ci = mgr.getConduitInitiatorForUri(address);
        }
    } catch (Exception ex) {
        throw MESSAGES.noConduitInitiatorAvailableFor2(address, ex);
    }
    if (ci == null) {
        throw MESSAGES.noConduitInitiatorAvailableFor(address);
    }
    return ci;
}
Also used : Bus(org.apache.cxf.Bus) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException)

Example 14 with ConduitInitiator

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

the class SOAPConnectionImpl method get.

@Override
public SOAPMessage get(Object addressObject) throws SOAPException {
    checkClosed();
    String address = getAddress(addressObject);
    ConduitInitiator ci = getConduitInitiator(address);
    // create a new Message and Exchange
    EndpointInfo info = new EndpointInfo();
    info.setAddress(address);
    Message outMessage = new MessageImpl();
    Exchange exch = new ExchangeImpl();
    outMessage.setExchange(exch);
    // sent GET request
    try {
        // TODO verify bus
        final Conduit c = ci.getConduit(info, BusFactory.getThreadDefaultBus(false));
        if (c instanceof HTTPConduit) {
            ((HTTPConduit) c).getClient().setAutoRedirect(true);
        }
        outMessage.put(Message.HTTP_REQUEST_METHOD, "GET");
        c.prepare(outMessage);
        c.setMessageObserver(createMessageObserver(c));
        c.close(outMessage);
    } catch (Exception ex) {
        throw MESSAGES.getRequestCouldNotBeSent(ex);
    }
    // read SOAPMessage
    return readSoapMessage(exch);
}
Also used : Exchange(org.apache.cxf.message.Exchange) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(org.apache.cxf.message.Message) SOAPMessage(javax.xml.soap.SOAPMessage) Conduit(org.apache.cxf.transport.Conduit) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException)

Example 15 with ConduitInitiator

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

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