You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by li...@apache.org on 2008/09/03 12:08:36 UTC
svn commit: r691558 - in
/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service:
RequestItem.java RpcRequestItem.java
Author: lindner
Date: Wed Sep 3 03:08:35 2008
New Revision: 691558
URL: http://svn.apache.org/viewvc?rev=691558&view=rev
Log:
SHINDIG-567 | Invalid user input should result in badRequest, not internalError. Patch from Adam Winer
Modified:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RequestItem.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RpcRequestItem.java
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RequestItem.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RequestItem.java?rev=691558&r1=691557&r2=691558&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RequestItem.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RequestItem.java Wed Sep 3 03:08:35 2008
@@ -21,6 +21,8 @@
import org.apache.shindig.social.opensocial.spi.GroupId;
import org.apache.shindig.social.opensocial.spi.PersonService;
import org.apache.shindig.social.opensocial.spi.UserId;
+import org.apache.shindig.social.opensocial.spi.SocialSpiException;
+import org.apache.shindig.social.ResponseError;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
@@ -109,13 +111,23 @@
public int getStartIndex() {
String startIndex = getParameter(START_INDEX);
- return startIndex == null ? DEFAULT_START_INDEX
- : Integer.valueOf(startIndex);
+ try {
+ return startIndex == null ? DEFAULT_START_INDEX
+ : Integer.valueOf(startIndex);
+ } catch (NumberFormatException nfe) {
+ throw new SocialSpiException(ResponseError.BAD_REQUEST,
+ "Parameter " + START_INDEX + " (" + startIndex + ") is not a number.");
+ }
}
public int getCount() {
String count = getParameter(COUNT);
- return count == null ? DEFAULT_COUNT : Integer.valueOf(count);
+ try {
+ return count == null ? DEFAULT_COUNT : Integer.valueOf(count);
+ } catch (NumberFormatException nfe) {
+ throw new SocialSpiException(ResponseError.BAD_REQUEST,
+ "Parameter " + COUNT + " (" + count + ") is not a number.");
+ }
}
public String getSortBy() {
@@ -125,9 +137,14 @@
public PersonService.SortOrder getSortOrder() {
String sortOrder = getParameter(SORT_ORDER);
- return sortOrder == null
- ? PersonService.SortOrder.ascending
- : PersonService.SortOrder.valueOf(sortOrder);
+ try {
+ return sortOrder == null
+ ? PersonService.SortOrder.ascending
+ : PersonService.SortOrder.valueOf(sortOrder);
+ } catch (IllegalArgumentException iae) {
+ throw new SocialSpiException(ResponseError.BAD_REQUEST,
+ "Parameter " + SORT_ORDER + " (" + sortOrder + ") is not valid.");
+ }
}
public String getFilterBy() {
@@ -136,9 +153,14 @@
public PersonService.FilterOperation getFilterOperation() {
String filterOp = getParameter(FILTER_OPERATION);
- return filterOp == null
- ? PersonService.FilterOperation.contains
- : PersonService.FilterOperation.valueOf(filterOp);
+ try {
+ return filterOp == null
+ ? PersonService.FilterOperation.contains
+ : PersonService.FilterOperation.valueOf(filterOp);
+ } catch (IllegalArgumentException iae) {
+ throw new SocialSpiException(ResponseError.BAD_REQUEST,
+ "Parameter " + FILTER_OPERATION + " (" + filterOp + ") is not valid.");
+ }
}
public String getFilterValue() {
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RpcRequestItem.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RpcRequestItem.java?rev=691558&r1=691557&r2=691558&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RpcRequestItem.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/RpcRequestItem.java Wed Sep 3 03:08:35 2008
@@ -19,6 +19,8 @@
package org.apache.shindig.social.opensocial.service;
import org.apache.shindig.auth.SecurityToken;
+import org.apache.shindig.social.opensocial.spi.SocialSpiException;
+import org.apache.shindig.social.ResponseError;
import com.google.common.collect.Lists;
@@ -65,7 +67,7 @@
return null;
}
} catch (JSONException je) {
- throw new IllegalArgumentException(je);
+ throw new SocialSpiException(ResponseError.BAD_REQUEST, je.getMessage(), je);
}
}
@@ -78,7 +80,7 @@
return defaultValue;
}
} catch (JSONException je) {
- throw new IllegalArgumentException(je);
+ throw new SocialSpiException(ResponseError.BAD_REQUEST, je.getMessage(), je);
}
}
@@ -101,7 +103,7 @@
return Collections.emptyList();
}
} catch (JSONException je) {
- throw new IllegalArgumentException(je);
+ throw new SocialSpiException(ResponseError.BAD_REQUEST, je.getMessage(), je);
}
}
@@ -110,7 +112,7 @@
try {
return converter.convertToObject(data.get(parameterName).toString(), dataTypeClass);
} catch (JSONException je) {
- throw new IllegalArgumentException(je);
+ throw new SocialSpiException(ResponseError.BAD_REQUEST, je.getMessage(), je);
}
}
@@ -120,6 +122,7 @@
// No params in the URL
}
+ /** Method used only by tests */
void setParameter(String paramName, String param) {
try {
data.put(paramName, param);
@@ -128,6 +131,7 @@
}
}
+ /** Method used only by tests */
void setListParameter(String paramName, List<String> params) {
try {
JSONArray arr = new JSONArray(params);