Search in sources :

Example 1 with CometDServlet

use of org.cometd.server.CometDServlet in project camel by apache.

the class CometdComponent method createServletForConnector.

protected CometDServlet createServletForConnector(Server server, Connector connector, CometdEndpoint endpoint) throws Exception {
    CometDServlet servlet = new CometDServlet();
    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
    ServletHolder holder = new ServletHolder();
    holder.setServlet(servlet);
    holder.setAsyncSupported(true);
    // pointing to by example classpath:webapp
    if (endpoint.getBaseResource() != null) {
        String[] resources = endpoint.getBaseResource().split(":");
        if (LOG.isDebugEnabled()) {
            LOG.debug(">>> Protocol found: " + resources[0] + ", and resource: " + resources[1]);
        }
        if (resources[0].equals("file")) {
            context.setBaseResource(Resource.newResource(resources[1]));
        } else if (resources[0].equals("classpath")) {
            // Create a URL handler using classpath protocol
            URL url = this.getCamelContext().getClassResolver().loadResourceAsURL(resources[1]);
            context.setBaseResource(Resource.newResource(url));
        }
    }
    applyCrossOriginFiltering(endpoint, context);
    context.addServlet(holder, "/cometd/*");
    context.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/");
    context.setSessionHandler(new SessionHandler());
    holder.setInitParameter("timeout", Integer.toString(endpoint.getTimeout()));
    holder.setInitParameter("interval", Integer.toString(endpoint.getInterval()));
    holder.setInitParameter("maxInterval", Integer.toString(endpoint.getMaxInterval()));
    holder.setInitParameter("multiFrameInterval", Integer.toString(endpoint.getMultiFrameInterval()));
    holder.setInitParameter("JSONCommented", Boolean.toString(endpoint.isJsonCommented()));
    holder.setInitParameter("logLevel", Integer.toString(endpoint.getLogLevel()));
    return servlet;
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) CometDServlet(org.cometd.server.CometDServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) URL(java.net.URL)

Example 2 with CometDServlet

use of org.cometd.server.CometDServlet in project camel by apache.

the class CometdComponent method connect.

/**
     * Connects the URL specified on the endpoint to the specified processor.
     */
public void connect(CometdProducerConsumer prodcon) throws Exception {
    Server server = null;
    // Make sure that there is a connector for the requested endpoint.
    CometdEndpoint endpoint = prodcon.getEndpoint();
    String connectorKey = endpoint.getProtocol() + ":" + endpoint.getUri().getHost() + ":" + endpoint.getPort();
    synchronized (connectors) {
        ConnectorRef connectorRef = connectors.get(connectorKey);
        if (connectorRef == null) {
            ServerConnector connector;
            server = createServer();
            if ("cometds".equals(endpoint.getProtocol())) {
                connector = getSslSocketConnector(server);
            } else {
                connector = new ServerConnector(server);
            }
            connector.setPort(endpoint.getPort());
            connector.setHost(endpoint.getUri().getHost());
            if ("localhost".equalsIgnoreCase(endpoint.getUri().getHost())) {
                LOG.warn("You use localhost interface! It means that no external connections will be available." + " Don't you want to use 0.0.0.0 instead (all network interfaces)?");
            }
            server.addConnector(connector);
            CometDServlet servlet = createServletForConnector(server, connector, endpoint);
            connectorRef = new ConnectorRef(connector, servlet, server);
            server.start();
            connectors.put(connectorKey, connectorRef);
        } else {
            connectorRef.increment();
        }
        BayeuxServerImpl bayeux = connectorRef.servlet.getBayeux();
        if (securityPolicy != null) {
            bayeux.setSecurityPolicy(securityPolicy);
        }
        if (extensions != null) {
            for (BayeuxServer.Extension extension : extensions) {
                bayeux.addExtension(extension);
            }
        }
        if (serverListeners != null) {
            for (BayeuxServer.BayeuxServerListener serverListener : serverListeners) {
                bayeux.addListener(serverListener);
            }
        }
        prodcon.setBayeux(bayeux);
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) BayeuxServerImpl(org.cometd.server.BayeuxServerImpl) Server(org.eclipse.jetty.server.Server) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) CometDServlet(org.cometd.server.CometDServlet)

Example 3 with CometDServlet

use of org.cometd.server.CometDServlet in project felix by apache.

the class CometdServiceImpl method register.

private void register(HttpService httpService) {
    if (this.continuationCometdServlet == null) {
        this.continuationCometdServlet = new CometDServlet();
    }
    try {
        Dictionary dictionary = new Hashtable();
        dictionary.put("requestAvailable", "true");
        httpService.registerServlet(this.config.getPath(), this.continuationCometdServlet, dictionary, null);
    } catch (Exception e) {
        SystemLogger.error("Failed to register ContinuationCometdServlet to " + this.config.getPath(), e);
    }
    this.cometdServiceReg = this.context.registerService(CometdService.class.getName(), this, null);
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) CometDServlet(org.cometd.server.CometDServlet)

Aggregations

CometDServlet (org.cometd.server.CometDServlet)3 URL (java.net.URL)1 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 BayeuxServer (org.cometd.bayeux.server.BayeuxServer)1 BayeuxServerImpl (org.cometd.server.BayeuxServerImpl)1 Server (org.eclipse.jetty.server.Server)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1