use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.
the class WebsocketComponentTest method testCreateServerWithStaticContent.
@Test
public void testCreateServerWithStaticContent() throws Exception {
ServletContextHandler handler = component.createContext(server, server.getConnectors()[0], null);
Server server = component.createStaticResourcesServer(handler, "localhost", 1988, "classpath:public");
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());
assertNotNull(handler.getSessionHandler());
assertNotNull(handler.getResourceBase());
assertTrue(handler.getResourceBase().startsWith(JettyClassPathResource.class.getName()));
assertNotNull(handler.getServletHandler().getHolderEntry("/"));
}
use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.
the class WebsocketEndpointConfigurationTest method testSetServletInitalparameters.
@Test
public void testSetServletInitalparameters() throws Exception {
port = AvailablePortFinder.getNextAvailable(16330);
String uri = "websocket://localhost:" + port + "/bar?bufferSize=25000&maxIdleTime=3000&maxTextMessageSize=500&maxBinaryMessageSize=550";
WebsocketEndpoint websocketEndpoint = (WebsocketEndpoint) context.getEndpoint(uri);
WebsocketComponent component = websocketEndpoint.getComponent();
component.setMinThreads(1);
component.setMaxThreads(20);
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);
String maxTextMessageSize = context.getInitParameter("maxTextMessageSize");
assertEquals("Got a wrong maxTextMessageSize", "500", maxTextMessageSize);
String maxBinaryMessageSize = context.getInitParameter("maxBinaryMessageSize");
assertEquals("Got a wrong maxBinaryMessageSize", "550", maxBinaryMessageSize);
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);
int factoryMaxTextMessageSize = factory.getPolicy().getMaxTextMessageSize();
assertEquals("Got a wrong maxTextMessageSize", 500, factoryMaxTextMessageSize);
int factoryMaxBinaryMessageSize = factory.getPolicy().getMaxBinaryMessageSize();
assertEquals("Got a wrong maxBinaryMessageSize", 550, factoryMaxBinaryMessageSize);
}
use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.
the class JettyTestServer method startServer.
public void startServer() {
server = new Server(PORT);
port = PORT;
ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContext.setSecurityHandler(basicAuth("camel", "camelPass", "Private!"));
servletContext.setContextPath("/");
server.setHandler(servletContext);
servletContext.addServlet(new ServletHolder(new MyHttpServlet()), "/*");
try {
server.start();
} catch (Exception ex) {
LOG.error("Could not start Server!", ex);
fail(ex.getLocalizedMessage());
}
}
use of org.eclipse.jetty.servlet.ServletContextHandler in project hadoop by apache.
the class HttpServer2 method addDefaultApps.
/**
* Add default apps.
* @param appDir The application directory
* @throws IOException
*/
protected void addDefaultApps(ContextHandlerCollection parent, final String appDir, Configuration conf) throws IOException {
// set up the context for "/logs/" if "hadoop.log.dir" property is defined
// and it's enabled.
String logDir = System.getProperty("hadoop.log.dir");
boolean logsEnabled = conf.getBoolean(CommonConfigurationKeys.HADOOP_HTTP_LOGS_ENABLED, CommonConfigurationKeys.HADOOP_HTTP_LOGS_ENABLED_DEFAULT);
if (logDir != null && logsEnabled) {
ServletContextHandler logContext = new ServletContextHandler(parent, "/logs");
logContext.setResourceBase(logDir);
logContext.addServlet(AdminAuthorizedServlet.class, "/*");
if (conf.getBoolean(CommonConfigurationKeys.HADOOP_JETTY_LOGS_SERVE_ALIASES, CommonConfigurationKeys.DEFAULT_HADOOP_JETTY_LOGS_SERVE_ALIASES)) {
@SuppressWarnings("unchecked") Map<String, String> params = logContext.getInitParams();
params.put("org.eclipse.jetty.servlet.Default.aliases", "true");
}
logContext.setDisplayName("logs");
SessionHandler handler = new SessionHandler();
SessionManager sm = handler.getSessionManager();
if (sm instanceof AbstractSessionManager) {
AbstractSessionManager asm = (AbstractSessionManager) sm;
asm.setHttpOnly(true);
asm.getSessionCookieConfig().setSecure(true);
}
logContext.setSessionHandler(handler);
setContextAttributes(logContext, conf);
addNoCacheFilter(logContext);
defaultContexts.put(logContext, true);
}
// set up the context for "/static/*"
ServletContextHandler staticContext = new ServletContextHandler(parent, "/static");
staticContext.setResourceBase(appDir + "/static");
staticContext.addServlet(DefaultServlet.class, "/*");
staticContext.setDisplayName("static");
@SuppressWarnings("unchecked") Map<String, String> params = staticContext.getInitParams();
params.put("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
params.put("org.eclipse.jetty.servlet.Default.gzip", "true");
SessionHandler handler = new SessionHandler();
SessionManager sm = handler.getSessionManager();
if (sm instanceof AbstractSessionManager) {
AbstractSessionManager asm = (AbstractSessionManager) sm;
asm.setHttpOnly(true);
asm.getSessionCookieConfig().setSecure(true);
}
staticContext.setSessionHandler(handler);
setContextAttributes(staticContext, conf);
defaultContexts.put(staticContext, true);
}
use of org.eclipse.jetty.servlet.ServletContextHandler in project hadoop by apache.
the class TestHTestCase method testJetty.
@Test
@TestJetty
public void testJetty() throws Exception {
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addServlet(MyServlet.class, "/bar");
Server server = TestJettyHelper.getJettyServer();
server.setHandler(context);
server.start();
URL url = new URL(TestJettyHelper.getJettyURL(), "/bar");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
assertEquals(reader.readLine(), "foo");
reader.close();
}
Aggregations