487511 - Jetty HTTP won't work on turkish systems.

Fixed usages of toLowerCase() and toUpperCase() to use Locale.ENGLISH.
This commit is contained in:
Simone Bordet 2016-02-09 17:50:26 +01:00
parent e853632c22
commit 145e4bee71
8 changed files with 130 additions and 109 deletions

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.client;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
@ -445,7 +446,7 @@ public class HttpClientURITest extends AbstractHttpClientServerTest
});
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme.toUpperCase())
.scheme(scheme.toUpperCase(Locale.ENGLISH))
.timeout(5, TimeUnit.SECONDS)
.send();

View File

@ -18,6 +18,15 @@
package org.eclipse.jetty.http;
import java.nio.ByteBuffer;
import java.util.Enumeration;
import java.util.Locale;
import org.eclipse.jetty.util.BufferUtil;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -25,13 +34,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.nio.ByteBuffer;
import java.util.Enumeration;
import org.eclipse.jetty.util.BufferUtil;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
/**
*
*/
@ -134,11 +136,11 @@ public class HttpFieldsTest
BufferUtil.flipToFill(buffer);
HttpGenerator.putTo(header,buffer);
BufferUtil.flipToFlush(buffer,0);
String out = BufferUtil.toString(buffer).toLowerCase();
String out = BufferUtil.toString(buffer).toLowerCase(Locale.ENGLISH);
Assert.assertThat(out,Matchers.containsString((HttpHeader.CONNECTION+": "+HttpHeaderValue.KEEP_ALIVE).toLowerCase()));
Assert.assertThat(out,Matchers.containsString((HttpHeader.TRANSFER_ENCODING+": "+HttpHeaderValue.CHUNKED).toLowerCase()));
Assert.assertThat(out,Matchers.containsString((HttpHeader.CONTENT_ENCODING+": "+HttpHeaderValue.GZIP).toLowerCase()));
Assert.assertThat(out,Matchers.containsString((HttpHeader.CONNECTION+": "+HttpHeaderValue.KEEP_ALIVE).toLowerCase(Locale.ENGLISH)));
Assert.assertThat(out,Matchers.containsString((HttpHeader.TRANSFER_ENCODING+": "+HttpHeaderValue.CHUNKED).toLowerCase(Locale.ENGLISH)));
Assert.assertThat(out,Matchers.containsString((HttpHeader.CONTENT_ENCODING+": "+HttpHeaderValue.GZIP).toLowerCase(Locale.ENGLISH)));
}
@Test
@ -290,7 +292,7 @@ public class HttpFieldsTest
assertEquals(true, e.hasMoreElements());
assertEquals(e.nextElement(), "value0D");
assertEquals(false, e.hasMoreElements());
e = fields.getValues("name1",",");
assertEquals(true, e.hasMoreElements());
assertEquals(e.nextElement(), "value1A");
@ -301,7 +303,7 @@ public class HttpFieldsTest
assertEquals(true, e.hasMoreElements());
assertEquals(e.nextElement(), "value1D");
assertEquals(false, e.hasMoreElements());
}
@Test

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.quickstart;
import java.util.Locale;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -29,7 +31,7 @@ public class PreconfigureQuickStartWar
{
private static final Logger LOG = Log.getLogger(PreconfigureQuickStartWar.class);
static final boolean ORIGIN=LOG.isDebugEnabled();
public static void main(String... args) throws Exception
{
@ -72,7 +74,7 @@ public class PreconfigureQuickStartWar
break;
}
preconfigure(war,dir,xml);
}
@ -82,7 +84,7 @@ public class PreconfigureQuickStartWar
* @param xml A context XML to apply (or null if none)
* @throws Exception
*/
public static void preconfigure(Resource war, Resource dir, Resource xml) throws Exception
public static void preconfigure(Resource war, Resource dir, Resource xml) throws Exception
{
// Do we need to unpack a war?
if (war != null)
@ -94,14 +96,14 @@ public class PreconfigureQuickStartWar
dir.getFile().mkdirs();
JarResource.newJarResource(war).copyTo(dir.getFile());
}
final Server server = new Server();
QuickStartWebApp webapp = new QuickStartWebApp();
if (xml != null)
{
if (xml.isDirectory() || !xml.toString().toLowerCase().endsWith(".xml"))
if (xml.isDirectory() || !xml.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml"))
error("Bad context.xml: "+xml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(xml.getURL());
xmlConfiguration.configure(webapp);
@ -112,9 +114,9 @@ public class PreconfigureQuickStartWar
server.start();
server.stop();
}
private static void error(String message)
{

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.quickstart;
import java.io.FileOutputStream;
import java.util.Locale;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -33,35 +34,35 @@ import org.eclipse.jetty.webapp.WebAppContext;
public class QuickStartWebApp extends WebAppContext
{
private static final Logger LOG = Log.getLogger(QuickStartWebApp.class);
public static final String[] __configurationClasses = new String[]
public static final String[] __configurationClasses = new String[]
{
org.eclipse.jetty.quickstart.QuickStartConfiguration.class.getCanonicalName(),
org.eclipse.jetty.plus.webapp.EnvConfiguration.class.getCanonicalName(),
org.eclipse.jetty.plus.webapp.PlusConfiguration.class.getCanonicalName(),
org.eclipse.jetty.webapp.JettyWebXmlConfiguration.class.getCanonicalName()
};
private boolean _preconfigure=false;
private boolean _autoPreconfigure=false;
private boolean _startWebapp=false;
private PreconfigureDescriptorProcessor _preconfigProcessor;
public static final String[] __preconfigurationClasses = new String[]
{
org.eclipse.jetty.webapp.WebInfConfiguration.class.getCanonicalName(),
{
org.eclipse.jetty.webapp.WebInfConfiguration.class.getCanonicalName(),
org.eclipse.jetty.webapp.WebXmlConfiguration.class.getCanonicalName(),
org.eclipse.jetty.webapp.MetaInfConfiguration.class.getCanonicalName(),
org.eclipse.jetty.webapp.MetaInfConfiguration.class.getCanonicalName(),
org.eclipse.jetty.webapp.FragmentConfiguration.class.getCanonicalName(),
org.eclipse.jetty.plus.webapp.EnvConfiguration.class.getCanonicalName(),
org.eclipse.jetty.plus.webapp.EnvConfiguration.class.getCanonicalName(),
org.eclipse.jetty.plus.webapp.PlusConfiguration.class.getCanonicalName(),
org.eclipse.jetty.annotations.AnnotationConfiguration.class.getCanonicalName(),
};
public QuickStartWebApp()
{
super();
@ -76,7 +77,7 @@ public class QuickStartWebApp extends WebAppContext
/* ------------------------------------------------------------ */
/** Preconfigure webapp
* @param preconfigure If true, then starting the webapp will generate
* @param preconfigure If true, then starting the webapp will generate
* the WEB-INF/quickstart-web.xml rather than start the webapp.
*/
public void setPreconfigure(boolean preconfigure)
@ -88,22 +89,22 @@ public class QuickStartWebApp extends WebAppContext
{
return _autoPreconfigure;
}
public void setAutoPreconfigure(boolean autoPrecompile)
{
_autoPreconfigure = autoPrecompile;
}
@Override
protected void startWebapp() throws Exception
{
if (isPreconfigure())
generateQuickstartWebXml(_preconfigProcessor.getXML());
if (_startWebapp)
super.startWebapp();
}
@Override
protected void doStart() throws Exception
{
@ -117,14 +118,14 @@ public class QuickStartWebApp extends WebAppContext
if (base.isDirectory())
dir=base;
else if (base.toString().toLowerCase().endsWith(".war"))
else if (base.toString().toLowerCase(Locale.ENGLISH).endsWith(".war"))
{
war=base;
String w=war.toString();
dir=Resource.newResource(w.substring(0,w.length()-4));
if (!dir.exists())
{
{
LOG.info("Quickstart Extract " + war + " to " + dir);
dir.getFile().mkdirs();
JarResource.newJarResource(war).copyTo(dir.getFile());
@ -133,12 +134,12 @@ public class QuickStartWebApp extends WebAppContext
setWar(null);
setBaseResource(dir);
}
else
else
throw new IllegalArgumentException();
Resource qswebxml=dir.addPath("/WEB-INF/quickstart-web.xml");
if (isPreconfigure())
{
_preconfigProcessor = new PreconfigureDescriptorProcessor();
@ -151,17 +152,17 @@ public class QuickStartWebApp extends WebAppContext
_startWebapp=true;
}
else if (_autoPreconfigure)
{
{
LOG.info("Quickstart preconfigure: {}(war={},dir={})",this,war,dir);
_preconfigProcessor = new PreconfigureDescriptorProcessor();
_preconfigProcessor = new PreconfigureDescriptorProcessor();
getMetaData().addDescriptorProcessor(_preconfigProcessor);
setPreconfigure(true);
_startWebapp=true;
}
else
_startWebapp=true;
super.doStart();
}
@ -178,5 +179,5 @@ public class QuickStartWebApp extends WebAppContext
}
}
}

View File

@ -18,12 +18,33 @@
package org.eclipse.jetty.runner;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.authentication.BasicAuthenticator;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.server.handler.*;
import org.eclipse.jetty.server.AbstractConnector;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.ConnectorStatistics;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.ShutdownMonitor;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
@ -36,15 +57,6 @@ import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.xml.XmlConfiguration;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Runner
@ -111,8 +123,9 @@ public class Runner
addJars(item);
else
{
if (path.toLowerCase().endsWith(".jar") ||
path.toLowerCase().endsWith(".zip"))
String lowerCasePath = path.toLowerCase(Locale.ENGLISH);
if (lowerCasePath.endsWith(".jar") ||
lowerCasePath.endsWith(".zip"))
{
URL url = item.getURL();
_classpath.add(url);
@ -247,7 +260,7 @@ public class Runner
for (int i=0;i<args.length;i++)
{
switch (args[i])
switch (args[i])
{
case "--port":
port = Integer.parseInt(args[++i]);
@ -309,9 +322,9 @@ public class Runner
}
//apply jetty config files if there are any
if (_configFiles != null)
if (_configFiles != null)
{
for (String cfg : _configFiles)
for (String cfg : _configFiles)
{
try (Resource resource = Resource.newResource(cfg)) {
XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.getURL());
@ -322,7 +335,7 @@ public class Runner
//check that everything got configured, and if not, make the handlers
HandlerCollection handlers = (HandlerCollection) _server.getChildHandlerByClass(HandlerCollection.class);
if (handlers == null)
if (handlers == null)
{
handlers = new HandlerCollection();
_server.setHandler(handlers);
@ -330,14 +343,14 @@ public class Runner
//check if contexts already configured
_contexts = (ContextHandlerCollection) handlers.getChildHandlerByClass(ContextHandlerCollection.class);
if (_contexts == null)
if (_contexts == null)
{
_contexts = new ContextHandlerCollection();
prependHandler(_contexts, handlers);
}
if (_enableStats)
if (_enableStats)
{
//if no stats handler already configured
if (handlers.getChildHandlerByClass(StatisticsHandler.class) == null) {
@ -352,7 +365,7 @@ public class Runner
ServletContextHandler statsContext = new ServletContextHandler(_contexts, "/stats");
statsContext.addServlet(new ServletHolder(new StatisticsServlet()), "/");
statsContext.setSessionHandler(new SessionHandler());
if (_statsPropFile != null)
if (_statsPropFile != null)
{
HashLoginService loginService = new HashLoginService("StatsRealm", _statsPropFile);
Constraint constraint = new Constraint();
@ -374,14 +387,14 @@ public class Runner
}
//ensure a DefaultHandler is present
if (handlers.getChildHandlerByClass(DefaultHandler.class) == null)
if (handlers.getChildHandlerByClass(DefaultHandler.class) == null)
{
handlers.addHandler(new DefaultHandler());
}
//ensure a log handler is present
_logHandler = (RequestLogHandler) handlers.getChildHandlerByClass(RequestLogHandler.class);
if (_logHandler == null)
if (_logHandler == null)
{
_logHandler = new RequestLogHandler();
handlers.addHandler(_logHandler);
@ -390,7 +403,7 @@ public class Runner
//check a connector is configured to listen on
Connector[] connectors = _server.getConnectors();
if (connectors == null || connectors.length == 0)
if (connectors == null || connectors.length == 0)
{
ServerConnector connector = new ServerConnector(_server);
connector.setPort(port);
@ -399,12 +412,12 @@ public class Runner
_server.addConnector(connector);
if (_enableStats)
connector.addBean(new ConnectorStatistics());
}
else
}
else
{
if (_enableStats)
if (_enableStats)
{
for (Connector connector : connectors)
for (Connector connector : connectors)
{
((AbstractConnector) connector).addBean(new ConnectorStatistics());
}
@ -415,7 +428,7 @@ public class Runner
}
// Create a context
try (Resource ctx = Resource.newResource(args[i]))
try (Resource ctx = Resource.newResource(args[i]))
{
if (!ctx.exists())
usage("Context '" + ctx + "' does not exist");
@ -424,7 +437,7 @@ public class Runner
contextPath = "/" + contextPath;
// Configure the context
if (!ctx.isDirectory() && ctx.toString().toLowerCase().endsWith(".xml"))
if (!ctx.isDirectory() && ctx.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml"))
{
// It is a context config file
XmlConfiguration xmlConfiguration = new XmlConfiguration(ctx.getURL());
@ -435,7 +448,7 @@ public class Runner
_contexts.addHandler(handler);
handler.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", __containerIncludeJarPattern);
}
else
else
{
// assume it is a WAR file
WebAppContext webapp = new WebAppContext(_contexts, ctx.toString(), contextPath);

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.servlet;
import java.io.IOException;
import java.util.Locale;
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
@ -35,37 +36,37 @@ import org.eclipse.jetty.util.resource.Resource;
/* ------------------------------------------------------------ */
/** Servlet handling JSP Property Group mappings
* <p>
* This servlet is mapped to by any URL pattern for a JSP property group.
* This servlet is mapped to by any URL pattern for a JSP property group.
* Resources handled by this servlet that are not directories will be passed
* directly to the JSP servlet. Resources that are directories will be
* directly to the JSP servlet. Resources that are directories will be
* passed directly to the default servlet.
*/
public class JspPropertyGroupServlet extends GenericServlet
{
private static final long serialVersionUID = 3681783214726776945L;
public final static String NAME = "__org.eclipse.jetty.servlet.JspPropertyGroupServlet__";
private final ServletHandler _servletHandler;
private final ContextHandler _contextHandler;
private ServletHolder _dftServlet;
private ServletHolder _jspServlet;
private boolean _starJspMapped;
public JspPropertyGroupServlet(ContextHandler context, ServletHandler servletHandler)
{
_contextHandler=context;
_servletHandler=servletHandler;
_servletHandler=servletHandler;
}
@Override
public void init() throws ServletException
{
{
String jsp_name = "jsp";
ServletMapping servlet_mapping =_servletHandler.getServletMapping("*.jsp");
if (servlet_mapping!=null)
{
_starJspMapped=true;
//now find the jsp servlet, ignoring the mapping that is for ourself
ServletMapping[] mappings = _servletHandler.getServletMappings();
for (ServletMapping m:mappings)
@ -80,11 +81,11 @@ public class JspPropertyGroupServlet extends GenericServlet
}
}
}
jsp_name=servlet_mapping.getServletName();
}
_jspServlet=_servletHandler.getServlet(jsp_name);
String dft_name="default";
ServletMapping default_mapping=_servletHandler.getServletMapping("/");
if (default_mapping!=null)
@ -94,7 +95,7 @@ public class JspPropertyGroupServlet extends GenericServlet
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
{
{
HttpServletRequest request = null;
if (req instanceof HttpServletRequest)
request = (HttpServletRequest)req;
@ -118,27 +119,27 @@ public class JspPropertyGroupServlet extends GenericServlet
servletPath = request.getServletPath();
pathInfo = request.getPathInfo();
}
String pathInContext=URIUtil.addPaths(servletPath,pathInfo);
if (pathInContext.endsWith("/"))
{
_dftServlet.getServlet().service(req,res);
}
else if (_starJspMapped && pathInContext.toLowerCase().endsWith(".jsp"))
else if (_starJspMapped && pathInContext.toLowerCase(Locale.ENGLISH).endsWith(".jsp"))
{
_jspServlet.getServlet().service(req,res);
}
else
{
Resource resource = _contextHandler.getResource(pathInContext);
if (resource!=null && resource.isDirectory())
_dftServlet.getServlet().service(req,res);
else
_jspServlet.getServlet().service(req,res);
}
}
}

View File

@ -279,7 +279,7 @@ public class Module
{
return true;
}
System.err.printf("%nModule %s:%n",getName());
System.err.printf(" + contains software not provided by the Eclipse Foundation!%n");
System.err.printf(" + contains software not covered by the Eclipse Public License!%n");
@ -309,7 +309,7 @@ public class Module
System.err.printf("%nProceed (y/N)? ");
String line = input.readLine();
licenseAck = !(line == null || line.length() == 0 || !line.toLowerCase().startsWith("y"));
licenseAck = !(line == null || line.length() == 0 || !line.toLowerCase(Locale.ENGLISH).startsWith("y"));
}
}

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.util.security;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Locale;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -28,15 +29,15 @@ import org.eclipse.jetty.util.log.Logger;
/* ------------------------------------------------------------ */
/**
* Password utility class.
*
*
* This utility class gets a password or pass phrase either by:
*
*
* <PRE>
* + Password is set as a system property.
* + The password is prompted for and read from standard input
* + A program is run to get the password.
* </pre>
*
*
* Passwords that begin with OBF: are de obfuscated. Passwords can be obfuscated
* by run org.eclipse.util.Password as a main class. Obfuscated password are
* required if a system needs to recover the full password (eg. so that it may
@ -50,8 +51,8 @@ import org.eclipse.jetty.util.log.Logger;
* a secure(ish) way to store passwords that only need to be checked rather than
* recovered. Note that it is not strong security - specially if simple
* passwords are used.
*
*
*
*
*/
public class Password extends Credential
{
@ -66,7 +67,7 @@ public class Password extends Credential
/* ------------------------------------------------------------ */
/**
* Constructor.
*
*
* @param password The String password.
*/
public Password(String password)
@ -112,10 +113,10 @@ public class Password extends Credential
@Override
public boolean equals(Object o)
{
if (this == o)
if (this == o)
return true;
if (null == o)
if (null == o)
return false;
if (o instanceof Password)
@ -125,7 +126,7 @@ public class Password extends Credential
return p._pw == _pw || (null != _pw && _pw.equals(p._pw));
}
if (o instanceof String)
if (o instanceof String)
return o.equals(_pw);
return false;
@ -151,8 +152,8 @@ public class Password extends Credential
byte b2 = b[b.length - (i + 1)];
if (b1<0 || b2<0)
{
int i0 = (0xff&b1)*256 + (0xff&b2);
String x = Integer.toString(i0, 36).toLowerCase();
int i0 = (0xff&b1)*256 + (0xff&b2);
String x = Integer.toString(i0, 36).toLowerCase(Locale.ENGLISH);
buf.append("U0000",0,5-x.length());
buf.append(x);
}
@ -161,13 +162,13 @@ public class Password extends Credential
int i1 = 127 + b1 + b2;
int i2 = 127 + b1 - b2;
int i0 = i1 * 256 + i2;
String x = Integer.toString(i0, 36).toLowerCase();
String x = Integer.toString(i0, 36).toLowerCase(Locale.ENGLISH);
int j0 = Integer.parseInt(x, 36);
int j1 = (i0 / 256);
int j2 = (i0 % 256);
byte bx = (byte) ((j1 + j2 - 254) / 2);
buf.append("000",0,4-x.length());
buf.append(x);
}
@ -216,7 +217,7 @@ public class Password extends Credential
* <LI>Prompting for a password
* <LI>Using promptDft if nothing was entered.
* </UL>
*
*
* @param realm The realm name for the password, used as a SystemProperty
* name.
* @param dft The default password.