Modified:
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/httpclient/WebClient.java
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/io/IOUtil.java
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/test/java/org/mycontainer/commons/json/JsonHandlerTest.java
/trunk/devel/implementation/mycontainer-components/mycontainer-servlet-commons/src/main/java/org/mycontainer/commons/servlet/ServletUtil.java
=======================================
---
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/httpclient/WebClient.java
Thu Apr 28 22:11:50 2011
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/httpclient/WebClient.java
Thu Jun 23 11:30:24 2011
@@ -42,7 +42,6 @@
client.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT,
30000);
-
// client.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
}
=======================================
---
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/io/IOUtil.java
Sun Jun 19 07:15:13 2011
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/io/IOUtil.java
Thu Jun 23 11:30:24 2011
@@ -158,7 +158,7 @@
return deserialize(serialized);
}
- private static Object deserialize(byte[] serialized) {
+ public static Object deserialize(byte[] serialized) {
try {
ObjectInputStream o = new ObjectInputStream(
new ByteArrayInputStream(serialized));
@@ -202,6 +202,13 @@
return out.toCharArray();
}
+
+ public static char[] readAll(Reader in) {
+ CharArrayWriter out = new CharArrayWriter();
+ copyAll(in, out);
+ out.close();
+ return out.toCharArray();
+ }
public static void copyAll(URL url, StringBuilder ret) {
Reader in = null;
=======================================
---
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/test/java/org/mycontainer/commons/json/JsonHandlerTest.java
Fri Apr 22 07:29:58 2011
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/test/java/org/mycontainer/commons/json/JsonHandlerTest.java
Thu Jun 23 11:30:24 2011
@@ -5,6 +5,9 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.util.HashMap;
+import java.util.Map;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -137,4 +140,16 @@
assertFalse(other == phone);
assertEquals("other", other.getNumber());
}
-}
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void parseMap() {
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("type", "FILE");
+ map.put("test", "value");
+ String json = handler.format(map);
+ assertEquals("{\"test\":\"value\",\"type\":\"FILE\"}", json);
+ Map<String, Object> parsed = handler.parse(json, map.getClass());
+ assertEquals(map, parsed);
+ }
+}
=======================================
---
/trunk/devel/implementation/mycontainer-components/mycontainer-servlet-commons/src/main/java/org/mycontainer/commons/servlet/ServletUtil.java
Fri Apr 22 08:27:59 2011
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-servlet-commons/src/main/java/org/mycontainer/commons/servlet/ServletUtil.java
Thu Jun 23 11:30:24 2011
@@ -1,10 +1,12 @@
package org.mycontainer.commons.servlet;
+import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
public class ServletUtil {
@@ -36,5 +38,35 @@
ret = ret.replaceAll(ignore, "");
return ret;
}
+
+ public static void checkMethods(HttpServletRequest request,
+ HttpServletResponse resp, String msg, String... alloweds) {
+ for (String allowed : alloweds) {
+ if (allowed.equals(request.getMethod())) {
+ return;
+ }
+ }
+ sendUnsupportedMethod(resp, msg, alloweds);
+ }
+
+ public static void sendUnsupportedMethod(HttpServletResponse resp,
+ String msg, String... alloweds) {
+ for (String allowed : alloweds) {
+ resp.addHeader("Allow", allowed);
+ }
+ sendError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
+ }
+
+ public static void sendError(HttpServletResponse resp, int code, String
msg) {
+ try {
+ if (msg == null) {
+ resp.sendError(code);
+ } else {
+ resp.sendError(code, msg);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
}