You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by li...@apache.org on 2011/05/09 07:08:47 UTC
svn commit: r1100888 - in /shindig/trunk/java/common/src:
main/java/org/apache/shindig/protocol/BaseRequestItem.java
test/java/org/apache/shindig/protocol/BaseRequestItemTest.java
Author: lindner
Date: Mon May 9 05:08:46 2011
New Revision: 1100888
URL: http://svn.apache.org/viewvc?rev=1100888&view=rev
Log:
SHINDIG-1527 | Replace NPE with proper protocol error
Modified:
shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java
shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java
Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java?rev=1100888&r1=1100887&r2=1100888&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java Mon May 9 05:08:46 2011
@@ -198,7 +198,11 @@ public class BaseRequestItem implements
public <T> T getTypedParameter(String parameterName, Class<T> dataTypeClass) {
try {
- return converter.convertToObject(getParameter(parameterName), dataTypeClass);
+ String json = getParameter(parameterName);
+ if (json == null) {
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "missing data for " + parameterName);
+ }
+ return converter.convertToObject(json, dataTypeClass);
} catch (RuntimeException e) {
if (e.getCause() instanceof JSONException)
throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
Modified: shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java?rev=1100888&r1=1100887&r2=1100888&view=diff
==============================================================================
--- shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java (original)
+++ shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java Mon May 9 05:08:46 2011
@@ -115,6 +115,11 @@ public class BaseRequestItemTest extends
assertEquals(1234, input.id);
}
+ @Test(expected = ProtocolException.class)
+ public void testGetTypedParameterEmpty() throws Exception {
+ request.getTypedParameter("empty", InputData.class);
+ }
+
@Test
public void testGetParameters() throws Exception {
request.setParameter("anykey", "{name: 'Bob', id: '1234'}");