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;
}
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);
}
}
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);
}
Aggregations