use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.
the class WeldDeploymentBinding method processBinding.
public void processBinding(Node node, App app) throws Exception {
ContextHandler handler = app.getContextHandler();
if (handler == null) {
throw new NullPointerException("No Handler created for App: " + app);
}
if (handler instanceof WebAppContext) {
// Do webapp specific init
WebAppContext webapp = (WebAppContext) handler;
JettyWeldInitializer.initWebApp(webapp);
} else {
// Do general init
JettyWeldInitializer.initContext(handler);
}
}
use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.
the class WebSocketCdiInitializer method onStartup.
@Override
public void onStartup(Set<Class<?>> c, ServletContext context) throws ServletException {
ContextHandler handler = ContextHandler.getContextHandler(context);
if (handler == null) {
throw new ServletException("Not running on Jetty, WebSocket+CDI support unavailable");
}
if (!(handler instanceof ServletContextHandler)) {
throw new ServletException("Not running in Jetty ServletContextHandler, WebSocket+CDI support unavailable");
}
ServletContextHandler jettyContext = (ServletContextHandler) handler;
try (ThreadClassLoaderScope scope = new ThreadClassLoaderScope(context.getClassLoader())) {
addListeners(jettyContext);
}
}
use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.
the class JettyHttpServer method checkIfContextIsFree.
private void checkIfContextIsFree(String path) {
Handler serverHandler = _server.getHandler();
if (serverHandler instanceof ContextHandler) {
ContextHandler ctx = (ContextHandler) serverHandler;
if (ctx.getContextPath().equals(path))
throw new RuntimeException("another context already bound to path " + path);
}
Handler[] handlers = _server.getHandlers();
if (handlers == null)
return;
for (Handler handler : handlers) {
if (handler instanceof ContextHandler) {
ContextHandler ctx = (ContextHandler) handler;
if (ctx.getContextPath().equals(path))
throw new RuntimeException("another context already bound to path " + path);
}
}
}
use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.
the class RequestTest method testMultiPart.
@Test
public void testMultiPart() throws Exception {
final File testTmpDir = File.createTempFile("reqtest", null);
if (testTmpDir.exists())
testTmpDir.delete();
testTmpDir.mkdir();
testTmpDir.deleteOnExit();
assertTrue(testTmpDir.list().length == 0);
ContextHandler contextHandler = new ContextHandler();
contextHandler.setContextPath("/foo");
contextHandler.setResourceBase(".");
contextHandler.setHandler(new MultiPartRequestHandler(testTmpDir));
contextHandler.addEventListener(new MultiPartCleanerListener() {
@Override
public void requestDestroyed(ServletRequestEvent sre) {
MultiPartInputStreamParser m = (MultiPartInputStreamParser) sre.getServletRequest().getAttribute(Request.__MULTIPART_INPUT_STREAM);
ContextHandler.Context c = (ContextHandler.Context) sre.getServletRequest().getAttribute(Request.__MULTIPART_CONTEXT);
assertNotNull(m);
assertNotNull(c);
assertTrue(c == sre.getServletContext());
assertTrue(!m.getParsedParts().isEmpty());
assertTrue(testTmpDir.list().length == 2);
super.requestDestroyed(sre);
String[] files = testTmpDir.list();
assertTrue(files.length == 0);
}
});
_server.stop();
_server.setHandler(contextHandler);
_server.start();
String multipart = "--AaB03x\r\n" + "content-disposition: form-data; name=\"field1\"\r\n" + "\r\n" + "Joe Blow\r\n" + "--AaB03x\r\n" + "content-disposition: form-data; name=\"stuff\"; filename=\"foo.upload\"\r\n" + "Content-Type: text/plain;charset=ISO-8859-1\r\n" + "\r\n" + "000000000000000000000000000000000000000000000000000\r\n" + "--AaB03x--\r\n";
String request = "GET /foo/x.html HTTP/1.1\r\n" + "Host: whatever\r\n" + "Content-Type: multipart/form-data; boundary=\"AaB03x\"\r\n" + "Content-Length: " + multipart.getBytes().length + "\r\n" + "Connection: close\r\n" + "\r\n" + multipart;
String responses = _connector.getResponse(request);
// System.err.println(responses);
assertTrue(responses.startsWith("HTTP/1.1 200"));
}
use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.
the class RequestTest method testInvalidHostHeader.
@Test
public void testInvalidHostHeader() throws Exception {
// Use a contextHandler with vhosts to force call to Request.getServerName()
ContextHandler context = new ContextHandler();
context.addVirtualHosts(new String[] { "something" });
_server.stop();
_server.setHandler(context);
_server.start();
// Request with illegal Host header
String request = "GET / HTTP/1.1\n" + "Host: whatever.com:xxxx\n" + "Content-Type: text/html;charset=utf8\n" + "Connection: close\n" + "\n";
String responses = _connector.getResponse(request);
assertThat(responses, Matchers.startsWith("HTTP/1.1 400"));
}
Aggregations