Merged branch 'jetty-9.4.x' into 'master'.

This commit is contained in:
Simone Bordet 2016-09-16 10:38:25 +02:00
commit 4f533f39be
6 changed files with 189 additions and 3 deletions

View File

@ -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
{

View File

@ -100,11 +100,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);
}

View File

@ -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!!" );
}
}
}

View File

@ -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<String> sources = modules.get(name).getEnableSources();
sources.remove("--add-to-start");
StartLog.info("%s already enabled by %s",name,sources);
}
}
}
if (StartLog.isDebugEnabled())

View File

@ -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]

View File

@ -0,0 +1 @@
--add-to-start=main