diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ShutdownHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ShutdownHandler.java index aa4edeb7f61..08135e61246 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ShutdownHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ShutdownHandler.java @@ -144,7 +144,9 @@ public class ShutdownHandler extends AbstractHandler private boolean hasCorrectSecurityToken(HttpServletRequest request) { - return _shutdownToken.equals(request.getParameter("token")); + String tok = request.getParameter("token"); + LOG.debug("Token: {}", tok); + return _shutdownToken.equals(tok); } private void shutdownServer() throws Exception diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java index ceb2250bc62..b756d9f77c0 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java @@ -217,7 +217,7 @@ public class HttpURITest try { HttpURI huri=new HttpURI(uri); - MultiMap params = new MultiMap(); + MultiMap params = new MultiMap<>(); huri.decodeQueryTo(params); System.err.println(params); Assert.assertTrue(false); @@ -229,7 +229,7 @@ public class HttpURITest try { HttpURI huri=new HttpURI(uri); - MultiMap params = new MultiMap(); + MultiMap params = new MultiMap<>(); huri.decodeQueryTo(params,"UTF-8"); System.err.println(params); Assert.assertTrue(false); @@ -247,9 +247,9 @@ public class HttpURITest { HttpURI uri = new HttpURI("/path?value="+URLEncoder.encode(value,"UTF-8")); - MultiMap parameters = new MultiMap(); + MultiMap parameters = new MultiMap<>(); uri.decodeQueryTo(parameters,"UTF-8"); - assertEquals(value,parameters.get("value")); + assertEquals(value,parameters.getString("value")); } } diff --git a/jetty-server/src/test/resources/jetty-logging.properties b/jetty-server/src/test/resources/jetty-logging.properties index 9e08d435daa..e5c7ca9cd9b 100644 --- a/jetty-server/src/test/resources/jetty-logging.properties +++ b/jetty-server/src/test/resources/jetty-logging.properties @@ -1,2 +1,2 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -#org.eclipse.jetty.LEVEL=WARN +# org.eclipse.jetty.LEVEL=WARN diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java index 1dbd5d1bc2b..10e95c41cb7 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java @@ -18,7 +18,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringWriter; import java.io.UnsupportedEncodingException; -import java.util.Iterator; +import java.util.List; import java.util.Map; import org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception; @@ -44,7 +44,8 @@ import org.eclipse.jetty.util.log.Logger; * * @see java.net.URLEncoder */ -public class UrlEncoded extends MultiMap implements Cloneable +@SuppressWarnings("serial") +public class UrlEncoded extends MultiMap implements Cloneable { static final Logger LOG = Log.getLogger(UrlEncoded.class); @@ -118,21 +119,24 @@ public class UrlEncoded extends MultiMap implements Cloneable * @param equalsForNullValue if True, then an '=' is always used, even * for parameters without a value. e.g. "blah?a=&b=&c=". */ - public static String encode(MultiMap map, String charset, boolean equalsForNullValue) + public static String encode(MultiMap map, String charset, boolean equalsForNullValue) { if (charset==null) charset=ENCODING; StringBuilder result = new StringBuilder(128); - Iterator> iter = map.entrySet().iterator(); - while(iter.hasNext()) + boolean delim = false; + for(Map.Entry> entry: map.entrySet()) { - Map.Entry entry = iter.next(); - String key = entry.getKey().toString(); - Object list = entry.getValue(); - int s=LazyList.size(list); + List list = entry.getValue(); + int s=list.size(); + + if (delim) + { + result.append('&'); + } if (s==0) { @@ -146,7 +150,7 @@ public class UrlEncoded extends MultiMap implements Cloneable { if (i>0) result.append('&'); - Object val=LazyList.get(list,i); + String val=list.get(i); result.append(encodeString(key,charset)); if (val!=null) @@ -164,8 +168,7 @@ public class UrlEncoded extends MultiMap implements Cloneable result.append('='); } } - if (iter.hasNext()) - result.append('&'); + delim = true; } return result.toString(); } @@ -176,7 +179,7 @@ public class UrlEncoded extends MultiMap implements Cloneable /** Decoded parameters to Map. * @param content the string containing the encoded parameters */ - public static void decodeTo(String content, MultiMap map, String charset) + public static void decodeTo(String content, MultiMap map, String charset) { decodeTo(content,map,charset,-1); } @@ -185,7 +188,7 @@ public class UrlEncoded extends MultiMap implements Cloneable /** Decoded parameters to Map. * @param content the string containing the encoded parameters */ - public static void decodeTo(String content, MultiMap map, String charset, int maxKeys) + public static void decodeTo(String content, MultiMap map, String charset, int maxKeys) { if (charset==null) charset=ENCODING; @@ -266,7 +269,7 @@ public class UrlEncoded extends MultiMap implements Cloneable * @param map the {@link MultiMap} to populate * @param buffer the buffer to decode into */ - public static void decodeUtf8To(byte[] raw,int offset, int length, MultiMap map) + public static void decodeUtf8To(byte[] raw,int offset, int length, MultiMap map) { Utf8StringBuilder buffer = new Utf8StringBuilder(); synchronized(map) @@ -347,7 +350,7 @@ public class UrlEncoded extends MultiMap implements Cloneable * @param map MultiMap to add parameters to * @param maxLength maximum number of keys to read or -1 for no limit */ - public static void decode88591To(InputStream in, MultiMap map, int maxLength, int maxKeys) + public static void decode88591To(InputStream in, MultiMap map, int maxLength, int maxKeys) throws IOException { synchronized(map) @@ -431,7 +434,7 @@ public class UrlEncoded extends MultiMap implements Cloneable * @param map MultiMap to add parameters to * @param maxLength maximum number of keys to read or -1 for no limit */ - public static void decodeUtf8To(InputStream in, MultiMap map, int maxLength, int maxKeys) + public static void decodeUtf8To(InputStream in, MultiMap map, int maxLength, int maxKeys) throws IOException { synchronized(map) @@ -518,7 +521,7 @@ public class UrlEncoded extends MultiMap implements Cloneable } /* -------------------------------------------------------------- */ - public static void decodeUtf16To(InputStream in, MultiMap map, int maxLength, int maxKeys) throws IOException + public static void decodeUtf16To(InputStream in, MultiMap map, int maxLength, int maxKeys) throws IOException { InputStreamReader input = new InputStreamReader(in,StringUtil.__UTF16); StringWriter buf = new StringWriter(8192); @@ -531,7 +534,7 @@ public class UrlEncoded extends MultiMap implements Cloneable /** Decoded parameters to Map. * @param in the stream containing the encoded parameters */ - public static void decodeTo(InputStream in, MultiMap map, String charset, int maxLength, int maxKeys) + public static void decodeTo(InputStream in, MultiMap map, String charset, int maxLength, int maxKeys) throws IOException { //no charset present, use the configured default diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java index 20cce6143fc..b9dedb7e240 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; +import org.junit.Assert; import org.junit.Test; @@ -177,7 +178,7 @@ public class URLEncodedTest for (int i=0;i m = new MultiMap<>(); UrlEncoded.decodeTo(in, m, charsets[i][1], -1,-1); assertEquals(i+" stream length",4,m.size()); assertEquals(i+" stream name\\n","value 0",m.getString("name\n")); @@ -190,7 +191,7 @@ public class URLEncodedTest if (java.nio.charset.Charset.isSupported("Shift_JIS")) { ByteArrayInputStream in2 = new ByteArrayInputStream ("name=%83e%83X%83g".getBytes()); - MultiMap m2 = new MultiMap(); + MultiMap m2 = new MultiMap<>(); UrlEncoded.decodeTo(in2, m2, "Shift_JIS", -1,-1); assertEquals("stream length",1,m2.size()); assertEquals("stream name","\u30c6\u30b9\u30c8",m2.getString("name")); @@ -232,7 +233,7 @@ public class URLEncodedTest String hex ="E0B89FE0B8ABE0B881E0B8A7E0B894E0B8B2E0B988E0B881E0B89FE0B8A7E0B8ABE0B8AAE0B894E0B8B2E0B988E0B8ABE0B89FE0B881E0B8A7E0B894E0B8AAE0B8B2E0B89FE0B881E0B8ABE0B8A3E0B894E0B989E0B89FE0B8ABE0B899E0B881E0B8A3E0B894E0B8B5"; String expected = new String(TypeUtil.fromHexString(hex),"utf-8"); - assertEquals(expected,url_encoded.get("text")); + Assert.assertEquals(expected,url_encoded.getString("text")); } /* -------------------------------------------------------------- */ @@ -241,7 +242,7 @@ public class URLEncodedTest { String query="name=X%c0%afZ"; - MultiMap map = new MultiMap(); + MultiMap map = new MultiMap<>(); UrlEncoded.LOG.info("EXPECT 4 Not Valid UTF8 warnings..."); UrlEncoded.decodeUtf8To(query.getBytes(StringUtil.__ISO_8859_1),0,query.length(),map); assertEquals("X"+Utf8Appendable.REPLACEMENT+Utf8Appendable.REPLACEMENT+"Z",map.getValue("name",0));