Refine search
public void addServletWithMapping( final String contextPath, final String servletClassName, final String servletMapping) { final ContextHandler contextHandler = new ContextHandler(); contextHandler.setContextPath(contextPath); final ServletHandler servletHandler = new ServletHandler(); servletHandler.addServletWithMapping(servletClassName, contextPath + servletMapping); contextHandler.setHandler(servletHandler); server.addHandler(servletHandler); }
/** * Infer the mime type for the response based on the extension of the request * URI. Returns null if unknown. */ private String inferMimeType(ServletRequest request) { String path = ((HttpServletRequest)request).getRequestURI(); ContextHandler.SContext sContext = (ContextHandler.SContext)config.getServletContext(); MimeTypes mimes = sContext.getContextHandler().getMimeTypes(); Buffer mimeBuffer = mimes.getMimeByExtension(path); return (mimeBuffer == null) ? null : mimeBuffer.toString(); }
private ContextHandler buildContextHandler(final HandlerList handlers) { final ContextHandler contextHandler = new ContextHandler("/"); contextHandler.setClassLoader(Thread.currentThread().getContextClassLoader()); contextHandler.setHandler(handlers); return contextHandler; }
/** Add a context handler. * @param contextPath The context path to add * @return * @throws IllegalAccessException * @throws InstantiationException */ public ContextHandler addContext(String contextPath,String resourceBase) { try { ContextHandler context = (ContextHandler)_contextClass.newInstance(); context.setContextPath(contextPath); context.setResourceBase(resourceBase); addHandler(context); return context; } catch (Exception e) { Log.warn(e); throw new Error(e); } }
public static void main(String[] args) throws Exception { Server server = new Server(); Connector connector=new SelectChannelConnector(); connector.setPort(8080); server.setConnectors(new Connector[]{connector}); ContextHandler context = new ContextHandler(); context.setContextPath("/"); context.setResourceBase("."); context.setClassLoader(Thread.currentThread().getContextClassLoader()); server.setHandler(context); Handler handler=new HelloHandler(); context.setHandler(handler); server.start(); server.join(); }
server.setConnectors(new Connector[]{connector}); ContextHandler context = new ContextHandler(); context.setContextPath("/"); final ServletContext servletContext = context.getServletContext(); server.setHandler(context); context.setHandler(handler);
ContextHandler contextHandler = new ContextHandler(); contextHandler.setContextPath( "" ); server.addHandler( contextHandler ); contextHandler.addHandler( servlets ); contextHandler.setAttribute( "queryEngine", queryEngine ); contextHandler.setAttribute( "collection", collection ); contextHandler.setAttribute( "titleList", titleList ); contextHandler.setAttribute( "action", "/Query" ); contextHandler.setAttribute( "template", System.getProperty( "it.unimi.dsi.mg4j.query.QueryServlet.template" ) ); if ( itemClass == FileSystemItem.class ) contextHandler.setAttribute( "derelativise", Boolean.TRUE ); else contextHandler.setAttribute( "uri", Boolean.TRUE ); contextHandler.setAttribute( "mimeType", itemMimeType );
private static void init(int port, EventListener servletInitializer, String resourceBase) { Server server = new Server(port); ContextHandler context = new ContextHandler("/"); context.setClassLoader(Thread.currentThread().getContextClassLoader()); context.addEventListener(servletInitializer); sessionHandler.setHandler(servletHandler); context.setHandler(servletAndResourceHandler);
_mimeTypes = _context.getContextHandler().getMimeTypes(); _welcomes = _context.getContextHandler().getWelcomeFiles(); if (_welcomes==null) _welcomes=new String[] {"index.jsp","index.html"}; _resourceBase=Resource.newResource(_context.getResource(URIUtil.SLASH)).addPath(rrb); Log.warn(Log.EXCEPTION,e); throw new UnavailableException(e.toString()); catch (Exception e) Log.warn(Log.EXCEPTION,e); throw new UnavailableException(e.toString()); Log.warn(Log.EXCEPTION,e); throw new UnavailableException(e.toString());
/** * */ public ContextHandler(String contextPath) { this(); setContextPath(contextPath); }
@Override public ServletContext getServletContext(final String contextPath) { final Iterable<Handler> handlers = (server.getHandlers() == null ? Collections .singletonList(server.getHandler()) : Arrays.asList(server.getHandlers())); for (final Handler handler : handlers) { if (handler instanceof ContextHandler) { final ContextHandler contextHandler = (ContextHandler) handler; if (ObjectUtils.equals(contextPath, contextHandler.getContextPath())) { return contextHandler.getServletContext(); } } } return null; }
ContextHandler context = new ContextHandler(); context.setContextPath(URIUtil.SLASH); context.setResourceBase(args.length==1?".":args[1]); ServletHandler servlet = new ServletHandler(); servlet.addServletWithMapping("org.mortbay.jetty.servlet.DefaultServlet", URIUtil.SLASH); context.setHandler(servlet); contexts.addHandler(context); Log.warn(Log.EXCEPTION,e);
server.setConnectors(new Connector[]{connector}); final ContextHandler context = new ContextHandler(); context.setContextPath("/"); final ServletContext servletContext = context.getServletContext(); server.setHandler(context); sessionHandler.setHandler(handler); context.setHandler(sessionHandler);
ContextHandler contextHandler = new ContextHandler(); contextHandler.setContextPath( "" ); server.addHandler( contextHandler ); contextHandler.addHandler( servlets ); contextHandler.setAttribute( "queryEngine", queryEngine ); contextHandler.setAttribute( "collection", collection ); contextHandler.setAttribute( "titleList", titleList ); contextHandler.setAttribute( "action", "/Query" ); contextHandler.setAttribute( "template", System.getProperty( "it.unimi.dsi.big.mg4j.query.QueryServlet.template" ) ); if ( itemClass == FileSystemItem.class ) contextHandler.setAttribute( "derelativise", Boolean.TRUE ); else contextHandler.setAttribute( "uri", Boolean.TRUE ); contextHandler.setAttribute( "mimeType", itemMimeType );
private ContextHandler init(final int port, final EventListener servletInitializer, final String resourceBase) { final Server server = new Server(port); final ContextHandler context = new ContextHandler("/"); context.setClassLoader(Thread.currentThread().getContextClassLoader()); context.addEventListener(servletInitializer); servletHandler.addServletMapping(imageServletMapping); context.setHandler(handlerList);
/** * */ public ContextHandler(HandlerContainer parent, String contextPath) { this(); setContextPath(contextPath); parent.addHandler(this); }
ContextHandler contextHandler = new ContextHandler(); contextHandler.setContextPath(root); contextHandler.setHandler(new ResourceHandler()); contextHandler.setResourceBase(resourceBase/*site.getDestination().getPath()*/);
public static void main(String[] args) throws Exception { Server server = new Server(); Connector connector=new SelectChannelConnector(); connector.setPort(8080); server.setConnectors(new Connector[]{connector}); ContextHandler context0 = new ContextHandler(); context0.setContextPath("/zero"); Handler handler0=new HelloHandler(); context0.setHandler(handler0); ContextHandler context1 = new ContextHandler(); context1.setContextPath("/one"); Handler handler1=new HelloHandler(); context1.setHandler(handler1); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[]{context0,context1}); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[]{contexts,new DefaultHandler()}); server.setHandler(handlers); server.start(); server.join(); }
server.setConnectors(new Connector[]{connector}); final ContextHandler context = new ContextHandler(); context.setContextPath("/"); final ServletContext servletContext = context.getServletContext(); server.setHandler(context); sessionHandler.setHandler(handler); context.setHandler(sessionHandler);
ContextHandler contextHandler = new ContextHandler(); contextHandler.setContextPath( "" ); server.addHandler( contextHandler ); contextHandler.addHandler( servlets ); contextHandler.setAttribute( "queryEngine", queryEngine ); contextHandler.setAttribute( "collection", collection ); contextHandler.setAttribute( "titleList", titleList ); contextHandler.setAttribute( "action", "/Query" ); contextHandler.setAttribute( "template", System.getProperty( "it.unimi.di.big.mg4j.query.QueryServlet.template" ) ); if ( itemClass == FileSystemItem.class ) contextHandler.setAttribute( "derelativise", Boolean.TRUE ); else contextHandler.setAttribute( "uri", Boolean.TRUE ); contextHandler.setAttribute( "mimeType", itemMimeType );