diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java index 59082e104ee..dabee2ce127 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java @@ -26,6 +26,7 @@ import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.jar.JarEntry; import org.eclipse.jetty.util.Loader; @@ -807,7 +808,7 @@ public class AnnotationParser try { String name = entry.getName(); - if (name.toLowerCase().endsWith(".class")) + if (name.toLowerCase(Locale.ENGLISH).endsWith(".class")) { String shortName = name.replace('/', '.').substring(0,name.length()-6); if ((resolver == null) @@ -853,7 +854,7 @@ public class AnnotationParser try { String name = entry.getName(); - if (name.toLowerCase().endsWith(".class")) + if (name.toLowerCase(Locale.ENGLISH).endsWith(".class")) { String shortName = name.replace('/', '.').substring(0,name.length()-6); diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ResourceAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ResourceAnnotationHandler.java index 0f15b2a7239..7f03c79e06e 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ResourceAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ResourceAnnotationHandler.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.annotations; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.Locale; import javax.annotation.Resource; import javax.naming.InitialContext; import javax.naming.NameNotFoundException; @@ -261,7 +262,7 @@ public class ResourceAnnotationHandler extends AbstractIntrospectableAnnotationH //default name is the javabean property name String name = method.getName().substring(3); - name = name.substring(0,1).toLowerCase()+name.substring(1); + name = name.substring(0,1).toLowerCase(Locale.ENGLISH)+name.substring(1); name = clazz.getCanonicalName()+"/"+name; name = (resource.name()!=null && !resource.name().trim().equals("")? resource.name(): name); diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java index d4fc27fb973..ab074d21b01 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -323,7 +324,7 @@ public class HttpClient extends ContainerLifeCycle protected void send(final Request request, List listeners) { - String scheme = request.getScheme().toLowerCase(); + String scheme = request.getScheme().toLowerCase(Locale.ENGLISH); if (!Arrays.asList("http", "https").contains(scheme)) throw new IllegalArgumentException("Invalid protocol " + scheme); diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpCookieParser.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpCookieParser.java index 8a7fbca3772..0651fe2636c 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpCookieParser.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpCookieParser.java @@ -44,7 +44,7 @@ public class HttpCookieParser public static List parseCookies(String headerValue) { - if (headerValue.toLowerCase().contains("expires=")) + if (headerValue.toLowerCase(Locale.ENGLISH).contains("expires=")) { HttpCookie cookie = parseCookie(headerValue, 0); if (cookie != null) @@ -111,7 +111,7 @@ public class HttpCookieParser try { String[] attributeParts = cookieParts[i].split("=", 2); - String attributeName = attributeParts[0].trim().toLowerCase(); + String attributeName = attributeParts[0].trim().toLowerCase(Locale.ENGLISH); String attributeValue = attributeParts.length < 2 ? "" : attributeParts[1].trim(); switch (attributeName) { diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java index b922ef24fa4..e8cdec6d1db 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.List; +import java.util.Locale; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicMarkableReference; import java.util.concurrent.atomic.AtomicReference; @@ -191,7 +192,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler if (exchange != null) { exchange.getResponse().getHeaders().add(name, value); - switch (name.toLowerCase()) + switch (name.toLowerCase(Locale.ENGLISH)) { case "set-cookie": case "set-cookie2": diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java b/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java index 1eba12ed74e..cecd461cfea 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.client.util; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.UnsupportedCharsetException; +import java.util.Locale; import org.eclipse.jetty.client.api.Response; import org.eclipse.jetty.client.api.Result; @@ -69,7 +70,7 @@ public abstract class BufferingResponseListener extends Response.Listener.Empty if (contentType != null) { String charset = "charset="; - int index = contentType.toLowerCase().indexOf(charset); + int index = contentType.toLowerCase(Locale.ENGLISH).indexOf(charset); if (index > 0) { String encoding = contentType.substring(index + charset.length()); diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java b/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java index 066520c1bb1..63ccdb74b3a 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; @@ -108,7 +109,7 @@ public class DigestAuthentication implements Authentication Matcher matcher = PARAM_PATTERN.matcher(part); if (matcher.matches()) { - String name = matcher.group(1).trim().toLowerCase(); + String name = matcher.group(1).trim().toLowerCase(Locale.ENGLISH); String value = matcher.group(2).trim(); if (value.startsWith("\"") && value.endsWith("\"")) value = value.substring(1, value.length() - 1); @@ -251,7 +252,7 @@ public class DigestAuthentication implements Authentication private String nextNonceCount() { String padding = "00000000"; - String next = Integer.toHexString(nonceCount.incrementAndGet()).toLowerCase(); + String next = Integer.toHexString(nonceCount.incrementAndGet()).toLowerCase(Locale.ENGLISH); return padding.substring(0, padding.length() - next.length()) + next; } @@ -265,7 +266,7 @@ public class DigestAuthentication implements Authentication private String toHexString(byte[] bytes) { - return TypeUtil.toHexString(bytes).toLowerCase(); + return TypeUtil.toHexString(bytes).toLowerCase(Locale.ENGLISH); } } } diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientLoadTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientLoadTest.java index 54cc78811de..25c4be15340 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientLoadTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientLoadTest.java @@ -23,6 +23,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.Random; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -184,7 +185,7 @@ public class HttpClientLoadTest extends AbstractHttpClientServerTest @Override public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - String method = request.getMethod().toUpperCase(); + String method = request.getMethod().toUpperCase(Locale.ENGLISH); switch (method) { case "GET": diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpSenderTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpSenderTest.java index 25136c830a8..9f46eccdb76 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpSenderTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpSenderTest.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.client; import java.net.URI; import java.nio.ByteBuffer; +import java.util.Locale; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -288,8 +289,8 @@ public class HttpSenderTest String requestString = endPoint.takeOutputString(); Assert.assertTrue(requestString.startsWith("GET ")); - String content = Integer.toHexString(content1.length()).toUpperCase() + "\r\n" + content1 + "\r\n"; - content += Integer.toHexString(content2.length()).toUpperCase() + "\r\n" + content2 + "\r\n"; + String content = Integer.toHexString(content1.length()).toUpperCase(Locale.ENGLISH) + "\r\n" + content1 + "\r\n"; + content += Integer.toHexString(content2.length()).toUpperCase(Locale.ENGLISH) + "\r\n" + content2 + "\r\n"; content += "0\r\n\r\n"; Assert.assertTrue(requestString.endsWith("\r\n\r\n" + content)); Assert.assertTrue(headersLatch.await(5, TimeUnit.SECONDS)); diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java index 61aa16509d1..8b301d8035d 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; import java.net.MalformedURLException; +import java.util.Locale; import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.ConfigurationManager; @@ -77,7 +78,7 @@ public class WebAppProvider extends ScanningAppProvider { return false; } - String lowername = name.toLowerCase(); + String lowername = name.toLowerCase(Locale.ENGLISH); File file = new File(dir,name); @@ -299,9 +300,9 @@ public class WebAppProvider extends ScanningAppProvider { context = URIUtil.SLASH; } - else if (context.toLowerCase().startsWith("root-")) + else if (context.toLowerCase(Locale.ENGLISH).startsWith("root-")) { - int dash=context.toLowerCase().indexOf('-'); + int dash=context.toLowerCase(Locale.ENGLISH).indexOf('-'); String virtual = context.substring(dash+1); wah.setVirtualHosts(new String[]{virtual}); context = URIUtil.SLASH; diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/util/FileID.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/util/FileID.java index cda1fe21a88..7df726926f0 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/util/FileID.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/util/FileID.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.deploy.util; import java.io.File; +import java.util.Locale; /** * Simple, yet surprisingly common utility methods for identifying various file types commonly seen and worked with in a @@ -38,7 +39,7 @@ public class FileID { if (path.isFile()) { - String name = path.getName().toLowerCase(); + String name = path.getName().toLowerCase(Locale.ENGLISH); return (name.endsWith(".war") || name.endsWith(".jar")); } @@ -62,7 +63,7 @@ public class FileID return false; } - String name = path.getName().toLowerCase(); + String name = path.getName().toLowerCase(Locale.ENGLISH); return (name.endsWith(".war") || name.endsWith(".jar")); } @@ -73,7 +74,7 @@ public class FileID return false; } - String name = path.getName().toLowerCase(); + String name = path.getName().toLowerCase(Locale.ENGLISH); return name.endsWith(".xml"); } } diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java index 6657b94f4a3..94551ed56cd 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java @@ -810,7 +810,7 @@ public class HttpFields implements Iterable { hasDomain = true; buf.append(";Domain="); - QuotedStringTokenizer.quoteIfNeeded(buf,domain.toLowerCase(),delim); + QuotedStringTokenizer.quoteIfNeeded(buf,domain.toLowerCase(Locale.ENGLISH),delim); } if (maxAge >= 0) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java b/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java index b252ca99025..17b6056a54d 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java @@ -22,6 +22,7 @@ import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.Enumeration; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -70,7 +71,7 @@ public class MimeTypes _string=s; _buffer=BufferUtil.toBuffer(s); - int i=s.toLowerCase().indexOf("charset="); + int i=s.toLowerCase(Locale.ENGLISH).indexOf("charset="); _charset=(i>0)?Charset.forName(s.substring(i+8)):null; } diff --git a/jetty-http/src/main/resources/org/eclipse/jetty/http/mime.properties b/jetty-http/src/main/resources/org/eclipse/jetty/http/mime.properties index 1d4c73da6ef..74601e30851 100644 --- a/jetty-http/src/main/resources/org/eclipse/jetty/http/mime.properties +++ b/jetty-http/src/main/resources/org/eclipse/jetty/http/mime.properties @@ -171,6 +171,7 @@ xhtml=application/xhtml+xml xls=application/vnd.ms-excel xml=application/xml xpm=image/x-xpixmap +xsd=application/xml xsl=application/xml xslt=application/xslt+xml xul=application/vnd.mozilla.xul+xml diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java index 3eba7713e9f..ea1198a786f 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.http; import java.nio.ByteBuffer; import java.util.Enumeration; import java.util.HashSet; +import java.util.Locale; import java.util.Set; import org.eclipse.jetty.util.BufferUtil; @@ -385,7 +386,7 @@ public class HttpFieldsTest { Set s=new HashSet(); while(e.hasMoreElements()) - s.add(e.nextElement().toLowerCase()); + s.add(e.nextElement().toLowerCase(Locale.ENGLISH)); return s; } diff --git a/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/LdapLoginModule.java b/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/LdapLoginModule.java index 734dece175d..649b31bbc7b 100644 --- a/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/LdapLoginModule.java +++ b/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/LdapLoginModule.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Properties; import javax.naming.Context; @@ -652,12 +653,12 @@ public class LdapLoginModule extends AbstractLoginModule public static String convertCredentialJettyToLdap(String encryptedPassword) { - if ("MD5:".startsWith(encryptedPassword.toUpperCase())) + if ("MD5:".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH))) { return "{MD5}" + encryptedPassword.substring("MD5:".length(), encryptedPassword.length()); } - if ("CRYPT:".startsWith(encryptedPassword.toUpperCase())) + if ("CRYPT:".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH))) { return "{CRYPT}" + encryptedPassword.substring("CRYPT:".length(), encryptedPassword.length()); } @@ -672,12 +673,12 @@ public class LdapLoginModule extends AbstractLoginModule return encryptedPassword; } - if ("{MD5}".startsWith(encryptedPassword.toUpperCase())) + if ("{MD5}".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH))) { return "MD5:" + encryptedPassword.substring("{MD5}".length(), encryptedPassword.length()); } - if ("{CRYPT}".startsWith(encryptedPassword.toUpperCase())) + if ("{CRYPT}".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH))) { return "CRYPT:" + encryptedPassword.substring("{CRYPT}".length(), encryptedPassword.length()); } diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java index 8c81f8654b2..2b1e346844e 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.jmx; import java.io.IOException; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.WeakHashMap; @@ -164,7 +165,7 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable domain = obj.getClass().getPackage().getName(); - String type = obj.getClass().getName().toLowerCase(); + String type = obj.getClass().getName().toLowerCase(Locale.ENGLISH); int dot = type.lastIndexOf('.'); if (dot >= 0) type = type.substring(dot + 1); diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java index db02cd3eb4b..2dcc9289570 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import javax.management.Attribute; @@ -622,7 +623,7 @@ public class ObjectMBean implements DynamicMBean convert = true; } - String uName = name.substring(0, 1).toUpperCase() + name.substring(1); + String uName = name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1); Class oClass = onMBean ? this.getClass() : _managed.getClass(); LOG.debug("defineAttribute {} {}:{}:{}:{}",name,onMBean,readonly,oClass,description); @@ -862,7 +863,7 @@ public class ObjectMBean implements DynamicMBean variableName = variableName.substring(2); } - variableName = variableName.substring(0,1).toLowerCase() + variableName.substring(1); + variableName = variableName.substring(0,1).toLowerCase(Locale.ENGLISH) + variableName.substring(1); return variableName; } diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java index f37a67ff663..a38272e09a0 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java @@ -36,6 +36,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Random; @@ -774,7 +775,7 @@ public class JettyRunForkedMojo extends AbstractMojo private String createToken () { - return Long.toString(random.nextLong()^System.currentTimeMillis(), 36).toUpperCase(); + return Long.toString(random.nextLong()^System.currentTimeMillis(), 36).toUpperCase(Locale.ENGLISH); } diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java index e982fdb9571..5d439e3e71d 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java @@ -24,6 +24,7 @@ import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Locale; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.LazyList; @@ -202,7 +203,7 @@ public class MavenWebInfConfiguration extends WebInfConfiguration { for (File f: jwac.getClassPathFiles()) { - if (f.getName().toLowerCase().endsWith(".jar")) + if (f.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) { try { diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java index aa7a6b43ce3..2cdf9b03bda 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java @@ -23,6 +23,7 @@ import java.io.FilenameFilter; import java.io.IOException; import java.util.HashSet; import java.util.Iterator; +import java.util.Locale; import java.util.Map.Entry; import java.util.Set; @@ -116,7 +117,7 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider */ private static String getDeployedAppName(String contextFileName) { - String lowername = contextFileName.toLowerCase(); + String lowername = contextFileName.toLowerCase(Locale.ENGLISH); if (lowername.endsWith(".xml")) { String contextName = contextFileName.substring(0, lowername.length() - ".xml".length()); diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java index 6a3010db277..6e1f7b9b5af 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/LibExtClassLoaderHelper.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -109,7 +110,7 @@ public class LibExtClassLoaderHelper for (File f : jettyResources.listFiles()) { jettyResFiles.put(f.getName(), f); - if (f.getName().toLowerCase().startsWith("readme")) + if (f.getName().toLowerCase(Locale.ENGLISH).startsWith("readme")) { continue; } diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/Injection.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/Injection.java index 5cfad9a248a..da94978a726 100644 --- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/Injection.java +++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/Injection.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.plus.annotation; import java.lang.reflect.Field; import java.lang.reflect.Member; import java.lang.reflect.Method; +import java.util.Locale; import javax.naming.InitialContext; import javax.naming.NamingException; @@ -140,7 +141,7 @@ public class Injection _resourceClass = resourceType; //first look for a javabeans style setter matching the targetName - String setter = "set"+target.substring(0,1).toUpperCase()+target.substring(1); + String setter = "set"+target.substring(0,1).toUpperCase(Locale.ENGLISH)+target.substring(1); try { LOG.debug("Looking for method for setter: "+setter+" with arg "+_resourceClass); diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/security/DataSourceLoginService.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/security/DataSourceLoginService.java index ae9e906a172..ffad0f617f2 100644 --- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/security/DataSourceLoginService.java +++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/security/DataSourceLoginService.java @@ -26,6 +26,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import javax.naming.InitialContext; import javax.naming.NameNotFoundException; import javax.naming.NamingException; @@ -413,7 +414,7 @@ public class DataSourceLoginService extends MappedLoginService DatabaseMetaData metaData = connection.getMetaData(); //check if tables exist - String tableName = (metaData.storesLowerCaseIdentifiers()? _userTableName.toLowerCase(): (metaData.storesUpperCaseIdentifiers()?_userTableName.toUpperCase(): _userTableName)); + String tableName = (metaData.storesLowerCaseIdentifiers()? _userTableName.toLowerCase(Locale.ENGLISH): (metaData.storesUpperCaseIdentifiers()?_userTableName.toUpperCase(Locale.ENGLISH): _userTableName)); ResultSet result = metaData.getTables(null, null, tableName, null); if (!result.next()) { @@ -431,7 +432,7 @@ public class DataSourceLoginService extends MappedLoginService result.close(); - tableName = (metaData.storesLowerCaseIdentifiers()? _roleTableName.toLowerCase(): (metaData.storesUpperCaseIdentifiers()?_roleTableName.toUpperCase(): _roleTableName)); + tableName = (metaData.storesLowerCaseIdentifiers()? _roleTableName.toLowerCase(Locale.ENGLISH): (metaData.storesUpperCaseIdentifiers()?_roleTableName.toUpperCase(Locale.ENGLISH): _roleTableName)); result = metaData.getTables(null, null, tableName, null); if (!result.next()) { @@ -448,7 +449,7 @@ public class DataSourceLoginService extends MappedLoginService result.close(); - tableName = (metaData.storesLowerCaseIdentifiers()? _userRoleTableName.toLowerCase(): (metaData.storesUpperCaseIdentifiers()?_userRoleTableName.toUpperCase(): _userRoleTableName)); + tableName = (metaData.storesLowerCaseIdentifiers()? _userRoleTableName.toLowerCase(Locale.ENGLISH): (metaData.storesUpperCaseIdentifiers()?_userRoleTableName.toUpperCase(Locale.ENGLISH): _userRoleTableName)); result = metaData.getTables(null, null, tableName, null); if (!result.next()) { diff --git a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ProxyServlet.java b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ProxyServlet.java index 18c8e72ea32..f6bb52fc37d 100644 --- a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ProxyServlet.java +++ b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ProxyServlet.java @@ -30,6 +30,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.StringTokenizer; @@ -489,7 +490,7 @@ public class ProxyServlet implements Servlet protected void onResponseHeader(Buffer name, Buffer value) throws IOException { String nameString = name.toString(); - String s = nameString.toLowerCase(); + String s = nameString.toLowerCase(Locale.ENGLISH); if (!_DontProxyHeaders.contains(s) || (HttpHeader.CONNECTION.is(name) && HttpHeaderValue.CLOSE.is(value))) { if (debug != 0) @@ -560,7 +561,7 @@ public class ProxyServlet implements Servlet String connectionHdr = request.getHeader("Connection"); if (connectionHdr != null) { - connectionHdr = connectionHdr.toLowerCase(); + connectionHdr = connectionHdr.toLowerCase(Locale.ENGLISH); if (connectionHdr.indexOf("keep-alive") < 0 && connectionHdr.indexOf("close") < 0) connectionHdr = null; } @@ -578,7 +579,7 @@ public class ProxyServlet implements Servlet { // TODO could be better than this! String hdr = (String)enm.nextElement(); - String lhdr = hdr.toLowerCase(); + String lhdr = hdr.toLowerCase(Locale.ENGLISH); if (_DontProxyHeaders.contains(lhdr)) continue; diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AbstractConnectHandlerTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AbstractConnectHandlerTest.java index bb80dcd90a3..037dd025f5c 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AbstractConnectHandlerTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AbstractConnectHandlerTest.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.net.Socket; import java.net.SocketTimeoutException; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -105,7 +106,7 @@ public abstract class AbstractConnectHandlerTest assertTrue(header.lookingAt()); String headerName = header.group(1); String headerValue = header.group(2); - headers.put(headerName.toLowerCase(), headerValue.toLowerCase()); + headers.put(headerName.toLowerCase(Locale.ENGLISH), headerValue.toLowerCase(Locale.ENGLISH)); } StringBuilder body; diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteHandlerTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteHandlerTest.java index 91e3efc69bf..66866e3ff1e 100644 --- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteHandlerTest.java +++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteHandlerTest.java @@ -79,6 +79,20 @@ public class RewriteHandlerTest extends AbstractRuleTestCase @Test public void test() throws Exception { + _response.setStatus(200); + _request.setHandled(false); + _handler.setOriginalPathAttribute("/before"); + _handler.setRewriteRequestURI(true); + _handler.setRewritePathInfo(true); + _request.setRequestURI("/xxx/bar"); + _request.setPathInfo("/xxx/bar"); + _handler.handle("/xxx/bar",_request,_request, _response); + assertEquals(201,_response.getStatus()); + assertEquals("/bar/zzz",_request.getAttribute("target")); + assertEquals("/bar/zzz",_request.getAttribute("URI")); + assertEquals("/bar/zzz",_request.getAttribute("info")); + assertEquals(null,_request.getAttribute("before")); + _response.setStatus(200); _request.setHandled(false); _handler.setOriginalPathAttribute("/before"); diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java b/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java index 6ee6bb4e706..c08e97c7b8a 100644 --- a/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java +++ b/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.security.authentication; import java.io.IOException; import java.util.Collections; import java.util.Enumeration; +import java.util.Locale; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletRequest; @@ -413,7 +414,7 @@ public class FormAuthenticator extends LoginAuthenticator @Override public long getDateHeader(String name) { - if (name.toLowerCase().startsWith("if-")) + if (name.toLowerCase(Locale.ENGLISH).startsWith("if-")) return -1; return super.getDateHeader(name); } @@ -421,7 +422,7 @@ public class FormAuthenticator extends LoginAuthenticator @Override public String getHeader(String name) { - if (name.toLowerCase().startsWith("if-")) + if (name.toLowerCase(Locale.ENGLISH).startsWith("if-")) return null; return super.getHeader(name); } @@ -435,7 +436,7 @@ public class FormAuthenticator extends LoginAuthenticator @Override public Enumeration getHeaders(String name) { - if (name.toLowerCase().startsWith("if-")) + if (name.toLowerCase(Locale.ENGLISH).startsWith("if-")) return Collections.enumeration(Collections.emptyList()); return super.getHeaders(name); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java index a61f780c133..15d1787ffd1 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; @@ -314,7 +315,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co { synchronized (_factories) { - return _factories.get(protocol.toLowerCase()); + return _factories.get(protocol.toLowerCase(Locale.ENGLISH)); } } @@ -337,7 +338,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co ConnectionFactory old=_factories.remove(factory.getProtocol()); if (old!=null) removeBean(old); - _factories.put(factory.getProtocol().toLowerCase(), factory); + _factories.put(factory.getProtocol().toLowerCase(Locale.ENGLISH), factory); addBean(factory); if (_defaultProtocol==null) _defaultProtocol=factory.getProtocol(); @@ -348,7 +349,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co { synchronized (_factories) { - ConnectionFactory factory= _factories.remove(protocol.toLowerCase()); + ConnectionFactory factory= _factories.remove(protocol.toLowerCase(Locale.ENGLISH)); removeBean(factory); return factory; } @@ -403,7 +404,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co public void setDefaultProtocol(String defaultProtocol) { - _defaultProtocol = defaultProtocol.toLowerCase(); + _defaultProtocol = defaultProtocol.toLowerCase(Locale.ENGLISH); if (isRunning()) _defaultConnectionFactory=getConnectionFactory(_defaultProtocol); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/CookieCutter.java b/jetty-server/src/main/java/org/eclipse/jetty/server/CookieCutter.java index 57e3f042024..6c9472149f3 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/CookieCutter.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/CookieCutter.java @@ -17,6 +17,8 @@ // package org.eclipse.jetty.server; +import java.util.Locale; + import javax.servlet.http.Cookie; import org.eclipse.jetty.util.LazyList; @@ -283,7 +285,7 @@ public class CookieCutter { if (name.startsWith("$")) { - String lowercaseName = name.toLowerCase(); + String lowercaseName = name.toLowerCase(Locale.ENGLISH); if ("$path".equals(lowercaseName)) { if (cookie!=null) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java index 61b7b983bf5..c7614071991 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionIdManager.java @@ -34,6 +34,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Random; import java.util.Timer; import java.util.TimerTask; @@ -124,7 +125,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager public DatabaseAdaptor (DatabaseMetaData dbMeta) throws SQLException { - _dbName = dbMeta.getDatabaseProductName().toLowerCase(); + _dbName = dbMeta.getDatabaseProductName().toLowerCase(Locale.ENGLISH); LOG.debug ("Using database {}",_dbName); _isLower = dbMeta.storesLowerCaseIdentifiers(); _isUpper = dbMeta.storesUpperCaseIdentifiers(); @@ -140,9 +141,9 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager public String convertIdentifier (String identifier) { if (_isLower) - return identifier.toLowerCase(); + return identifier.toLowerCase(Locale.ENGLISH); if (_isUpper) - return identifier.toUpperCase(); + return identifier.toUpperCase(Locale.ENGLISH); return identifier; } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java index a636570871e..22463973e60 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.Socket; +import java.util.Locale; import org.eclipse.jetty.server.session.SessionHandler; import org.eclipse.jetty.util.IO; @@ -52,7 +53,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest _handler.setSuspendFor(100); _handler.setResumeAfter(25); - assertTrue(process(null).toUpperCase().contains("RESUMED")); + assertTrue(process(null).toUpperCase(Locale.ENGLISH).contains("RESUMED")); } @Test @@ -66,7 +67,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest _server.start(); _handler.setSuspendFor(50); - assertTrue(process(null).toUpperCase().contains("TIMEOUT")); + assertTrue(process(null).toUpperCase(Locale.ENGLISH).contains("TIMEOUT")); } @Test @@ -81,7 +82,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest _handler.setSuspendFor(100); _handler.setCompleteAfter(25); - assertTrue(process(null).toUpperCase().contains("COMPLETED")); + assertTrue(process(null).toUpperCase(Locale.ENGLISH).contains("COMPLETED")); } private synchronized String process(String content) throws UnsupportedEncodingException, IOException, InterruptedException diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java index 287ae0d3750..5812e0a2af3 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java @@ -30,6 +30,7 @@ import java.net.Socket; import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -153,7 +154,7 @@ public class IPAccessHandlerTest assertTrue(header.lookingAt()); String headerName = header.group(1); String headerValue = header.group(2); - headers.put(headerName.toLowerCase(), headerValue.toLowerCase()); + headers.put(headerName.toLowerCase(Locale.ENGLISH), headerValue.toLowerCase(Locale.ENGLISH)); } StringBuilder body = new StringBuilder(); diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Invoker.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Invoker.java index 86e60b356c7..21fe1c763c7 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Invoker.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Invoker.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.servlet; import java.io.IOException; import java.util.Enumeration; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.ServletException; @@ -90,7 +91,7 @@ public class Invoker extends HttpServlet { String param=(String)e.nextElement(); String value=getInitParameter(param); - String lvalue=value.toLowerCase(); + String lvalue=value.toLowerCase(Locale.ENGLISH); if ("nonContextServlets".equals(param)) { _nonContextServlets=value.length()>0 && lvalue.startsWith("t"); diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java index d3cc37bde38..13f9564c5f5 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java @@ -24,6 +24,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Enumeration; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -138,7 +139,7 @@ public class CGI extends HttpServlet if (!_env.envMap.containsKey("SystemRoot")) { String os = System.getProperty("os.name"); - if (os != null && os.toLowerCase().indexOf("windows") != -1) + if (os != null && os.toLowerCase(Locale.ENGLISH).indexOf("windows") != -1) { _env.set("SystemRoot","C:\\WINDOWS"); } @@ -255,7 +256,7 @@ public class CGI extends HttpServlet { String name = (String)enm.nextElement(); String value = req.getHeader(name); - env.set("HTTP_" + name.toUpperCase().replace('-','_'),value); + env.set("HTTP_" + name.toUpperCase(Locale.ENGLISH).replace('-','_'),value); } // these extra ones were from printenv on www.dev.nomura.co.uk diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java index 81a05fcbf80..5e2b16771de 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.servlets; import java.io.IOException; import java.util.HashSet; +import java.util.Locale; import java.util.Set; import java.util.StringTokenizer; import java.util.regex.Pattern; @@ -277,7 +278,7 @@ public class GzipFilter extends UserAgentFilter { for (int i=0; i< encodings.length; i++) { - if (encodings[i].toLowerCase().contains(GZIP)) + if (encodings[i].toLowerCase(Locale.ENGLISH).contains(GZIP)) { if (isEncodingAcceptable(encodings[i])) { @@ -286,7 +287,7 @@ public class GzipFilter extends UserAgentFilter } } - if (encodings[i].toLowerCase().contains(DEFLATE)) + if (encodings[i].toLowerCase(Locale.ENGLISH).contains(DEFLATE)) { if (isEncodingAcceptable(encodings[i])) { diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java index 13a749ca83d..081457e7adc 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java @@ -31,6 +31,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import javax.servlet.Filter; import javax.servlet.FilterChain; diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java index 24b8718a14d..ae2c7baa8ae 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java @@ -26,6 +26,7 @@ import java.net.URL; import java.util.Arrays; import java.util.EnumSet; import java.util.HashSet; +import java.util.Locale; import java.util.Set; import javax.servlet.DispatcherType; import javax.servlet.http.HttpServletResponse; @@ -62,7 +63,7 @@ public class PutFilterTest FilterHolder holder = tester.addFilter(PutFilter.class,"/*",EnumSet.of(DispatcherType.REQUEST)); holder.setInitParameter("delAllowed","true"); // Bloody Windows does not allow file renaming - if (!System.getProperty("os.name").toLowerCase().contains("windows")) + if (!System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")) holder.setInitParameter("putAtomic","true"); tester.start(); } diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersBlockGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersBlockGenerator.java index 30c3e50a8dc..6ae94e121dc 100644 --- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersBlockGenerator.java +++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersBlockGenerator.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.spdy.generator; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; import java.nio.charset.Charset; +import java.util.Locale; import org.eclipse.jetty.spdy.CompressionDictionary; import org.eclipse.jetty.spdy.CompressionFactory; @@ -45,7 +46,7 @@ public class HeadersBlockGenerator writeCount(version, buffer, headers.size()); for (Fields.Field header : headers) { - String name = header.name().toLowerCase(); + String name = header.name().toLowerCase(Locale.ENGLISH); byte[] nameBytes = name.getBytes(iso1); writeNameLength(version, buffer, nameBytes.length); buffer.write(nameBytes, 0, nameBytes.length); diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/ReferrerPushStrategy.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/ReferrerPushStrategy.java index 9f8bdb55a06..13dbe6eb0b6 100644 --- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/ReferrerPushStrategy.java +++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/ReferrerPushStrategy.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -206,7 +207,7 @@ public class ReferrerPushStrategy implements PushStrategy if (header == null) return true; - String contentType = header.value().toLowerCase(); + String contentType = header.value().toLowerCase(Locale.ENGLISH); for (String pushContentType : pushContentTypes) if (contentType.startsWith(pushContentType)) return true; diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java index 10bd415cd1c..585e5f51e9d 100644 --- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java +++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.spdy.server.proxy; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.Locale; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -92,7 +93,7 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse @Override public boolean parsedHeader(HttpHeader header, String headerName, String headerValue) { - switch (headerName.toLowerCase()) + switch (headerName.toLowerCase(Locale.ENGLISH)) { case "host": headers.put(HTTPSPDYHeader.HOST.name(version), headerValue); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java index 0235a760cfc..f6249ccaf61 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java @@ -38,6 +38,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -269,7 +270,7 @@ public class Config } else { - String name = entry.getName().toLowerCase(); + String name = entry.getName().toLowerCase(Locale.ENGLISH); if (name.endsWith(".jar") || name.endsWith(".zip")) { String jar = entry.getCanonicalPath(); @@ -796,7 +797,7 @@ public class Config } // Add XML configuration - if (subject.toLowerCase().endsWith(".xml")) + if (subject.toLowerCase(Locale.ENGLISH).endsWith(".xml")) { // Config file File f = new File(fixPath(file)); @@ -807,7 +808,7 @@ public class Config } // Set the main class to execute (overrides any previously set) - if (subject.toLowerCase().endsWith(".class")) + if (subject.toLowerCase(Locale.ENGLISH).endsWith(".class")) { // Class String cn = expand(subject.substring(0,subject.length() - 6)); @@ -820,7 +821,7 @@ public class Config } // Add raw classpath entry - if (subject.toLowerCase().endsWith(".path")) + if (subject.toLowerCase(Locale.ENGLISH).endsWith(".path")) { // classpath (jetty.class.path?) to add to runtime classpath String cn = expand(subject.substring(0,subject.length() - 5)); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index a13e53c11da..3a9e1d93c30 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -46,6 +46,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Properties; import java.util.Set; @@ -365,7 +366,7 @@ public class Main return false; } - String name = path.getName().toLowerCase(); + String name = path.getName().toLowerCase(Locale.ENGLISH); return (name.startsWith("jetty") && name.endsWith(".xml")); } }); @@ -639,7 +640,7 @@ public class Main private String resolveXmlConfig(String xmlFilename) throws FileNotFoundException { - if (!xmlFilename.toLowerCase().endsWith(".xml")) + if (!xmlFilename.toLowerCase(Locale.ENGLISH).endsWith(".xml")) { // Nothing to resolve. return xmlFilename; @@ -853,7 +854,7 @@ public class Main if (element.isFile()) { - String name = element.getName().toLowerCase(); + String name = element.getName().toLowerCase(Locale.ENGLISH); if (name.endsWith(".jar")) { return JarVersion.getVersion(element); @@ -1105,7 +1106,7 @@ public class Main @Override public boolean accept(File dir, String name) { - return name.toLowerCase().endsWith(".ini"); + return name.toLowerCase(Locale.ENGLISH).endsWith(".ini"); } }); Arrays.sort(inis); diff --git a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONObjectConvertor.java b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONObjectConvertor.java index 70e73e97786..f2e823deab9 100755 --- a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONObjectConvertor.java +++ b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONObjectConvertor.java @@ -22,6 +22,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.HashSet; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -89,9 +90,9 @@ public class JSONObjectConvertor implements JSON.Convertor { String name=m.getName(); if (name.startsWith("is")) - name=name.substring(2,3).toLowerCase()+name.substring(3); + name=name.substring(2,3).toLowerCase(Locale.ENGLISH)+name.substring(3); else if (name.startsWith("get")) - name=name.substring(3,4).toLowerCase()+name.substring(4); + name=name.substring(3,4).toLowerCase(Locale.ENGLISH)+name.substring(4); else continue; diff --git a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java index d49d4cfe8ec..b0196fc49b5 100644 --- a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java +++ b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java @@ -26,6 +26,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -122,9 +123,9 @@ public class JSONPojoConvertor implements JSON.Convertor if(m.getReturnType()!=null) { if (name.startsWith("is") && name.length()>2) - name=name.substring(2,3).toLowerCase()+name.substring(3); + name=name.substring(2,3).toLowerCase(Locale.ENGLISH)+name.substring(3); else if (name.startsWith("get") && name.length()>3) - name=name.substring(3,4).toLowerCase()+name.substring(4); + name=name.substring(3,4).toLowerCase(Locale.ENGLISH)+name.substring(4); else break; if(includeField(name, m)) @@ -134,7 +135,7 @@ public class JSONPojoConvertor implements JSON.Convertor case 1: if (name.startsWith("set") && name.length()>3) { - name=name.substring(3,4).toLowerCase()+name.substring(4); + name=name.substring(3,4).toLowerCase(Locale.ENGLISH)+name.substring(4); if(includeField(name, m)) addSetter(name, m); } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Fields.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Fields.java index 83b258b8c9f..18a2d30082c 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/Fields.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Fields.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -93,7 +94,7 @@ public class Fields implements Iterable */ public Field get(String name) { - return fields.get(name.trim().toLowerCase()); + return fields.get(name.trim().toLowerCase(Locale.ENGLISH)); } /** @@ -107,7 +108,7 @@ public class Fields implements Iterable name = name.trim(); // Preserve the case for the field name Field field = new Field(name, value); - fields.put(name.toLowerCase(), field); + fields.put(name.toLowerCase(Locale.ENGLISH), field); } /** @@ -118,7 +119,7 @@ public class Fields implements Iterable public void put(Field field) { if (field != null) - fields.put(field.name().toLowerCase(), field); + fields.put(field.name().toLowerCase(Locale.ENGLISH), field); } /** @@ -131,16 +132,16 @@ public class Fields implements Iterable public void add(String name, String value) { name = name.trim(); - Field field = fields.get(name.toLowerCase()); + Field field = fields.get(name.toLowerCase(Locale.ENGLISH)); if (field == null) { field = new Field(name, value); - fields.put(name.toLowerCase(), field); + fields.put(name.toLowerCase(Locale.ENGLISH), field); } else { field = new Field(field.name(), field.values(), value); - fields.put(name.toLowerCase(), field); + fields.put(name.toLowerCase(Locale.ENGLISH), field); } } @@ -153,7 +154,7 @@ public class Fields implements Iterable public Field remove(String name) { name = name.trim(); - return fields.remove(name.toLowerCase()); + return fields.remove(name.toLowerCase(Locale.ENGLISH)); } /** @@ -234,7 +235,7 @@ public class Fields implements Iterable @Override public int hashCode() { - int result = name.toLowerCase().hashCode(); + int result = name.toLowerCase(Locale.ENGLISH).hashCode(); result = 31 * result + Arrays.hashCode(values); return result; } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStream.java b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStream.java index d070687b86a..2d3d004ceb2 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStream.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStream.java @@ -34,6 +34,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Locale; import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; @@ -176,7 +177,7 @@ public class MultiPartInputStream { if (name == null) return null; - return (String)_headers.getValue(name.toLowerCase(), 0); + return (String)_headers.getValue(name.toLowerCase(Locale.ENGLISH), 0); } /** @@ -500,7 +501,7 @@ public class MultiPartInputStream int c=line.indexOf(':',0); if(c>0) { - String key=line.substring(0,c).trim().toLowerCase(); + String key=line.substring(0,c).trim().toLowerCase(Locale.ENGLISH); String value=line.substring(c+1,line.length()).trim(); headers.put(key, value); if (key.equalsIgnoreCase("content-disposition")) @@ -526,7 +527,7 @@ public class MultiPartInputStream while(tok.hasMoreTokens()) { String t=tok.nextToken().trim(); - String tl=t.toLowerCase(); + String tl=t.toLowerCase(Locale.ENGLISH); if(t.startsWith("form-data")) form_data=true; else if(tl.startsWith("name=")) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java b/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java index a4d7ee7a13e..fffada8bd33 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java @@ -27,6 +27,7 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.Locale; import java.util.TimeZone; import java.util.Timer; import java.util.TimerTask; @@ -221,7 +222,7 @@ public class RolloverFileOutputStream extends FilterOutputStream // Is this a rollover file? String filename=file.getName(); - int i=filename.toLowerCase().indexOf(YYYY_MM_DD); + int i=filename.toLowerCase(Locale.ENGLISH).indexOf(YYYY_MM_DD); if (i>=0) { file=new File(dir, @@ -258,7 +259,7 @@ public class RolloverFileOutputStream extends FilterOutputStream File file= new File(_filename); File dir = new File(file.getParent()); String fn=file.getName(); - int s=fn.toLowerCase().indexOf(YYYY_MM_DD); + int s=fn.toLowerCase(Locale.ENGLISH).indexOf(YYYY_MM_DD); if (s<0) return; String prefix=fn.substring(0,s); diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JarScanner.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JarScanner.java index 4528e162923..0dfa1eefb9e 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JarScanner.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JarScanner.java @@ -23,6 +23,7 @@ import java.io.InputStream; import java.net.URI; import java.net.URL; import java.net.URLClassLoader; +import java.util.Locale; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; import java.util.regex.Pattern; @@ -144,7 +145,7 @@ public abstract class JarScanner extends org.eclipse.jetty.util.PatternMatcher throws Exception { LOG.debug("Search of {}",uri); - if (uri.toString().toLowerCase().endsWith(".jar")) + if (uri.toString().toLowerCase(Locale.ENGLISH).endsWith(".jar")) { InputStream in = Resource.newResource(uri).getInputStream(); diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java index cd55f50d43e..64f2dbab87a 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java @@ -22,6 +22,7 @@ package org.eclipse.jetty.webapp; import java.net.URI; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.jar.JarEntry; import org.eclipse.jetty.util.log.Log; @@ -136,7 +137,7 @@ public class MetaInfConfiguration extends AbstractConfiguration } else { - String lcname = name.toLowerCase(); + String lcname = name.toLowerCase(Locale.ENGLISH); if (lcname.endsWith(".tld")) { addResource(context,METAINF_TLDS,Resource.newResource("jar:"+jarUri+"!/"+name)); diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java index 11d0a72565c..ef8681f5751 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java @@ -25,6 +25,7 @@ import java.util.EventListener; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import javax.servlet.DispatcherType; @@ -324,7 +325,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor XmlParser.Node startup = node.get("load-on-startup"); if (startup != null) { - String s = startup.toString(false, true).toLowerCase(); + String s = startup.toString(false, true).toLowerCase(Locale.ENGLISH); int order = 0; if (s.startsWith("t")) { @@ -1387,7 +1388,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor if (data != null) { data = data.get("transport-guarantee"); - String guarantee = data.toString(false, true).toUpperCase(); + String guarantee = data.toString(false, true).toUpperCase(Locale.ENGLISH); if (guarantee == null || guarantee.length() == 0 || "NONE".equals(guarantee)) scBase.setDataConstraint(Constraint.DC_NONE); else if ("INTEGRAL".equals(guarantee)) diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/TagLibConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/TagLibConfiguration.java index 72075ddbe10..c1f7f9a8e78 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/TagLibConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/TagLibConfiguration.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import javax.servlet.Servlet; @@ -216,7 +217,7 @@ public class TagLibConfiguration extends AbstractConfiguration while(iter.hasNext()) { String location = iter.next(); - if (location!=null && location.toLowerCase().endsWith(".tld")) + if (location!=null && location.toLowerCase(Locale.ENGLISH).endsWith(".tld")) { if (!location.startsWith("/")) location="/WEB-INF/"+location; @@ -233,7 +234,7 @@ public class TagLibConfiguration extends AbstractConfiguration String[] contents = web_inf.list(); for (int i=0;contents!=null && i + *
  • Eclipse Jetty Bug #393075
  • + *
  • Apache Tomcat Bug #54067
  • + * + * @throws IOException + */ + @Test + @Ignore("Bug with Transfer-Encoding") + public void testTomcat7_0_32_WithTransferEncoding() throws Exception { + DummyServer server = new DummyServer(); + int bufferSize = 512; + QueuedThreadPool threadPool = new QueuedThreadPool(); + WebSocketClientFactory factory = new WebSocketClientFactory(threadPool, new ZeroMaskGen(), bufferSize); + + try { + server.start(); + + // Setup Client Factory + threadPool.start(); + factory.start(); + + // Create Client + WebSocketClient client = new WebSocketClient(factory); + + // Create End User WebSocket Class + final CountDownLatch openLatch = new CountDownLatch(1); + final CountDownLatch dataLatch = new CountDownLatch(1); + WebSocket.OnTextMessage websocket = new WebSocket.OnTextMessage() + { + public void onOpen(Connection connection) + { + openLatch.countDown(); + } + + public void onMessage(String data) + { + // System.out.println("data = " + data); + dataLatch.countDown(); + } + + public void onClose(int closeCode, String message) + { + } + }; + + // Open connection + URI wsURI = server.getWsUri(); + client.open(wsURI, websocket); + + // Accept incoming connection + ServerConnection socket = server.accept(); + socket.setSoTimeout(2000); // timeout + + // Issue upgrade + Map extraResponseHeaders = new HashMap(); + extraResponseHeaders.put("Transfer-Encoding", "chunked"); // !! The problem !! + socket.upgrade(extraResponseHeaders); + + // Wait for proper upgrade + Assert.assertTrue("Timed out waiting for Client side WebSocket open event", openLatch.await(1, TimeUnit.SECONDS)); + + // Have server write frame. + int length = bufferSize / 2; + ByteBuffer serverFrame = ByteBuffer.allocate(bufferSize); + serverFrame.put((byte)(0x80 | 0x01)); // FIN + TEXT + serverFrame.put((byte)0x7E); // No MASK and 2 bytes length + serverFrame.put((byte)(length >> 8)); // first length byte + serverFrame.put((byte)(length & 0xFF)); // second length byte + for (int i = 0; i < length; ++i) + serverFrame.put((byte)'x'); + serverFrame.flip(); + byte buf[] = serverFrame.array(); + socket.write(buf,0,buf.length); + socket.flush(); + + Assert.assertTrue(dataLatch.await(1000, TimeUnit.SECONDS)); + } finally { + factory.stop(); + threadPool.stop(); + server.stop(); + } + } +} diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/dummy/DummyServer.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/dummy/DummyServer.java new file mode 100644 index 00000000000..9b41e51e2fa --- /dev/null +++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/dummy/DummyServer.java @@ -0,0 +1,308 @@ +// +// ======================================================================== +// Copyright (c) 1995-2012 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.websocket.dummy; + +import static org.hamcrest.Matchers.*; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.net.URI; +import java.nio.ByteBuffer; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.WebSocketConnectionRFC6455; +import org.junit.Assert; + +/** + * Simple ServerSocket server used to test oddball server scenarios encountered in the real world. + */ +public class DummyServer +{ + public static class ServerConnection + { + private static final Logger LOG = Log.getLogger(ServerConnection.class); + private final Socket socket; + private InputStream in; + private OutputStream out; + + public ServerConnection(Socket socket) + { + this.socket = socket; + } + + public int read(ByteBuffer buf) throws IOException + { + int len = 0; + while ((in.available() > 0) && (buf.remaining() > 0)) + { + buf.put((byte)in.read()); + len++; + } + return len; + } + + public void disconnect() + { + LOG.debug("disconnect"); + IO.close(in); + IO.close(out); + if (socket != null) + { + try + { + socket.close(); + } + catch (IOException ignore) + { + /* ignore */ + } + } + } + + public InputStream getInputStream() throws IOException + { + if (in == null) + { + in = socket.getInputStream(); + } + return in; + } + + public OutputStream getOutputStream() throws IOException + { + if (out == null) + { + out = socket.getOutputStream(); + } + return out; + } + + public void flush() throws IOException + { + LOG.debug("flush()"); + getOutputStream().flush(); + } + + public String readRequest() throws IOException + { + LOG.debug("Reading client request"); + StringBuilder request = new StringBuilder(); + BufferedReader in = new BufferedReader(new InputStreamReader(getInputStream())); + for (String line = in.readLine(); line != null; line = in.readLine()) + { + if (line.length() == 0) + { + break; + } + request.append(line).append("\r\n"); + LOG.debug("read line: {}",line); + } + + LOG.debug("Client Request:{}{}","\n",request); + return request.toString(); + } + + public void respond(String rawstr) throws IOException + { + LOG.debug("respond(){}{}","\n",rawstr); + getOutputStream().write(rawstr.getBytes()); + flush(); + } + + public void setSoTimeout(int ms) throws SocketException + { + socket.setSoTimeout(ms); + } + + public void upgrade(Map extraResponseHeaders) throws IOException + { + @SuppressWarnings("unused") + Pattern patExts = Pattern.compile("^Sec-WebSocket-Extensions: (.*)$",Pattern.CASE_INSENSITIVE); + Pattern patKey = Pattern.compile("^Sec-WebSocket-Key: (.*)$",Pattern.CASE_INSENSITIVE); + + LOG.debug("(Upgrade) Reading HTTP Request"); + Matcher mat; + String key = "not sent"; + BufferedReader in = new BufferedReader(new InputStreamReader(getInputStream())); + for (String line = in.readLine(); line != null; line = in.readLine()) + { + if (line.length() == 0) + { + break; + } + + // TODO: Check for extensions + // mat = patExts.matcher(line); + // if (mat.matches()) + + // Check for Key + mat = patKey.matcher(line); + if (mat.matches()) + { + key = mat.group(1); + } + } + + LOG.debug("(Upgrade) Writing HTTP Response"); + // TODO: handle extensions? + + // Setup Response + StringBuilder resp = new StringBuilder(); + resp.append("HTTP/1.1 101 Upgrade\r\n"); + resp.append("Upgrade: websocket\r\n"); + resp.append("Connection: upgrade\r\n"); + resp.append("Sec-WebSocket-Accept: "); + resp.append(WebSocketConnectionRFC6455.hashKey(key)).append("\r\n"); + // extra response headers. + if (extraResponseHeaders != null) + { + for (Map.Entry header : extraResponseHeaders.entrySet()) + { + resp.append(header.getKey()); + resp.append(": "); + resp.append(header.getValue()); + resp.append("\r\n"); + } + } + resp.append("\r\n"); + + // Write Response + getOutputStream().write(resp.toString().getBytes()); + flush(); + } + + public void write(byte[] bytes) throws IOException + { + LOG.debug("Writing {} bytes", bytes.length); + getOutputStream().write(bytes); + } + + public void write(byte[] buf, int offset, int length) throws IOException + { + LOG.debug("Writing bytes[{}], offset={}, length={}", buf.length, offset, length); + getOutputStream().write(buf,offset,length); + } + + public void write(int b) throws IOException + { + LOG.debug("Writing int={}", b); + getOutputStream().write(b); + } + } + + private static final Logger LOG = Log.getLogger(DummyServer.class); + private ServerSocket serverSocket; + private URI wsUri; + + public ServerConnection accept() throws IOException + { + LOG.debug(".accept()"); + assertIsStarted(); + Socket socket = serverSocket.accept(); + return new ServerConnection(socket); + } + + private void assertIsStarted() + { + Assert.assertThat("ServerSocket",serverSocket,notNullValue()); + Assert.assertThat("ServerSocket.isBound",serverSocket.isBound(),is(true)); + Assert.assertThat("ServerSocket.isClosed",serverSocket.isClosed(),is(false)); + + Assert.assertThat("WsUri",wsUri,notNullValue()); + } + + public URI getWsUri() + { + return wsUri; + } + + public void respondToClient(Socket connection, String serverResponse) throws IOException + { + InputStream in = null; + InputStreamReader isr = null; + BufferedReader buf = null; + OutputStream out = null; + try + { + in = connection.getInputStream(); + isr = new InputStreamReader(in); + buf = new BufferedReader(isr); + String line; + while ((line = buf.readLine()) != null) + { + // System.err.println(line); + if (line.length() == 0) + { + // Got the "\r\n" line. + break; + } + } + + // System.out.println("[Server-Out] " + serverResponse); + out = connection.getOutputStream(); + out.write(serverResponse.getBytes()); + out.flush(); + } + finally + { + IO.close(buf); + IO.close(isr); + IO.close(in); + IO.close(out); + } + } + + public void start() throws IOException + { + serverSocket = new ServerSocket(); + InetAddress addr = InetAddress.getByName("localhost"); + InetSocketAddress endpoint = new InetSocketAddress(addr,0); + serverSocket.bind(endpoint); + int port = serverSocket.getLocalPort(); + String uri = String.format("ws://%s:%d/",addr.getHostAddress(),port); + wsUri = URI.create(uri); + LOG.debug("Server Started on {} -> {}",endpoint,wsUri); + } + + public void stop() + { + LOG.debug("Stopping Server"); + try + { + serverSocket.close(); + } + catch (IOException ignore) + { + /* ignore */ + } + } + +} diff --git a/jetty-websocket/src/test/resources/jetty-logging.properties b/jetty-websocket/src/test/resources/jetty-logging.properties new file mode 100644 index 00000000000..78d8a9d8123 --- /dev/null +++ b/jetty-websocket/src/test/resources/jetty-logging.properties @@ -0,0 +1,4 @@ +# Setup default logging implementation for during testing +org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +org.eclipse.jetty.LEVEL=INFO +org.eclipse.jetty.websocket.LEVEL=DEBUG \ No newline at end of file diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ClientUpgradeRequest.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ClientUpgradeRequest.java index b8fe6e3a8d8..6f4961670b8 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ClientUpgradeRequest.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ClientUpgradeRequest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Random; import java.util.Set; @@ -188,7 +189,7 @@ public class ClientUpgradeRequest implements UpgradeRequest for (String key : headers.keySet()) { String value = headers.get(key); - if (FORBIDDEN_HEADERS.contains(key.toLowerCase())) + if (FORBIDDEN_HEADERS.contains(key.toLowerCase(Locale.ENGLISH))) { LOG.warn("Skipping forbidden header - {}: {}",key,value); continue; // skip diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ClientUpgradeResponse.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ClientUpgradeResponse.java index 0a3e4020a5a..9f81d18b57b 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ClientUpgradeResponse.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ClientUpgradeResponse.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Set; import org.eclipse.jetty.util.MultiMap; @@ -47,7 +48,7 @@ public class ClientUpgradeResponse implements UpgradeResponse @Override public void addHeader(String name, String value) { - headers.add(name.toLowerCase(),value); + headers.add(name.toLowerCase(Locale.ENGLISH),value); } @Override @@ -71,13 +72,13 @@ public class ClientUpgradeResponse implements UpgradeResponse @Override public String getHeaderValue(String name) { - return headers.getValue(name.toLowerCase(),0); + return headers.getValue(name.toLowerCase(Locale.ENGLISH),0); } @Override public Iterator getHeaderValues(String name) { - List values = headers.getValues(name.toLowerCase()); + List values = headers.getValues(name.toLowerCase(Locale.ENGLISH)); if (values == null) { return Collections.emptyIterator(); diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ConnectionManager.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ConnectionManager.java index 0cb7c902bca..4f818447336 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ConnectionManager.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/ConnectionManager.java @@ -25,6 +25,7 @@ import java.net.URI; import java.nio.channels.SocketChannel; import java.util.Collection; import java.util.Collections; +import java.util.Locale; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Executor; @@ -57,7 +58,7 @@ public class ConnectionManager extends ContainerLifeCycle } int port = uri.getPort(); - String scheme = uri.getScheme().toLowerCase(); + String scheme = uri.getScheme().toLowerCase(Locale.ENGLISH); if ("ws".equals(scheme)) { if (port == (-1)) diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/DefaultWebSocketClient.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/DefaultWebSocketClient.java index 6d44cd5805d..001e68ed140 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/DefaultWebSocketClient.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/internal/DefaultWebSocketClient.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.client.internal; import java.io.IOException; import java.net.URI; +import java.util.Locale; import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.StringUtil; @@ -99,7 +100,7 @@ public class DefaultWebSocketClient extends FutureCallback impl throw new IllegalArgumentException("WebSocket URI must include a scheme"); } - String scheme = websocketUri.getScheme().toLowerCase(); + String scheme = websocketUri.getScheme().toLowerCase(Locale.ENGLISH); if (("ws".equals(scheme) == false) && ("wss".equals(scheme) == false)) { throw new IllegalArgumentException("WebSocket URI scheme only supports [ws] and [wss], not [" + scheme + "]"); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/mux/MuxGeneratorWrite139SizeTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/mux/MuxGeneratorWrite139SizeTest.java index 281996167b1..a14abe23d7c 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/mux/MuxGeneratorWrite139SizeTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/mux/MuxGeneratorWrite139SizeTest.java @@ -24,6 +24,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Locale; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.TypeUtil; @@ -90,7 +91,7 @@ public class MuxGeneratorWrite139SizeTest generator.write139Size(bbuf,value); BufferUtil.flipToFlush(bbuf,0); byte actual[] = BufferUtil.toArray(bbuf); - String actualHex = TypeUtil.toHexString(actual).toUpperCase(); + String actualHex = TypeUtil.toHexString(actual).toUpperCase(Locale.ENGLISH); Assert.assertThat("1/3/9 encoded size of [" + value + "]",actualHex,is(expectedHex)); } } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/mux/MuxGeneratorWriteChannelIdTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/mux/MuxGeneratorWriteChannelIdTest.java index f6f10bd2f2b..724ea1f9b71 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/mux/MuxGeneratorWriteChannelIdTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/mux/MuxGeneratorWriteChannelIdTest.java @@ -24,6 +24,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Locale; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.TypeUtil; @@ -94,7 +95,7 @@ public class MuxGeneratorWriteChannelIdTest generator.writeChannelId(bbuf,channelId); BufferUtil.flipToFlush(bbuf,0); byte actual[] = BufferUtil.toArray(bbuf); - String actualHex = TypeUtil.toHexString(actual).toUpperCase(); + String actualHex = TypeUtil.toHexString(actual).toUpperCase(Locale.ENGLISH); Assert.assertThat("Channel ID [" + channelId + "]",actualHex,is(expectedHex)); } } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/protocol/OutgoingNetworkBytesCapture.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/protocol/OutgoingNetworkBytesCapture.java index 2ce24d94682..0ed4af371c8 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/protocol/OutgoingNetworkBytesCapture.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/protocol/OutgoingNetworkBytesCapture.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; @@ -49,8 +50,8 @@ public class OutgoingNetworkBytesCapture implements OutgoingFrames { Assert.assertThat("Capture index does not exist",idx,lessThan(captured.size())); ByteBuffer buf = captured.get(idx); - String actualHex = TypeUtil.toHexString(BufferUtil.toArray(buf)).toUpperCase(); - Assert.assertThat("captured[" + idx + "]",actualHex,is(expectedHex.toUpperCase())); + String actualHex = TypeUtil.toHexString(BufferUtil.toArray(buf)).toUpperCase(Locale.ENGLISH); + Assert.assertThat("captured[" + idx + "]",actualHex,is(expectedHex.toUpperCase(Locale.ENGLISH))); } public List getCaptured() diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/Fuzzer.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/Fuzzer.java index 6f727834596..7c45d6ba87a 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/Fuzzer.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/Fuzzer.java @@ -25,6 +25,7 @@ import java.net.SocketException; import java.nio.ByteBuffer; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -280,7 +281,7 @@ public class Fuzzer // early socket close can propagate back to the client // before it has a chance to finish writing out the // remaining frame octets - Assert.assertThat("Allowed to be a broken pipe",ignore.getMessage().toLowerCase(),containsString("broken pipe")); + Assert.assertThat("Allowed to be a broken pipe",ignore.getMessage().toLowerCase(Locale.ENGLISH),containsString("broken pipe")); } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserSocket.java index c03b63c60b0..6ed2c25fc77 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserSocket.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.Locale; import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.StringUtil; @@ -68,7 +69,7 @@ public class BrowserSocket int idx = message.indexOf(':'); if (idx > 0) { - String key = message.substring(0,idx).toLowerCase(); + String key = message.substring(0,idx).toLowerCase(Locale.ENGLISH); String val = message.substring(idx + 1); switch (key) { diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index 78776b2a987..58521cc8956 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -40,6 +40,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Queue; @@ -420,7 +421,7 @@ public class XmlConfiguration private void set(Object obj, XmlParser.Node node) throws Exception { String attr = node.getAttribute("name"); - String name = "set" + attr.substring(0,1).toUpperCase() + attr.substring(1); + String name = "set" + attr.substring(0,1).toUpperCase(Locale.ENGLISH) + attr.substring(1); Object value = value(obj,node); Object[] arg = { value }; @@ -623,7 +624,7 @@ public class XmlConfiguration try { // try calling a getXxx method. - Method method = oClass.getMethod("get" + name.substring(0,1).toUpperCase() + name.substring(1),(java.lang.Class[])null); + Method method = oClass.getMethod("get" + name.substring(0,1).toUpperCase(Locale.ENGLISH) + name.substring(1),(java.lang.Class[])null); obj = method.invoke(obj,(java.lang.Object[])null); configure(obj,node,0); } @@ -1172,7 +1173,7 @@ public class XmlConfiguration Object[] obj = new Object[args.length]; for (int i = 0; i < args.length; i++) { - if (args[i].toLowerCase().endsWith(".properties")) + if (args[i].toLowerCase(Locale.ENGLISH).endsWith(".properties")) { properties.load(Resource.newResource(args[i]).getInputStream()); } diff --git a/test-jetty-webapp/src/main/java/com/acme/Dump.java b/test-jetty-webapp/src/main/java/com/acme/Dump.java index 01f9b16cffd..1b953d087b3 100644 --- a/test-jetty-webapp/src/main/java/com/acme/Dump.java +++ b/test-jetty-webapp/src/main/java/com/acme/Dump.java @@ -129,7 +129,7 @@ public class Dump extends HttpServlet final boolean flush= request.getParameter("flush")!=null?Boolean.parseBoolean(request.getParameter("flush")):false; - if(request.getPathInfo()!=null && request.getPathInfo().toLowerCase().indexOf("script")!=-1) + if(request.getPathInfo()!=null && request.getPathInfo().toLowerCase(Locale.ENGLISH).indexOf("script")!=-1) { response.sendRedirect(response.encodeRedirectURL(getServletContext().getContextPath() + "/dump/info")); return;