From 70705a5ac142e5ee5fb6765276fa0efb1bde5b80 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 16 Sep 2016 12:25:24 +1000 Subject: [PATCH 1/4] Issue #788 Already enabled info --- .../main/java/org/eclipse/jetty/start/BaseBuilder.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/BaseBuilder.java b/jetty-start/src/main/java/org/eclipse/jetty/start/BaseBuilder.java index 4c4effcb5fd..11d74334669 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/BaseBuilder.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/BaseBuilder.java @@ -118,7 +118,15 @@ public class BaseBuilder if (!startArgs.getStartModules().isEmpty()) { for (String name:startArgs.getStartModules()) + { newly_added.addAll(modules.enable(name,"--add-to-start")); + if (!newly_added.contains(name)) + { + Set sources = modules.get(name).getEnableSources(); + sources.remove("--add-to-start"); + StartLog.info("%s already enabled by %s",name,sources); + } + } } if (StartLog.isDebugEnabled()) From f2737b173737fb07d962959803fc743c537395eb Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 16 Sep 2016 17:18:32 +1000 Subject: [PATCH 2/4] Issue #788 unit test --- .../barebones.alreadyEnabled.assert.txt | 17 +++++++++++++++++ .../barebones.alreadyEnabled.prepare.txt | 1 + 2 files changed, 18 insertions(+) create mode 100644 jetty-start/src/test/resources/usecases/barebones.alreadyEnabled.assert.txt create mode 100644 jetty-start/src/test/resources/usecases/barebones.alreadyEnabled.prepare.txt diff --git a/jetty-start/src/test/resources/usecases/barebones.alreadyEnabled.assert.txt b/jetty-start/src/test/resources/usecases/barebones.alreadyEnabled.assert.txt new file mode 100644 index 00000000000..9b924722124 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/barebones.alreadyEnabled.assert.txt @@ -0,0 +1,17 @@ +## The XMLs we expect (order is important) +XML|${jetty.home}/etc/base.xml +XML|${jetty.home}/etc/main.xml + +# The LIBs we expect (order is irrelevant) +LIB|${jetty.home}/lib/base.jar +LIB|${jetty.home}/lib/main.jar +LIB|${jetty.home}/lib/other.jar + +# The Properties we expect (order is irrelevant) +PROP|main.prop=value0 + +# Files / Directories to create +EXISTS|maindir/ +EXISTS|start.ini + +OUTPUT|INFO : main already enabled by \[\$\{jetty.base}/start.ini] diff --git a/jetty-start/src/test/resources/usecases/barebones.alreadyEnabled.prepare.txt b/jetty-start/src/test/resources/usecases/barebones.alreadyEnabled.prepare.txt new file mode 100644 index 00000000000..b780ce19332 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/barebones.alreadyEnabled.prepare.txt @@ -0,0 +1 @@ +--add-to-start=main From f7816a6ea44307b7d55d6bcda8128d96c61cc2e3 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 16 Sep 2016 10:31:01 +0200 Subject: [PATCH 3/4] Improved logging. --- .../src/main/java/org/eclipse/jetty/server/HttpChannel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index fc3e0146d26..eaa0bfe93f5 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -476,9 +476,9 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor else if (failure instanceof BadMessageException) { if (LOG.isDebugEnabled()) - LOG.warn(_request.getRequestURI(), failure); + LOG.debug(_request.getRequestURI(), failure); else - LOG.warn("{} {}",_request.getRequestURI(), failure.getMessage()); + LOG.warn("{} {}",_request.getRequestURI(), failure); } else { From 1bf87b317b0b4024eac58ae268db064a8c00bc83 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 16 Sep 2016 18:36:33 +1000 Subject: [PATCH 4/4] Add support of a query param to reset stats of StatisticsHandler tru StatisticsServlet (#919) StatisticsServlet: support a new parameter to be able to reset stats Signed-off-by: olivier lamy --- .../jetty/servlet/StatisticsServlet.java | 8 +- .../jetty/servlet/StatisticsServletTest.java | 154 ++++++++++++++++++ 2 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 jetty-servlet/src/test/java/org/eclipse/jetty/servlet/StatisticsServletTest.java diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/StatisticsServlet.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/StatisticsServlet.java index 0e9347e427d..d97eb76bdaa 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/StatisticsServlet.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/StatisticsServlet.java @@ -101,11 +101,17 @@ public class StatisticsServlet extends HttpServlet } } + if (Boolean.valueOf( req.getParameter("statsReset"))) + { + _statsHandler.statsReset(); + return; + } + String wantXml = req.getParameter("xml"); if (wantXml == null) wantXml = req.getParameter("XML"); - if (wantXml != null && "true".equalsIgnoreCase(wantXml)) + if (Boolean.valueOf(wantXml)) { sendXmlResponse(resp); } diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/StatisticsServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/StatisticsServletTest.java new file mode 100644 index 00000000000..6d1dcb86731 --- /dev/null +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/StatisticsServletTest.java @@ -0,0 +1,154 @@ +// +// ======================================================================== +// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.servlet; + +import org.eclipse.jetty.http.HttpTester; +import org.eclipse.jetty.http.HttpVersion; +import org.eclipse.jetty.server.LocalConnector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.StatisticsHandler; +import org.eclipse.jetty.server.session.SessionHandler; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.xml.sax.InputSource; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringReader; +import java.nio.ByteBuffer; + +public class StatisticsServletTest +{ + private Server _server; + + private LocalConnector _connector; + + @Before + public void createServer() + { + _server = new Server(); + _connector = new LocalConnector( _server ); + _server.addConnector( _connector ); + } + + + @After + public void destroyServer() + throws Exception + { + _server.stop(); + _server.join(); + } + + @Test + public void getStats() + throws Exception + { + StatisticsHandler statsHandler = new StatisticsHandler(); + _server.setHandler(statsHandler); + ServletContextHandler statsContext = new ServletContextHandler(statsHandler, "/"); + statsContext.addServlet( new ServletHolder( new TestServlet() ), "/test1" ); + ServletHolder servletHolder = new ServletHolder( new StatisticsServlet() ); + servletHolder.setInitParameter( "restrictToLocalhost", "false" ); + statsContext.addServlet( servletHolder, "/stats" ); + statsContext.setSessionHandler( new SessionHandler() ); + _server.start(); + + getResponse("/test1" ); + String response = getResponse("/stats?xml=true" ); + Stats stats = parseStats( response ); + + Assert.assertEquals(1, stats.responses2xx); + + getResponse("/stats?statsReset=true" ); + response = getResponse("/stats?xml=true" ); + stats = parseStats( response ); + + Assert.assertEquals(1, stats.responses2xx); + + getResponse("/test1" ); + getResponse("/nothing" ); + response = getResponse("/stats?xml=true" ); + stats = parseStats( response ); + + Assert.assertEquals(3, stats.responses2xx); + Assert.assertEquals(1, stats.responses4xx); + } + + public String getResponse( String path ) + throws Exception + { + HttpTester.Request request = new HttpTester.Request(); + request.setMethod( "GET" ); + request.setURI( path ); + request.setVersion( HttpVersion.HTTP_1_1 ); + request.setHeader( "Host", "test" ); + + ByteBuffer responseBuffer = _connector.getResponse( request.generate() ); + return HttpTester.parseResponse( responseBuffer ).getContent(); + } + + + public Stats parseStats( String xml ) + throws Exception + { + XPath xPath = XPathFactory.newInstance().newXPath(); + + String responses4xx = xPath.evaluate( "//responses4xx", new InputSource( new StringReader( xml ) ) ); + + String responses2xx = xPath.evaluate( "//responses2xx", new InputSource( new StringReader( xml ) ) ); + + return new Stats(Integer.parseInt( responses2xx), Integer.parseInt( responses4xx )); + } + + public static class Stats + { + int responses2xx,responses4xx; + + public Stats( int responses2xx, int responses4xx ) + { + this.responses2xx = responses2xx; + this.responses4xx = responses4xx; + } + } + + + public static class TestServlet + extends HttpServlet + { + + @Override + protected void doGet( HttpServletRequest req, HttpServletResponse resp ) + throws ServletException, IOException + { + resp.setStatus( HttpServletResponse.SC_OK ); + PrintWriter writer = resp.getWriter(); + writer.write( "Yup!!" ); + } + } + +}