Mercurial Hosting > luan
diff src/org/eclipse/jetty/server/handler/DefaultHandler.java @ 807:947b11aa3157
remove jetty favicon
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 07 Sep 2016 23:26:12 -0600 |
parents | 3428c60d7cfc |
children | 8e9db0bbf4f9 |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/server/handler/DefaultHandler.java Wed Sep 07 22:50:42 2016 -0600 +++ b/src/org/eclipse/jetty/server/handler/DefaultHandler.java Wed Sep 07 23:26:12 2016 -0600 @@ -53,156 +53,100 @@ */ public class DefaultHandler extends AbstractHandler { - private static final Logger LOG = Log.getLogger(DefaultHandler.class); + private static final Logger LOG = Log.getLogger(DefaultHandler.class); - final long _faviconModified=(System.currentTimeMillis()/1000)*1000L; - byte[] _favicon; - boolean _serveIcon=true; - boolean _showContexts=true; - - public DefaultHandler() - { - try - { - URL fav = this.getClass().getClassLoader().getResource("org/eclipse/jetty/favicon.ico"); - if (fav!=null) - { - Resource r = Resource.newResource(fav); - _favicon=IO.readBytes(r.getInputStream()); - } - } - catch(Exception e) - { - LOG.warn(e); - } - } - - /* ------------------------------------------------------------ */ - /* - * @see org.eclipse.jetty.server.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int) - */ - public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException - { - if (response.isCommitted() || baseRequest.isHandled()) - return; - - baseRequest.setHandled(true); - - String method=request.getMethod(); - - // little cheat for common request - if (_serveIcon && _favicon!=null && method.equals(HttpMethods.GET) && request.getRequestURI().equals("/favicon.ico")) - { - if (request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)==_faviconModified) - response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); - else - { - response.setStatus(HttpServletResponse.SC_OK); - response.setContentType("image/x-icon"); - response.setContentLength(_favicon.length); - response.setDateHeader(HttpHeaders.LAST_MODIFIED, _faviconModified); - response.setHeader(HttpHeaders.CACHE_CONTROL,"max-age=360000,public"); - response.getOutputStream().write(_favicon); - } - return; - } - - - if (!method.equals(HttpMethods.GET) || !request.getRequestURI().equals("/")) - { - response.sendError(HttpServletResponse.SC_NOT_FOUND); - return; - } + boolean _showContexts=true; + + /* ------------------------------------------------------------ */ + /* + * @see org.eclipse.jetty.server.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int) + */ + public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + { + if (response.isCommitted() || baseRequest.isHandled()) + return; + + baseRequest.setHandled(true); + + String method=request.getMethod(); + + if (!method.equals(HttpMethods.GET) || !request.getRequestURI().equals("/")) + { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + return; + } - response.setStatus(HttpServletResponse.SC_NOT_FOUND); - response.setContentType(MimeTypes.TEXT_HTML); - - ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500); - - writer.write("<HTML>\n<HEAD>\n<TITLE>Error 404 - Not Found"); - writer.write("</TITLE>\n<BODY>\n<H2>Error 404 - Not Found.</H2>\n"); - writer.write("No context on this server matched or handled this request.<BR>"); - - if (_showContexts) - { - writer.write("Contexts known to this server are: <ul>"); - - Server server = getServer(); - Handler[] handlers = server==null?null:server.getChildHandlersByClass(ContextHandler.class); - - for (int i=0;handlers!=null && i<handlers.length;i++) - { - ContextHandler context = (ContextHandler)handlers[i]; - if (context.isRunning()) - { - writer.write("<li><a href=\""); - if (context.getVirtualHosts()!=null && context.getVirtualHosts().length>0) - writer.write("http://"+context.getVirtualHosts()[0]+":"+request.getLocalPort()); - writer.write(context.getContextPath()); - if (context.getContextPath().length()>1 && context.getContextPath().endsWith("/")) - writer.write("/"); - writer.write("\">"); - writer.write(context.getContextPath()); - if (context.getVirtualHosts()!=null && context.getVirtualHosts().length>0) - writer.write(" @ "+context.getVirtualHosts()[0]+":"+request.getLocalPort()); - writer.write(" ---> "); - writer.write(context.toString()); - writer.write("</a></li>\n"); - } - else - { - writer.write("<li>"); - writer.write(context.getContextPath()); - if (context.getVirtualHosts()!=null && context.getVirtualHosts().length>0) - writer.write(" @ "+context.getVirtualHosts()[0]+":"+request.getLocalPort()); - writer.write(" ---> "); - writer.write(context.toString()); - if (context.isFailed()) - writer.write(" [failed]"); - if (context.isStopped()) - writer.write(" [stopped]"); - writer.write("</li>\n"); - } - } - } - - for (int i=0;i<10;i++) - writer.write("\n<!-- Padding for IE -->"); - - writer.write("\n</BODY>\n</HTML>\n"); - writer.flush(); - response.setContentLength(writer.size()); - OutputStream out=response.getOutputStream(); - writer.writeTo(out); - out.close(); - } + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + response.setContentType(MimeTypes.TEXT_HTML); + + ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500); + + writer.write("<HTML>\n<HEAD>\n<TITLE>Error 404 - Not Found"); + writer.write("</TITLE>\n<BODY>\n<H2>Error 404 - Not Found.</H2>\n"); + writer.write("No context on this server matched or handled this request.<BR>"); + + if (_showContexts) + { + writer.write("Contexts known to this server are: <ul>"); + + Server server = getServer(); + Handler[] handlers = server==null?null:server.getChildHandlersByClass(ContextHandler.class); + + for (int i=0;handlers!=null && i<handlers.length;i++) + { + ContextHandler context = (ContextHandler)handlers[i]; + if (context.isRunning()) + { + writer.write("<li><a href=\""); + if (context.getVirtualHosts()!=null && context.getVirtualHosts().length>0) + writer.write("http://"+context.getVirtualHosts()[0]+":"+request.getLocalPort()); + writer.write(context.getContextPath()); + if (context.getContextPath().length()>1 && context.getContextPath().endsWith("/")) + writer.write("/"); + writer.write("\">"); + writer.write(context.getContextPath()); + if (context.getVirtualHosts()!=null && context.getVirtualHosts().length>0) + writer.write(" @ "+context.getVirtualHosts()[0]+":"+request.getLocalPort()); + writer.write(" ---> "); + writer.write(context.toString()); + writer.write("</a></li>\n"); + } + else + { + writer.write("<li>"); + writer.write(context.getContextPath()); + if (context.getVirtualHosts()!=null && context.getVirtualHosts().length>0) + writer.write(" @ "+context.getVirtualHosts()[0]+":"+request.getLocalPort()); + writer.write(" ---> "); + writer.write(context.toString()); + if (context.isFailed()) + writer.write(" [failed]"); + if (context.isStopped()) + writer.write(" [stopped]"); + writer.write("</li>\n"); + } + } + } + + for (int i=0;i<10;i++) + writer.write("\n<!-- Padding for IE -->"); + + writer.write("\n</BODY>\n</HTML>\n"); + writer.flush(); + response.setContentLength(writer.size()); + OutputStream out=response.getOutputStream(); + writer.writeTo(out); + out.close(); + } - /* ------------------------------------------------------------ */ - /** - * @return Returns true if the handle can server the jetty favicon.ico - */ - public boolean getServeIcon() - { - return _serveIcon; - } + public boolean getShowContexts() + { + return _showContexts; + } - /* ------------------------------------------------------------ */ - /** - * @param serveIcon true if the handle can server the jetty favicon.ico - */ - public void setServeIcon(boolean serveIcon) - { - _serveIcon = serveIcon; - } - - public boolean getShowContexts() - { - return _showContexts; - } - - public void setShowContexts(boolean show) - { - _showContexts = show; - } + public void setShowContexts(boolean show) + { + _showContexts = show; + } }