use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.
the class AbstractBaseEsbPerformanceIntegrationTest method setUp.
@Before
@Override
public void setUp() throws Exception {
server = new Server(9000);
ServerConnector connector0 = new ServerConnector(server);
connector0.setReuseAddress(true);
server.setConnectors(new Connector[] { connector0 });
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/service");
server.setHandler(context);
context.addServlet(new ServletHolder(new EchoService()), "/EchoService");
server.start();
payload = readPayload();
super.setUp();
}
use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.
the class WebsocketComponent method connect.
/**
* Connects the URL specified on the endpoint to the specified processor.
*/
public void connect(WebsocketProducerConsumer prodcon) throws Exception {
Server server = null;
WebsocketEndpoint endpoint = prodcon.getEndpoint();
String connectorKey = getConnectorKey(endpoint);
synchronized (CONNECTORS) {
ConnectorRef connectorRef = CONNECTORS.get(connectorKey);
if (connectorRef == null) {
ServerConnector connector;
// Create Server and add connector
server = createServer();
if (endpoint.isEnableJmx()) {
enableJmx(server);
}
if (endpoint.getSslContextParameters() != null) {
connector = getSslSocketConnector(server, endpoint.getSslContextParameters());
} else {
connector = new ServerConnector(server);
}
if (endpoint.getPort() != null) {
connector.setPort(endpoint.getPort());
} else {
connector.setPort(port);
}
if (endpoint.getHost() != null) {
connector.setHost(endpoint.getHost());
} else {
connector.setHost(host);
}
server.addConnector(connector);
LOG.trace("Jetty Connector added: {}", connector.getName());
// Create ServletContextHandler
ServletContextHandler context = createContext(server, connector, endpoint.getHandlers());
// setup the WebSocketComponentServlet initial parameters
setWebSocketComponentServletInitialParameter(context, endpoint);
server.setHandler(context);
// Apply CORS (http://www.w3.org/TR/cors/)
applyCrossOriginFiltering(endpoint, context);
// Create Static resources
if (endpoint.getStaticResources() != null) {
server = createStaticResourcesServer(server, context, endpoint.getStaticResources());
}
MemoryWebsocketStore memoryStore = new MemoryWebsocketStore();
// Don't provide a Servlet object as Producer/Consumer will create them later on
connectorRef = new ConnectorRef(server, connector, null, memoryStore);
// must enable session before we start
if (endpoint.isSessionSupport()) {
enableSessionSupport(connectorRef.server, connectorKey);
}
LOG.info("Jetty Server starting on host: {}:{}", connector.getHost(), connector.getPort());
connectorRef.memoryStore.start();
connectorRef.server.start();
CONNECTORS.put(connectorKey, connectorRef);
} else {
connectorRef.increment();
}
// check the session support
if (endpoint.isSessionSupport()) {
enableSessionSupport(connectorRef.server, connectorKey);
}
NodeSynchronization sync = new DefaultNodeSynchronization(connectorRef.memoryStore);
WebsocketComponentServlet servlet = addServlet(sync, prodcon, endpoint.getResourceUri());
if (prodcon instanceof WebsocketConsumer) {
WebsocketConsumer consumer = WebsocketConsumer.class.cast(prodcon);
if (servlet.getConsumer() == null) {
servlet.setConsumer(consumer);
}
// register the consumer here
servlet.connect(consumer);
}
if (prodcon instanceof WebsocketProducer) {
WebsocketProducer producer = WebsocketProducer.class.cast(prodcon);
producer.setStore(connectorRef.memoryStore);
}
}
}
use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.
the class WebsocketComponent method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
if (staticResources != null) {
// host and port must be configured
ObjectHelper.notEmpty(host, "host", this);
ObjectHelper.notNull(port, "port", this);
LOG.info("Starting static resources server {}:{} with static resource: {}", new Object[] { host, port, staticResources });
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
staticResourcesServer = createStaticResourcesServer(context, host, port, staticResources);
staticResourcesServer.start();
ServerConnector connector = (ServerConnector) staticResourcesServer.getConnectors()[0];
// must add static resource server to CONNECTORS in case the websocket producers/consumers
// uses the same port number, and therefore we must be part of this
MemoryWebsocketStore memoryStore = new MemoryWebsocketStore();
ConnectorRef ref = new ConnectorRef(staticResourcesServer, connector, null, memoryStore);
String key = "websocket:" + host + ":" + port;
CONNECTORS.put(key, ref);
}
}
use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.
the class WebsocketEndpointConfigurationTest method testSetServletThreadPool.
@Test
public void testSetServletThreadPool() throws Exception {
port = AvailablePortFinder.getNextAvailable(16332);
String uri = "websocket://localhost:" + port + "/bar?bufferSize=25000&maxIdleTime=3000";
WebsocketEndpoint websocketEndpoint = (WebsocketEndpoint) context.getEndpoint(uri);
WebsocketComponent component = websocketEndpoint.getComponent();
QueuedThreadPool qtp = new QueuedThreadPool(20, 1);
component.setThreadPool(qtp);
Consumer consumer = websocketEndpoint.createConsumer(processor);
component.connect((WebsocketProducerConsumer) consumer);
assertNotNull(consumer);
assertEquals(WebsocketConsumer.class, consumer.getClass());
// just check the servlet initial parameters
ConnectorRef conector = WebsocketComponent.getConnectors().values().iterator().next();
ServletContextHandler context = (ServletContextHandler) conector.server.getHandler();
String buffersize = context.getInitParameter("bufferSize");
assertEquals("Got a wrong buffersize", "25000", buffersize);
String maxIdleTime = context.getInitParameter("maxIdleTime");
assertEquals("Got a wrong maxIdleTime", "3000", maxIdleTime);
WebSocketServletFactory factory = (WebSocketServletFactory) context.getServletContext().getAttribute(WebSocketServletFactory.class.getName());
int factoryBufferSize = factory.getPolicy().getInputBufferSize();
assertEquals("Got a wrong buffersize", 25000, factoryBufferSize);
long factoryMaxIdleTime = factory.getPolicy().getIdleTimeout();
assertEquals("Got a wrong maxIdleTime", 3000, factoryMaxIdleTime);
}
use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.
the class WebsocketComponentTest method testCreateServerWithoutStaticContent.
@Test
public void testCreateServerWithoutStaticContent() throws Exception {
ServletContextHandler handler = component.createContext(server, server.getConnectors()[0], null);
assertEquals(1, server.getConnectors().length);
assertEquals("localhost", ((ServerConnector) server.getConnectors()[0]).getHost());
assertEquals(1988, ((ServerConnector) server.getConnectors()[0]).getPort());
assertFalse(server.getConnectors()[0].isStarted());
assertEquals(handler, server.getHandler());
assertEquals(1, server.getHandlers().length);
assertEquals(handler, server.getHandlers()[0]);
assertEquals("/", handler.getContextPath());
assertNull(handler.getSessionHandler());
assertNull(handler.getResourceBase());
assertNull(handler.getServletHandler().getHolderEntry("/"));
}
Aggregations