[mycontainer] r831 committed - [No log message]

0 views
Skip to first unread message

mycon...@googlecode.com

unread,
Jun 26, 2011, 6:57:47 AM6/26/11
to mycontain...@googlegroups.com
Revision: 831
Author: fuw...@gmail.com
Date: Sun Jun 26 03:57:15 2011
Log: [No log message]
http://code.google.com/p/mycontainer/source/detail?r=831

Added:

/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/util/CheckUtil.java
Modified:

/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/http/hook/BasicRequestService.java

/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/http/hook/Request.java

/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/http/hook/Response.java

/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/util/MapUtil.java

/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/test/java/org/mycontainer/commons/http/hook/BasicRequestServiceTest.java

/trunk/devel/implementation/mycontainer-components/mycontainer-servlet-commons/src/main/java/org/mycontainer/commons/servlet/http/hook/HookFilter.java

/trunk/devel/implementation/mycontainer-components/mycontainer-servlet-commons/src/test/java/org/mycontainer/commons/servlet/http/hook/HookFilterTest.java

=======================================
--- /dev/null
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/util/CheckUtil.java
Sun Jun 26 03:57:15 2011
@@ -0,0 +1,17 @@
+package org.mycontainer.commons.util;
+
+import java.util.Arrays;
+
+public class CheckUtil {
+
+ public static <T> T check(T check, T... values) {
+ for (T object : values) {
+ if (object.equals(check)) {
+ return object;
+ }
+ }
+ throw new RuntimeException("expected: " + Arrays.toString(values)
+ + ", but was: " + check);
+ }
+
+}
=======================================
---
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/http/hook/BasicRequestService.java
Sat Jun 25 12:08:32 2011
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/http/hook/BasicRequestService.java
Sun Jun 26 03:57:15 2011
@@ -8,7 +8,7 @@
private final List<Hook> hooks = new ArrayList<Hook>();

public void addHook(Hook hook) {
- this.hooks.add(hook);
+ this.hooks.add(0, hook);
}

public Response invoke(Request request) {
=======================================
---
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/http/hook/Request.java
Sat Jun 25 12:08:32 2011
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/http/hook/Request.java
Sun Jun 26 03:57:15 2011
@@ -4,6 +4,8 @@
import java.util.List;
import java.util.Map;

+import org.mycontainer.commons.util.MapUtil;
+
public class Request {

private String method;
@@ -19,6 +21,14 @@
public String getMethod() {
return method;
}
+
+ public String getParameter(String name, String def) {
+ String ret = MapUtil.getFirstValue(queryString, name, def);
+ if ("".equals(ret)) {
+ return def;
+ }
+ return ret;
+ }

public Request setMethod(String method) {
this.method = method;
=======================================
---
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/http/hook/Response.java
Sat Jun 25 12:08:32 2011
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/http/hook/Response.java
Sun Jun 26 03:57:15 2011
@@ -6,7 +6,7 @@

public class Response {

- private Integer code;
+ private Integer code = 200;

private Map<String, List<String>> headers = new HashMap<String,
List<String>>();

@@ -42,8 +42,9 @@
return content;
}

- public void setContent(Object content) {
+ public Response setContent(Object content) {
this.content = content;
+ return this;
}

}
=======================================
---
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/util/MapUtil.java
Sat Jun 25 11:17:50 2011
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/main/java/org/mycontainer/commons/util/MapUtil.java
Sun Jun 26 03:57:15 2011
@@ -7,6 +7,18 @@

public class MapUtil {

+ public static <K, V> V getFirstValue(Map<K, List<V>> map, String name, V
def) {
+ List<V> list = map.get(name);
+ if (list == null || list.isEmpty()) {
+ return def;
+ }
+ V ret = list.get(0);
+ if (ret == null) {
+ return def;
+ }
+ return ret;
+ }
+
@SuppressWarnings("unchecked")
public static <K, V> Map<K, List<V>> populateList(Map<K, List<V>> map,
Object... array) {
=======================================
---
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/test/java/org/mycontainer/commons/http/hook/BasicRequestServiceTest.java
Sat Jun 25 12:08:32 2011
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-commons/src/test/java/org/mycontainer/commons/http/hook/BasicRequestServiceTest.java
Sun Jun 26 03:57:15 2011
@@ -39,9 +39,9 @@
@Test
public void testRequestChain() {
BasicRequestService service = new BasicRequestService();
- service.addHook(new TestHookDouble());
- service.addHook(new TestHookSquare());
service.addHook(new TestHookReply());
+ service.addHook(new TestHookSquare());
+ service.addHook(new TestHookDouble());

Request req = new Request();
req.setMethod("GET").setUri("my/uri").setContent(5l);
=======================================
---
/trunk/devel/implementation/mycontainer-components/mycontainer-servlet-commons/src/main/java/org/mycontainer/commons/servlet/http/hook/HookFilter.java
Sat Jun 25 12:08:32 2011
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-servlet-commons/src/main/java/org/mycontainer/commons/servlet/http/hook/HookFilter.java
Sun Jun 26 03:57:15 2011
@@ -56,7 +56,7 @@
public static Request parse(HttpServletRequest request) {
try {
Request req = new Request();
- req.setMethod(req.getMethod()).setUri(request.getRequestURI());
+ req.setMethod(request.getMethod()).setUri(request.getRequestURI());
ServletUtil.getHeaders(req.getHeaders(), request);
ServletUtil.getParameters(req.getQueryString(), request);
req.setContent(IOUtil.readAll(request.getInputStream()));
=======================================
---
/trunk/devel/implementation/mycontainer-components/mycontainer-servlet-commons/src/test/java/org/mycontainer/commons/servlet/http/hook/HookFilterTest.java
Sat Jun 25 12:08:32 2011
+++
/trunk/devel/implementation/mycontainer-components/mycontainer-servlet-commons/src/test/java/org/mycontainer/commons/servlet/http/hook/HookFilterTest.java
Sun Jun 26 03:57:15 2011
@@ -62,9 +62,9 @@

@Test
public void testRequestReply() {
- filter.addHook(new TestHookDouble());
- filter.addHook(new TestHookSquare());
filter.addHook(new TestHookReply());
+ filter.addHook(new TestHookSquare());
+ filter.addHook(new TestHookDouble());
WebClient client = createClient();
WebRequest req = client.createRequest(RequestMethod.GET);
try {

Reply all
Reply to author
Forward
0 new messages