juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject incubator-juneau git commit: Bug fixes in proxy interface support.
Date Sun, 26 Mar 2017 23:14:30 GMT
Repository: incubator-juneau
Updated Branches:
  refs/heads/master 9e095d85f -> ca31b2388


Bug fixes in proxy interface support.

Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/ca31b238
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/ca31b238
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/ca31b238

Branch: refs/heads/master
Commit: ca31b238871dbc92f5d200d04297bec49cb2369b
Parents: 9e095d8
Author: JamesBognar <jamesbognar@apache.org>
Authored: Sun Mar 26 16:14:28 2017 -0700
Committer: JamesBognar <jamesbognar@apache.org>
Committed: Sun Mar 26 16:14:28 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/juneau/html/HtmlParser.java |  8 +++---
 .../org/apache/juneau/html/HtmlSerializer.java  | 30 ++++++++++----------
 .../apache/juneau/rest/test/InterfaceProxy.java |  2 ++
 .../rest/test/InterfaceProxyResource.java       |  7 +++++
 .../juneau/rest/test/InterfaceProxyTest.java    | 12 ++++++++
 .../apache/juneau/rest/test/RestTestcase.java   |  9 ++++++
 .../java/org/apache/juneau/rest/RestLogger.java | 13 +++++++--
 7 files changed, 59 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ca31b238/juneau-core/src/main/java/org/apache/juneau/html/HtmlParser.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/html/HtmlParser.java b/juneau-core/src/main/java/org/apache/juneau/html/HtmlParser.java
