[multimap-ng] moving UrlEncoded over and fixing various other failing tests
This commit is contained in:
parent
2ad81fc627
commit
b8de9a35a4
|
@ -144,7 +144,9 @@ public class ShutdownHandler extends AbstractHandler
|
||||||
|
|
||||||
private boolean hasCorrectSecurityToken(HttpServletRequest request)
|
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
|
private void shutdownServer() throws Exception
|
||||||
|
|
|
@ -217,7 +217,7 @@ public class HttpURITest
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpURI huri=new HttpURI(uri);
|
HttpURI huri=new HttpURI(uri);
|
||||||
MultiMap params = new MultiMap();
|
MultiMap<String> params = new MultiMap<>();
|
||||||
huri.decodeQueryTo(params);
|
huri.decodeQueryTo(params);
|
||||||
System.err.println(params);
|
System.err.println(params);
|
||||||
Assert.assertTrue(false);
|
Assert.assertTrue(false);
|
||||||
|
@ -229,7 +229,7 @@ public class HttpURITest
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpURI huri=new HttpURI(uri);
|
HttpURI huri=new HttpURI(uri);
|
||||||
MultiMap params = new MultiMap();
|
MultiMap<String> params = new MultiMap<>();
|
||||||
huri.decodeQueryTo(params,"UTF-8");
|
huri.decodeQueryTo(params,"UTF-8");
|
||||||
System.err.println(params);
|
System.err.println(params);
|
||||||
Assert.assertTrue(false);
|
Assert.assertTrue(false);
|
||||||
|
@ -247,9 +247,9 @@ public class HttpURITest
|
||||||
{
|
{
|
||||||
HttpURI uri = new HttpURI("/path?value="+URLEncoder.encode(value,"UTF-8"));
|
HttpURI uri = new HttpURI("/path?value="+URLEncoder.encode(value,"UTF-8"));
|
||||||
|
|
||||||
MultiMap parameters = new MultiMap();
|
MultiMap<String> parameters = new MultiMap<>();
|
||||||
uri.decodeQueryTo(parameters,"UTF-8");
|
uri.decodeQueryTo(parameters,"UTF-8");
|
||||||
assertEquals(value,parameters.get("value"));
|
assertEquals(value,parameters.getString("value"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
|
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
|
||||||
#org.eclipse.jetty.LEVEL=WARN
|
# org.eclipse.jetty.LEVEL=WARN
|
||||||
|
|
|
@ -18,7 +18,7 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Iterator;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception;
|
import org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception;
|
||||||
|
@ -44,7 +44,8 @@ import org.eclipse.jetty.util.log.Logger;
|
||||||
*
|
*
|
||||||
* @see java.net.URLEncoder
|
* @see java.net.URLEncoder
|
||||||
*/
|
*/
|
||||||
public class UrlEncoded extends MultiMap implements Cloneable
|
@SuppressWarnings("serial")
|
||||||
|
public class UrlEncoded extends MultiMap<String> implements Cloneable
|
||||||
{
|
{
|
||||||
static final Logger LOG = Log.getLogger(UrlEncoded.class);
|
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
|
* @param equalsForNullValue if True, then an '=' is always used, even
|
||||||
* for parameters without a value. e.g. "blah?a=&b=&c=".
|
* 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<String> map, String charset, boolean equalsForNullValue)
|
||||||
{
|
{
|
||||||
if (charset==null)
|
if (charset==null)
|
||||||
charset=ENCODING;
|
charset=ENCODING;
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder(128);
|
StringBuilder result = new StringBuilder(128);
|
||||||
|
|
||||||
Iterator<Map.Entry<String, Object>> iter = map.entrySet().iterator();
|
boolean delim = false;
|
||||||
while(iter.hasNext())
|
for(Map.Entry<String, List<String>> entry: map.entrySet())
|
||||||
{
|
{
|
||||||
Map.Entry<String, Object> entry = iter.next();
|
|
||||||
|
|
||||||
String key = entry.getKey().toString();
|
String key = entry.getKey().toString();
|
||||||
Object list = entry.getValue();
|
List<String> list = entry.getValue();
|
||||||
int s=LazyList.size(list);
|
int s=list.size();
|
||||||
|
|
||||||
|
if (delim)
|
||||||
|
{
|
||||||
|
result.append('&');
|
||||||
|
}
|
||||||
|
|
||||||
if (s==0)
|
if (s==0)
|
||||||
{
|
{
|
||||||
|
@ -146,7 +150,7 @@ public class UrlEncoded extends MultiMap implements Cloneable
|
||||||
{
|
{
|
||||||
if (i>0)
|
if (i>0)
|
||||||
result.append('&');
|
result.append('&');
|
||||||
Object val=LazyList.get(list,i);
|
String val=list.get(i);
|
||||||
result.append(encodeString(key,charset));
|
result.append(encodeString(key,charset));
|
||||||
|
|
||||||
if (val!=null)
|
if (val!=null)
|
||||||
|
@ -164,8 +168,7 @@ public class UrlEncoded extends MultiMap implements Cloneable
|
||||||
result.append('=');
|
result.append('=');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (iter.hasNext())
|
delim = true;
|
||||||
result.append('&');
|
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
@ -176,7 +179,7 @@ public class UrlEncoded extends MultiMap implements Cloneable
|
||||||
/** Decoded parameters to Map.
|
/** Decoded parameters to Map.
|
||||||
* @param content the string containing the encoded parameters
|
* @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<String> map, String charset)
|
||||||
{
|
{
|
||||||
decodeTo(content,map,charset,-1);
|
decodeTo(content,map,charset,-1);
|
||||||
}
|
}
|
||||||
|
@ -185,7 +188,7 @@ public class UrlEncoded extends MultiMap implements Cloneable
|
||||||
/** Decoded parameters to Map.
|
/** Decoded parameters to Map.
|
||||||
* @param content the string containing the encoded parameters
|
* @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<String> map, String charset, int maxKeys)
|
||||||
{
|
{
|
||||||
if (charset==null)
|
if (charset==null)
|
||||||
charset=ENCODING;
|
charset=ENCODING;
|
||||||
|
@ -266,7 +269,7 @@ public class UrlEncoded extends MultiMap implements Cloneable
|
||||||
* @param map the {@link MultiMap} to populate
|
* @param map the {@link MultiMap} to populate
|
||||||
* @param buffer the buffer to decode into
|
* @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<String> map)
|
||||||
{
|
{
|
||||||
Utf8StringBuilder buffer = new Utf8StringBuilder();
|
Utf8StringBuilder buffer = new Utf8StringBuilder();
|
||||||
synchronized(map)
|
synchronized(map)
|
||||||
|
@ -347,7 +350,7 @@ public class UrlEncoded extends MultiMap implements Cloneable
|
||||||
* @param map MultiMap to add parameters to
|
* @param map MultiMap to add parameters to
|
||||||
* @param maxLength maximum number of keys to read or -1 for no limit
|
* @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<String> map, int maxLength, int maxKeys)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
synchronized(map)
|
synchronized(map)
|
||||||
|
@ -431,7 +434,7 @@ public class UrlEncoded extends MultiMap implements Cloneable
|
||||||
* @param map MultiMap to add parameters to
|
* @param map MultiMap to add parameters to
|
||||||
* @param maxLength maximum number of keys to read or -1 for no limit
|
* @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<String> map, int maxLength, int maxKeys)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
synchronized(map)
|
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<String> map, int maxLength, int maxKeys) throws IOException
|
||||||
{
|
{
|
||||||
InputStreamReader input = new InputStreamReader(in,StringUtil.__UTF16);
|
InputStreamReader input = new InputStreamReader(in,StringUtil.__UTF16);
|
||||||
StringWriter buf = new StringWriter(8192);
|
StringWriter buf = new StringWriter(8192);
|
||||||
|
@ -531,7 +534,7 @@ public class UrlEncoded extends MultiMap implements Cloneable
|
||||||
/** Decoded parameters to Map.
|
/** Decoded parameters to Map.
|
||||||
* @param in the stream containing the encoded parameters
|
* @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<String> map, String charset, int maxLength, int maxKeys)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
//no charset present, use the configured default
|
//no charset present, use the configured default
|
||||||
|
|
|
@ -18,6 +18,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,7 +178,7 @@ public class URLEncodedTest
|
||||||
for (int i=0;i<charsets.length;i++)
|
for (int i=0;i<charsets.length;i++)
|
||||||
{
|
{
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream("name\n=value+%30&name1=&name2&n\u00e3me3=value+3".getBytes(charsets[i][0]));
|
ByteArrayInputStream in = new ByteArrayInputStream("name\n=value+%30&name1=&name2&n\u00e3me3=value+3".getBytes(charsets[i][0]));
|
||||||
MultiMap m = new MultiMap();
|
MultiMap<String> m = new MultiMap<>();
|
||||||
UrlEncoded.decodeTo(in, m, charsets[i][1], -1,-1);
|
UrlEncoded.decodeTo(in, m, charsets[i][1], -1,-1);
|
||||||
assertEquals(i+" stream length",4,m.size());
|
assertEquals(i+" stream length",4,m.size());
|
||||||
assertEquals(i+" stream name\\n","value 0",m.getString("name\n"));
|
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"))
|
if (java.nio.charset.Charset.isSupported("Shift_JIS"))
|
||||||
{
|
{
|
||||||
ByteArrayInputStream in2 = new ByteArrayInputStream ("name=%83e%83X%83g".getBytes());
|
ByteArrayInputStream in2 = new ByteArrayInputStream ("name=%83e%83X%83g".getBytes());
|
||||||
MultiMap m2 = new MultiMap();
|
MultiMap<String> m2 = new MultiMap<>();
|
||||||
UrlEncoded.decodeTo(in2, m2, "Shift_JIS", -1,-1);
|
UrlEncoded.decodeTo(in2, m2, "Shift_JIS", -1,-1);
|
||||||
assertEquals("stream length",1,m2.size());
|
assertEquals("stream length",1,m2.size());
|
||||||
assertEquals("stream name","\u30c6\u30b9\u30c8",m2.getString("name"));
|
assertEquals("stream name","\u30c6\u30b9\u30c8",m2.getString("name"));
|
||||||
|
@ -232,7 +233,7 @@ public class URLEncodedTest
|
||||||
|
|
||||||
String hex ="E0B89FE0B8ABE0B881E0B8A7E0B894E0B8B2E0B988E0B881E0B89FE0B8A7E0B8ABE0B8AAE0B894E0B8B2E0B988E0B8ABE0B89FE0B881E0B8A7E0B894E0B8AAE0B8B2E0B89FE0B881E0B8ABE0B8A3E0B894E0B989E0B89FE0B8ABE0B899E0B881E0B8A3E0B894E0B8B5";
|
String hex ="E0B89FE0B8ABE0B881E0B8A7E0B894E0B8B2E0B988E0B881E0B89FE0B8A7E0B8ABE0B8AAE0B894E0B8B2E0B988E0B8ABE0B89FE0B881E0B8A7E0B894E0B8AAE0B8B2E0B89FE0B881E0B8ABE0B8A3E0B894E0B989E0B89FE0B8ABE0B899E0B881E0B8A3E0B894E0B8B5";
|
||||||
String expected = new String(TypeUtil.fromHexString(hex),"utf-8");
|
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";
|
String query="name=X%c0%afZ";
|
||||||
|
|
||||||
MultiMap map = new MultiMap();
|
MultiMap<String> map = new MultiMap<>();
|
||||||
UrlEncoded.LOG.info("EXPECT 4 Not Valid UTF8 warnings...");
|
UrlEncoded.LOG.info("EXPECT 4 Not Valid UTF8 warnings...");
|
||||||
UrlEncoded.decodeUtf8To(query.getBytes(StringUtil.__ISO_8859_1),0,query.length(),map);
|
UrlEncoded.decodeUtf8To(query.getBytes(StringUtil.__ISO_8859_1),0,query.length(),map);
|
||||||
assertEquals("X"+Utf8Appendable.REPLACEMENT+Utf8Appendable.REPLACEMENT+"Z",map.getValue("name",0));
|
assertEquals("X"+Utf8Appendable.REPLACEMENT+Utf8Appendable.REPLACEMENT+"Z",map.getValue("name",0));
|
||||||
|
|
Loading…
Reference in New Issue