Search in sources :

Example 6 with DestinationFactory

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

the class AbstractWSDLBasedEndpointFactory method modifyTransportIdPerAddress.

private void modifyTransportIdPerAddress(EndpointInfo ei) {
    // this is useful for local & camel transport
    if (transportId == null && getAddress() != null) {
        DestinationFactory df = getDestinationFactory();
        if (df == null) {
            DestinationFactoryManager dfm = getBus().getExtension(DestinationFactoryManager.class);
            df = dfm.getDestinationFactoryForUri(getAddress());
        }
        if (df != null) {
            transportId = df.getTransportIds().get(0);
        } else {
            // check conduits (the address could be supported on
            // client only)
            ConduitInitiatorManager cim = getBus().getExtension(ConduitInitiatorManager.class);
            ConduitInitiator ci = cim.getConduitInitiatorForUri(getAddress());
            if (ci != null) {
                transportId = ci.getTransportIds().get(0);
            }
        }
    }
    if (transportId != null) {
        ei.setTransportId(transportId);
    }
}
Also used : DestinationFactory(org.apache.cxf.transport.DestinationFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator)

Example 7 with DestinationFactory

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

the class ServerFactoryBean method detectTransportIdFromAddress.

@Override
protected String detectTransportIdFromAddress(String ad) {
    DestinationFactory df = getDestinationFactory();
    if (df == null) {
        DestinationFactoryManager dfm = getBus().getExtension(DestinationFactoryManager.class);
        df = dfm.getDestinationFactoryForUri(getAddress());
        if (df != null) {
            return df.getTransportIds().get(0);
        }
    }
    return null;
}
Also used : DestinationFactory(org.apache.cxf.transport.DestinationFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager)

Example 8 with DestinationFactory

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

the class MtomServerTest method servStatic.

/**
 * Serve static file
 */
private void servStatic(final URL resource, final String add) throws Exception {
    Bus bus = getStaticBus();
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    DestinationFactory df = dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress(add);
    Destination d = df.getDestination(ei, bus);
    d.setMessageObserver(new MessageObserver() {

        public void onMessage(Message message) {
            try {
                // HTTP seems to need this right now...
                ExchangeImpl ex = new ExchangeImpl();
                ex.setInMessage(message);
                Conduit backChannel = message.getDestination().getBackChannel(message);
                MessageImpl res = new MessageImpl();
                ex.setOutMessage(res);
                res.put(Message.CONTENT_TYPE, "text/xml");
                backChannel.prepare(res);
                OutputStream out = res.getContent(OutputStream.class);
                InputStream is = resource.openStream();
                IOUtils.copy(is, out, 2048);
                out.flush();
                out.close();
                is.close();
                backChannel.close(res);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) Destination(org.apache.cxf.transport.Destination) MessageObserver(org.apache.cxf.transport.MessageObserver) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) Message(org.apache.cxf.message.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 9 with DestinationFactory

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

the class MtomServerTest method unregisterServStatic.

private void unregisterServStatic(String add) throws Exception {
    Bus bus = getStaticBus();
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    DestinationFactory df = dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress(add);
    Destination d = df.getDestination(ei, bus);
    d.setMessageObserver(null);
}
Also used : Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Destination(org.apache.cxf.transport.Destination) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager)

Example 10 with DestinationFactory

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

the class CXFNonSpringServlet method getDestinationRegistryFromBusOrDefault.

protected DestinationRegistry getDestinationRegistryFromBusOrDefault(final String transportId) {
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    try {
        String peferredTransportId = transportId;
        // extension or customization).
        if (StringUtils.isEmpty(peferredTransportId) && getBus() != null) {
            peferredTransportId = (String) getBus().getProperty(AbstractTransportFactory.PREFERRED_TRANSPORT_ID);
        }
        if (StringUtils.isEmpty(peferredTransportId)) {
            final Set<String> candidates = dfm.getRegisteredDestinationFactoryNames();
            // consider other candidates
            if (!candidates.contains(DEFAULT_TRANSPORT_ID)) {
                peferredTransportId = candidates.stream().filter(name -> name.endsWith("/configuration")).findAny().orElse(DEFAULT_TRANSPORT_ID);
            }
        }
        DestinationFactory df = StringUtils.isEmpty(peferredTransportId) ? dfm.getDestinationFactory(DEFAULT_TRANSPORT_ID) : dfm.getDestinationFactory(peferredTransportId);
        if (df instanceof HTTPTransportFactory) {
            HTTPTransportFactory transportFactory = (HTTPTransportFactory) df;
            return transportFactory.getRegistry();
        }
    } catch (BusException e) {
    // why are we throwing a busexception if the DF isn't found?
    }
    return null;
}
Also used : Bus(org.apache.cxf.Bus) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) FilterChain(javax.servlet.FilterChain) ServletException(javax.servlet.ServletException) StringUtils(org.apache.cxf.common.util.StringUtils) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) ResourceManager(org.apache.cxf.resource.ResourceManager) HttpServletRequest(javax.servlet.http.HttpServletRequest) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) Method(java.lang.reflect.Method) ServletRequest(javax.servlet.ServletRequest) ServiceListGeneratorServlet(org.apache.cxf.transport.servlet.servicelist.ServiceListGeneratorServlet) ServletConfig(javax.servlet.ServletConfig) HttpServlet(javax.servlet.http.HttpServlet) CastUtils(org.apache.cxf.helpers.CastUtils) DestinationFactory(org.apache.cxf.transport.DestinationFactory) Collection(java.util.Collection) BusException(org.apache.cxf.BusException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) IOException(java.io.IOException) AbstractTransportFactory(org.apache.cxf.transport.AbstractTransportFactory) ClassLoaderUtils(org.apache.cxf.common.classloader.ClassLoaderUtils) ServletResponse(javax.servlet.ServletResponse) BusFactory(org.apache.cxf.BusFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) ServletContext(javax.servlet.ServletContext) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) DestinationFactory(org.apache.cxf.transport.DestinationFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) BusException(org.apache.cxf.BusException)

Aggregations

DestinationFactory (org.apache.cxf.transport.DestinationFactory)19 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)18 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)10 Bus (org.apache.cxf.Bus)9 Destination (org.apache.cxf.transport.Destination)7 QName (javax.xml.namespace.QName)6 BusException (org.apache.cxf.BusException)4 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)4 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)4 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)4 Test (org.junit.Test)4 ConfigurerImpl (org.apache.cxf.configuration.spring.ConfigurerImpl)3 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)3 IOException (java.io.IOException)2 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)2 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)2 Message (org.apache.cxf.message.Message)2 MessageImpl (org.apache.cxf.message.MessageImpl)2 BindingInfo (org.apache.cxf.service.model.BindingInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1