index 3c14825..94132e6 100644
--- a/juneau-core/src/main/java/org/apache/juneau/html/HtmlParser.java
+++ b/juneau-core/src/main/java/org/apache/juneau/html/HtmlParser.java
@@ -442,10 +442,10 @@ public class HtmlParser extends XmlParser {
 					}
 					String key = keys.get(i);
 					if (m != null) {
-						ClassMeta<?> et = elementType.getValueType();
-						Object value = parseAnything(session, et, r, l, false, pMeta);
-						setName(et, value, key);
-						m.put(key, value);
+						ClassMeta<?> kt = elementType.getKeyType(), vt = elementType.getValueType();
+						Object value = parseAnything(session, vt, r, l, false, pMeta);
+						setName(vt, value, key);
+						m.put(session.convertToType(key, kt), value);
 					}
 				}
 				if (m != null && c != null) {

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ca31b238/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializer.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializer.java b/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializer.java
index 391d496..0f79e8e 100644
--- a/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializer.java
+++ b/juneau-core/src/main/java/org/apache/juneau/html/HtmlSerializer.java
@@ -479,13 +479,13 @@ public class HtmlSerializer extends XmlSerializer {
 		// Look at the objects to see how we're going to handle them.  Check the first object to
see how we're going to handle this.
 		// If it's a map or bean, then we'll create a table.
 		// Otherwise, we'll create a list.
-		String[] th = getTableHeaders(session, c, hbpMeta);
+		Object[] th = getTableHeaders(session, c, hbpMeta);
 
 		if (th != null) {
 
 			out.oTag(i, "table").attr(btpn, type2).append('>').nl();
 			out.sTag(i+1, "tr").nl();
-			for (String key : th)
+			for (Object key : th)
 				out.sTag(i+2, "th").append(key).eTag("th").nl();
 			out.eTag(i+1, "tr").nl();
 
@@ -510,9 +510,9 @@ public class HtmlSerializer extends XmlSerializer {
 				} else if (cm.isMap() && ! (cm.isBeanMap())) {
 					Map m2 = session.sort((Map)o);
 
-					for (String k : th) {
+					for (Object k : th) {
 						out.sTag(i+2, "td");
-						ContentResult cr = serializeAnything(session, out, m2.get(k), seType, k, 2, null, false);
+						ContentResult cr = serializeAnything(session, out, m2.get(k), seType, session.toString(k),
2, null, false);
 						if (cr == CR_NORMAL)
 							out.i(i+2);
 						out.eTag("td").nl();
@@ -524,8 +524,8 @@ public class HtmlSerializer extends XmlSerializer {
 					else
 						m2 = session.toBeanMap(o);
 
-					for (String k : th) {
-						BeanMapEntry p = m2.getProperty(k);
+					for (Object k : th) {
+						BeanMapEntry p = m2.getProperty(session.toString(k));
 						BeanPropertyMeta pMeta = p.getMeta();
 						out.sTag(i+2, "td");
 						ContentResult cr = serializeAnything(session, out, p.getValue(), pMeta.getClassMeta(),
p.getKey().toString(), 2, pMeta, false);
@@ -560,12 +560,12 @@ public class HtmlSerializer extends XmlSerializer {
 	 * 2-dimensional tables are used for collections of objects that all have the same set of
property names.
 	 */
 	@SuppressWarnings({ "rawtypes", "unchecked" })
-	private static String[] getTableHeaders(SerializerSession session, Collection c, HtmlBeanPropertyMeta
hbpMeta) throws Exception {
+	private static Object[] getTableHeaders(SerializerSession session, Collection c, HtmlBeanPropertyMeta
hbpMeta) throws Exception {
 		if (c.size() == 0)
 			return null;
 		c = session.sort(c);
-		String[] th;
-		Set<String> s = new TreeSet<String>();
+		Object[] th;
+		Set<Object> s = new TreeSet<Object>();
 		Set<ClassMeta> prevC = new HashSet<ClassMeta>();
 		Object o1 = null;
 		for (Object o : c)
@@ -589,11 +589,11 @@ public class HtmlSerializer extends XmlSerializer {
 		if (h.isNoTables() || (hbpMeta != null && hbpMeta.isNoTables()))
 			return null;
 		if (h.isNoTableHeaders() || (hbpMeta != null && hbpMeta.isNoTableHeaders()))
-			return new String[0];
+			return new Object[0];
 		if (session.canIgnoreValue(cm, null, o1))
 			return null;
 		if (cm.isMap() && ! cm.isBeanMap()) {
-			Set<String> set = new LinkedHashSet<String>();
+			Set<Object> set = new LinkedHashSet<Object>();
 			for (Object o : c) {
 				if (! session.canIgnoreValue(cm, null, o)) {
 					if (! cm.isInstance(o))
@@ -601,13 +601,13 @@ public class HtmlSerializer extends XmlSerializer {
 					Map m = session.sort((Map)o);
 					for (Map.Entry e : (Set<Map.Entry>)m.entrySet()) {
 						if (e.getValue() != null)
-							set.add(e.getKey() == null ? null : e.getKey().toString());
+							set.add(e.getKey() == null ? null : e.getKey());
 					}
 				}
 			}
-			th = set.toArray(new String[set.size()]);
+			th = set.toArray(new Object[set.size()]);
 		} else {
-			Set<String> set = new LinkedHashSet<String>();
+			Set<Object> set = new LinkedHashSet<Object>();
 			for (Object o : c) {
 				if (! session.canIgnoreValue(cm, null, o)) {
 					if (! cm.isInstance(o))
@@ -619,7 +619,7 @@ public class HtmlSerializer extends XmlSerializer {
 					}
 				}
 			}
-			th = set.toArray(new String[set.size()]);
+			th = set.toArray(new Object[set.size()]);
 		}
 		prevC.add(cm);
 		s.addAll(Arrays.asList(th));

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ca31b238/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/InterfaceProxy.java
----------------------------------------------------------------------
diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/InterfaceProxy.java
b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/InterfaceProxy.java
index 359f103..762886e 100644
--- a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/InterfaceProxy.java
+++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/InterfaceProxy.java
@@ -36,6 +36,7 @@ public interface InterfaceProxy {
 	List<Bean> returnBeanList();
 	Map<String,Bean> returnBeanMap();
 	Map<String,List<Bean>> returnBeanListMap();
+	Map<Integer,List<Bean>> returnBeanListMapIntegerKeys();
 
 	void setNothing();
 	void setInt(int x);
@@ -54,6 +55,7 @@ public interface InterfaceProxy {
 	void setBeanList(List<Bean> x);
 	void setBeanMap(Map<String,Bean> x);
 	void setBeanListMap(Map<String,List<Bean>> x);
+	void setBeanListMapIntegerKeys(Map<Integer,List<Bean>> x);
 
 	public static class Bean {
 		public int a;

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ca31b238/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/InterfaceProxyResource.java
----------------------------------------------------------------------
diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/InterfaceProxyResource.java
b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/InterfaceProxyResource.java
index b8cdf03..57fa638 100644
--- a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/InterfaceProxyResource.java
+++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/InterfaceProxyResource.java
@@ -70,6 +70,8 @@ public class InterfaceProxyResource extends RestServletJenaDefault {
 			public Map<String,Bean> returnBeanMap() { return new HashMap<String,Bean>(){{put("foo",new
Bean().init());}}; }
 			@Override
 			public Map<String,List<Bean>> returnBeanListMap() { return new HashMap<String,List<Bean>>(){{put("foo",Arrays.asList(new
Bean().init()));}}; }
+			@Override
+			public Map<Integer,List<Bean>> returnBeanListMapIntegerKeys() { return new
HashMap<Integer,List<Bean>>(){{put(1,Arrays.asList(new Bean().init()));}}; }
 
 			@Override
 			public void setNothing() {
@@ -138,6 +140,11 @@ public class InterfaceProxyResource extends RestServletJenaDefault {
 			public void setBeanListMap(Map<String,List<Bean>> x) {
 				assertObjectEquals("{foo:[{a:1,b:'foo'}]}", x);
 			}
+			@Override
+			public void setBeanListMapIntegerKeys(Map<Integer,List<Bean>> x) {
+				assertObjectEquals("{'1':[{a:1,b:'foo'}]}", x);  // Note: JsonSerializer serializes key
as string.
+				assertEquals(Integer.class, x.keySet().iterator().next().getClass());
+			}
 		};
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ca31b238/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/InterfaceProxyTest.java
----------------------------------------------------------------------
diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/InterfaceProxyTest.java
b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/InterfaceProxyTest.java
index 6ecfb0d..2a7fdfd 100644
--- a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/InterfaceProxyTest.java
+++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/InterfaceProxyTest.java
@@ -153,6 +153,13 @@ public class InterfaceProxyTest extends RestTestcase {
 	}
 
 	@Test
+	public void returnBeanListMapIntegerKeys() {
+		// Note: JsonSerializer serializes key as string.
+		assertObjectEquals("{'1':[{a:1,b:'foo'}]}", getProxy().returnBeanListMapIntegerKeys());
+		assertClass(Integer.class, getProxy().returnBeanListMapIntegerKeys().keySet().iterator().next());
+	}
+
+	@Test
 	public void setNothing() {
 		getProxy().setNothing();
 	}
@@ -256,4 +263,9 @@ public class InterfaceProxyTest extends RestTestcase {
 	public void setBeanListMap() {
 		getProxy().setBeanListMap(new HashMap<String,List<Bean>>(){{put("foo",Arrays.asList(new
Bean().init()));}});
 	}
+
+	@Test
+	public void setBeanListMapIntegerKeys() {
+		getProxy().setBeanListMapIntegerKeys(new HashMap<Integer,List<Bean>>(){{put(1,Arrays.asList(new
Bean().init()));}});
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ca31b238/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/RestTestcase.java
----------------------------------------------------------------------
diff --git a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/RestTestcase.java
b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/RestTestcase.java
index 1a23177..bd6346c 100644
--- a/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/RestTestcase.java
+++ b/juneau-rest-test/src/test/java/org/apache/juneau/rest/test/RestTestcase.java
@@ -45,6 +45,15 @@ public class RestTestcase {
 		return rc;
 	}
 
+	/**
+	 * Same as {@link #getClient(Serializer, Parser)} but sets the debug flag on the client.
+	 */
+	protected RestClient getDebugClient(Serializer serializer, Parser parser) {
+		RestClient rc = TestMicroservice.client(serializer, parser).debug(true).build();
+		clients.add(rc);
+		return rc;
+	}
+
 	@AfterClass
 	public static void tearDown() {
 		if (microserviceStarted)

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ca31b238/juneau-rest/src/main/java/org/apache/juneau/rest/RestLogger.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestLogger.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestLogger.java
index 8a13d2f..da266de 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestLogger.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestLogger.java
@@ -157,10 +157,9 @@ public abstract class RestLogger {
 	 * @return <jk>true</jk> if exception should be logged.
 	 */
 	protected boolean shouldLog(HttpServletRequest req, HttpServletResponse res, RestException
e) {
-		if ("true".equals(req.getHeader("No-Trace")))
+		if (isNoTrace(req) && ! isDebug(req))
 			return false;
-		String q = req.getQueryString();
-		return (q == null ? true : q.indexOf("noTrace=true") == -1);
+		return true;
 	}
 
 	/**
@@ -194,6 +193,14 @@ public abstract class RestLogger {
 		return false;
 	}
 
+	private static boolean isNoTrace(HttpServletRequest req) {
+		return "true".equals(req.getHeader("No-Trace")) || req.getQueryString().contains("noTrace=true");
+	}
+
+	private static boolean isDebug(HttpServletRequest req) {
+		return "true".equals(req.getHeader("Debug"));
+	}
+
 	/**
 	 * NO-OP logger.
 	 * <p>


Mime
View raw message