You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by aw...@apache.org on 2009/04/21 21:02:37 UTC
svn commit: r767255 - in /incubator/shindig/trunk/java:
common/src/main/java/org/apache/shindig/protocol/
common/src/test/java/org/apache/shindig/protocol/
gadgets/src/main/java/org/apache/shindig/gadgets/http/
gadgets/src/main/java/org/apache/shindig/...
Author: awiner
Date: Tue Apr 21 19:02:36 2009
New Revision: 767255
URL: http://svn.apache.org/viewvc?rev=767255&view=rev
Log:
Remove ResponseError class, and use HTTP/JSON-RPC error codes throughout
- Start using -32700 for JsonRpcServlet JSON RPC parsing issues
- Transform negative values for errorCodes into acceptable HTTP error codes in DataServiceServlet
Removed:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ResponseError.java
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DataServiceServlet.java
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DefaultHandlerRegistry.java
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/HandlerPreconditions.java
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ProtocolException.java
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ResponseItem.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/TestHandler.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/InvalidationHandler.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpRequestHandler.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/AppDataHandler.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/MessageHandler.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/SocialSpiException.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/service/SampleContainerHandler.java
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/AppDataHandlerTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/ResponseItemTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java Tue Apr 21 19:02:36 2009
@@ -118,7 +118,7 @@
throws IOException;
protected void sendSecurityError(HttpServletResponse servletResponse) throws IOException {
- sendError(servletResponse, new ResponseItem(ResponseError.UNAUTHORIZED,
+ sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_UNAUTHORIZED,
"The request did not have a proper security token nor oauth message and unauthenticated "
+ "requests are not allowed"));
}
@@ -144,10 +144,10 @@
if (t instanceof ProtocolException) {
ProtocolException spe = (ProtocolException) t;
logger.log(Level.INFO, "Returning a response error as result of a protocol exception", spe);
- return new ResponseItem(spe.getError(), spe.getMessage());
+ return new ResponseItem(spe.getCode(), spe.getMessage());
}
logger.log(Level.WARNING, "Returning a response error as result of an exception", t);
- return new ResponseItem(ResponseError.INTERNAL_ERROR, t.getMessage());
+ return new ResponseItem(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, t.getMessage());
}
protected void setCharacterEncodings(HttpServletRequest servletRequest,
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java Tue Apr 21 19:02:36 2009
@@ -41,6 +41,8 @@
import java.util.Map;
import java.util.Set;
+import javax.servlet.http.HttpServletResponse;
+
/**
* Default implementation of RequestItem
*/
@@ -92,7 +94,7 @@
this.converter = converter;
this.formItems = formItems;
} catch (JSONException je) {
- throw new ProtocolException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je);
}
this.jsonConverter = jsonConverter;
}
@@ -127,7 +129,7 @@
? SortOrder.ascending
: SortOrder.valueOf(sortOrder);
} catch (IllegalArgumentException iae) {
- throw new ProtocolException(ResponseError.BAD_REQUEST,
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
"Parameter " + SORT_ORDER + " (" + sortOrder + ") is not valid.");
}
}
@@ -142,7 +144,7 @@
return startIndex == null ? DEFAULT_START_INDEX
: Integer.valueOf(startIndex);
} catch (NumberFormatException nfe) {
- throw new ProtocolException(ResponseError.BAD_REQUEST,
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
"Parameter " + START_INDEX + " (" + startIndex + ") is not a number.");
}
}
@@ -152,7 +154,7 @@
try {
return count == null ? DEFAULT_COUNT : Integer.valueOf(count);
} catch (NumberFormatException nfe) {
- throw new ProtocolException(ResponseError.BAD_REQUEST,
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
"Parameter " + COUNT + " (" + count + ") is not a number.");
}
}
@@ -164,7 +166,7 @@
? FilterOperation.contains
: FilterOperation.valueOf(filterOp);
} catch (IllegalArgumentException iae) {
- throw new ProtocolException(ResponseError.BAD_REQUEST,
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
"Parameter " + FILTER_OPERATION + " (" + filterOp + ") is not valid.");
}
}
@@ -247,7 +249,7 @@
}
return returnVal;
} catch (JSONException je) {
- throw new ProtocolException(ResponseError.BAD_REQUEST, je.getMessage(), je);
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, je.getMessage(), je);
}
} else {
// Allow up-conversion of non-array to array params.
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DataServiceServlet.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DataServiceServlet.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DataServiceServlet.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DataServiceServlet.java Tue Apr 21 19:02:36 2009
@@ -61,7 +61,8 @@
checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType());
executeRequest(servletRequest, servletResponse);
} catch (ContentTypes.InvalidContentTypeException icte) {
- sendError(servletResponse, new ResponseItem(ResponseError.BAD_REQUEST, icte.getMessage()));
+ sendError(servletResponse,
+ new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage()));
}
}
@@ -80,7 +81,8 @@
checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType());
executeRequest(servletRequest, servletResponse);
} catch (ContentTypes.InvalidContentTypeException icte) {
- sendError(servletResponse, new ResponseItem(ResponseError.BAD_REQUEST, icte.getMessage()));
+ sendError(servletResponse,
+ new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage()));
}
}
@@ -109,7 +111,29 @@
@Override
protected void sendError(HttpServletResponse servletResponse, ResponseItem responseItem)
throws IOException {
- servletResponse.sendError(responseItem.getError().getHttpErrorCode(),
+ int errorCode = responseItem.getErrorCode();
+ if (errorCode < 0) {
+ // Map JSON-RPC error codes into HTTP error codes as best we can
+ // TODO: Augment the error message (if missing) with a default
+ switch (errorCode) {
+ case -32700:
+ case -32602:
+ case -32600:
+ // Parse error, invalid params, and invalid request
+ errorCode = HttpServletResponse.SC_BAD_REQUEST;
+ break;
+ case -32601:
+ // Procedure doesn't exist
+ errorCode = HttpServletResponse.SC_NOT_IMPLEMENTED;
+ case -32603:
+ default:
+ // Internal server error, or any application-defined error
+ errorCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
+ break;
+ }
+ }
+
+ servletResponse.sendError(responseItem.getErrorCode(),
responseItem.getErrorMessage());
}
@@ -136,7 +160,7 @@
ResponseItem responseItem = getResponseItem(future);
servletResponse.setContentType(converter.getContentType());
- if (responseItem.getError() == null) {
+ if (responseItem.getErrorCode() >= 200 && responseItem.getErrorCode() < 400) {
PrintWriter writer = servletResponse.getWriter();
Object response = responseItem.getResponse();
// TODO: ugliness resulting from not using RestfulItem
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DefaultHandlerRegistry.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DefaultHandlerRegistry.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DefaultHandlerRegistry.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DefaultHandlerRegistry.java Tue Apr 21 19:02:36 2009
@@ -49,6 +49,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.servlet.http.HttpServletResponse;
+
/**
* Default implementation of HandlerRegistry. Bind to appropriately
* annotated handlers.
@@ -123,12 +125,12 @@
String key = rpc.getString("method");
RpcInvocationHandler rpcHandler = rpcOperations.get(key);
if (rpcHandler == null) {
- return new ErrorRpcHandler(new ProtocolException(ResponseError.NOT_IMPLEMENTED,
+ return new ErrorRpcHandler(new ProtocolException(HttpServletResponse.SC_NOT_IMPLEMENTED,
"The method " + key + " is not implemented"));
}
return new RpcInvocationWrapper(rpcHandler, rpc);
} catch (JSONException je) {
- return new ErrorRpcHandler(new ProtocolException(ResponseError.BAD_REQUEST,
+ return new ErrorRpcHandler(new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
"No method requested in RPC"));
}
}
@@ -154,7 +156,7 @@
}
}
}
- return new ErrorRestHandler(new ProtocolException(ResponseError.NOT_IMPLEMENTED,
+ return new ErrorRestHandler(new ProtocolException(HttpServletResponse.SC_NOT_IMPLEMENTED,
"No service defined for path " + path));
}
@@ -596,7 +598,7 @@
for (int i = 0; i < Math.min(requestPathParts.length, parts.size()); i++) {
if (parts.get(i).type == PartType.SINGULAR_PARAM) {
if (requestPathParts[i].indexOf(',') != -1) {
- throw new ProtocolException(ResponseError.BAD_REQUEST,
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
"Cannot expect plural value " + requestPathParts[i]
+ " for singular field " + parts.get(i) + " for path " + operationPath);
}
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/HandlerPreconditions.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/HandlerPreconditions.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/HandlerPreconditions.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/HandlerPreconditions.java Tue Apr 21 19:02:36 2009
@@ -21,6 +21,8 @@
import java.util.Collection;
+import javax.servlet.http.HttpServletResponse;
+
/**
* Utility class for common API call preconditions
*/
@@ -31,26 +33,26 @@
public static void requireNotEmpty(Collection<?> coll, String message)
throws ProtocolException {
if (coll.isEmpty()) {
- throw new ProtocolException(ResponseError.BAD_REQUEST, message);
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, message);
}
}
public static void requireEmpty(Collection<?> coll, String message) throws ProtocolException {
if (!coll.isEmpty()) {
- throw new ProtocolException(ResponseError.BAD_REQUEST, message);
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, message);
}
}
public static void requireSingular(Collection<?> coll, String message)
throws ProtocolException {
if (coll.size() != 1) {
- throw new ProtocolException(ResponseError.BAD_REQUEST, message);
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, message);
}
}
public static void requirePlural(Collection<?> coll, String message) throws ProtocolException {
if (coll.size() <= 1) {
- throw new ProtocolException(ResponseError.BAD_REQUEST, message);
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, message);
}
}
}
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java Tue Apr 21 19:02:36 2009
@@ -24,6 +24,7 @@
import org.apache.shindig.protocol.multipart.FormDataItem;
import org.apache.shindig.protocol.multipart.MultipartFormParser;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -57,6 +58,11 @@
*/
public static final String REQUEST_PARAM = "request";
+ /**
+ * Error code for JSON-RPC requests with an error parsing JSON.
+ */
+ public static final int SC_JSON_PARSE_ERROR = -32700;
+
private MultipartFormParser formParser;
@Inject
@@ -78,7 +84,7 @@
JSONObject request = JsonConversionUtil.fromRequest(servletRequest);
dispatch(request, null, servletRequest, servletResponse, token);
} catch (JSONException je) {
- // FIXME
+ sendJsonParseError(je, servletResponse);
}
}
@@ -132,7 +138,7 @@
dispatch(request, formItems, servletRequest, servletResponse, token);
}
} catch (JSONException je) {
- sendBadRequest(je, servletResponse);
+ sendJsonParseError(je, servletResponse);
} catch (ContentTypes.InvalidContentTypeException icte) {
sendBadRequest(icte, servletResponse);
}
@@ -200,11 +206,11 @@
if (key != null) {
result.put("id", key);
}
- if (responseItem.getError() != null) {
+ if (responseItem.getErrorCode() < 200 ||
+ responseItem.getErrorCode() >= 400) {
result.put("error", getErrorJson(responseItem));
} else {
Object response = responseItem.getResponse();
-
if (response instanceof DataCollection) {
result.put("data", ((DataCollection) response).getEntry());
} else if (response instanceof RestfulCollection) {
@@ -217,22 +223,42 @@
} else {
result.put("data", response);
}
+
+ // TODO: put "code" for != 200?
}
return result;
}
+ /** Map of old-style error titles */
+ private static final Map<Integer, String> errorTitles = ImmutableMap.<Integer, String> builder()
+ .put(HttpServletResponse.SC_NOT_IMPLEMENTED, "notImplemented")
+ .put(HttpServletResponse.SC_UNAUTHORIZED, "unauthorized")
+ .put(HttpServletResponse.SC_FORBIDDEN, "forbidden")
+ .put(HttpServletResponse.SC_BAD_REQUEST, "badRequest")
+ .put(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "internalError")
+ .put(HttpServletResponse.SC_EXPECTATION_FAILED, "limitExceeded")
+ .build();
+
// TODO(doll): Refactor the responseItem so that the fields on it line up with this format.
// Then we can use the general converter to output the response to the client and we won't
// be harcoded to json.
private Object getErrorJson(ResponseItem responseItem) {
Map<String, Object> error = new HashMap<String, Object>(2, 1);
- error.put("code", responseItem.getError().getHttpErrorCode());
+ error.put("code", responseItem.getErrorCode());
- String message = responseItem.getError().toString();
- if (StringUtils.isNotBlank(responseItem.getErrorMessage())) {
- message += ": " + responseItem.getErrorMessage();
+ String message = errorTitles.get(responseItem.getErrorCode());
+ if (message == null) {
+ message = responseItem.getErrorMessage();
+ } else {
+ if (StringUtils.isNotBlank(responseItem.getErrorMessage())) {
+ message += ": " + responseItem.getErrorMessage();
+ }
+ }
+
+ if (StringUtils.isNotBlank(message)) {
+ error.put("message", message);
}
- error.put("message", message);
+
return error;
}
@@ -243,7 +269,12 @@
}
private void sendBadRequest(Throwable t, HttpServletResponse response) throws IOException {
- sendError(response, new ResponseItem(ResponseError.BAD_REQUEST,
+ sendError(response, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST,
"Invalid batch - " + t.getMessage()));
}
+
+ private void sendJsonParseError(JSONException e, HttpServletResponse response) throws IOException {
+ sendError(response, new ResponseItem(SC_JSON_PARSE_ERROR,
+ "Invalid JSON - " + e.getMessage()));
+ }
}
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ProtocolException.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ProtocolException.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ProtocolException.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ProtocolException.java Tue Apr 21 19:02:36 2009
@@ -17,23 +17,35 @@
*/
package org.apache.shindig.protocol;
+import javax.servlet.http.HttpServletResponse;
+
+import com.google.common.base.Preconditions;
+
/**
* Unchecked exception class for errors thrown by request handlers
*/
public class ProtocolException extends RuntimeException {
- private final ResponseError error;
+ private final int errorCode;
- public ProtocolException(ResponseError error, String errorMessage, Throwable cause) {
+ public ProtocolException(int errorCode, String errorMessage, Throwable cause) {
super(errorMessage, cause);
- this.error = error;
+ checkErrorCode(errorCode);
+ this.errorCode = errorCode;
}
- public ProtocolException(ResponseError error, String errorMessage) {
+ public ProtocolException(int errorCode, String errorMessage) {
super(errorMessage);
- this.error = error;
+ checkErrorCode(errorCode);
+ this.errorCode = errorCode;
+ }
+
+ public int getCode() {
+ return errorCode;
}
- public ResponseError getError() {
- return error;
+ private void checkErrorCode(int code) {
+ // 200 is not a legit use of ProtocolExceptions.
+ Preconditions.checkArgument(code != HttpServletResponse.SC_OK,
+ "May not use OK error code with ProtocolException");
}
}
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ResponseItem.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ResponseItem.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ResponseItem.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/ResponseItem.java Tue Apr 21 19:02:36 2009
@@ -25,9 +25,9 @@
*/
public final class ResponseItem {
/**
- * The ResponseError associated with the item.
+ * The error code associated with the item.
*/
- private final ResponseError error;
+ private final int errorCode;
/**
* The error message.
@@ -41,11 +41,11 @@
/**
* Create a ResponseItem specifying the ResponseError and error Message.
- * @param error a ResponseError
+ * @param errorCode an RPC error code
* @param errorMessage the Error Message
*/
- public ResponseItem(ResponseError error, String errorMessage) {
- this.error = error;
+ public ResponseItem(int errorCode, String errorMessage) {
+ this.errorCode = errorCode;
this.errorMessage = errorMessage;
this.response = null;
}
@@ -54,7 +54,7 @@
* Create a ResponseItem specifying a value.
*/
public ResponseItem(Object response) {
- this.error = null;
+ this.errorCode = 200;
this.errorMessage = null;
this.response = response;
}
@@ -67,11 +67,11 @@
}
/**
- * Get the ResponseError associated with this ResponseItem.
- * @return the ResponseError associated with this ResponseItem
+ * Get the error code associated with this ResponseItem.
+ * @return the error code associated with this ResponseItem
*/
- public ResponseError getError() {
- return error;
+ public int getErrorCode() {
+ return errorCode;
}
/**
@@ -93,13 +93,13 @@
}
ResponseItem that = (ResponseItem) o;
- return (error == that.error)
+ return (errorCode == that.errorCode)
&& Objects.equal(errorMessage, that.errorMessage)
&& Objects.equal(response, that.response);
}
@Override
public int hashCode() {
- return Objects.hashCode(error, errorMessage, response);
+ return Objects.hashCode(errorCode, errorMessage, response);
}
}
\ No newline at end of file
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java Tue Apr 21 19:02:36 2009
@@ -23,12 +23,6 @@
import org.apache.shindig.common.testing.FakeHttpServletRequest;
import org.apache.shindig.protocol.conversion.BeanConverter;
import org.apache.shindig.protocol.conversion.BeanJsonConverter;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Sets;
-
-import junit.framework.TestCase;
-
import org.easymock.IMocksControl;
import org.easymock.classextension.EasyMock;
@@ -38,6 +32,11 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import junit.framework.TestCase;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Sets;
+
public class DataServiceServletTest extends TestCase {
private static final FakeGadgetToken FAKE_GADGET_TOKEN = new FakeGadgetToken()
@@ -128,7 +127,7 @@
setupRequest(route, "DELETE", null);
// Shouldnt these be expectations
- res.sendError(ResponseError.BAD_REQUEST.getHttpErrorCode(), TestHandler.FAILURE_MESSAGE);
+ res.sendError(HttpServletResponse.SC_BAD_REQUEST, TestHandler.FAILURE_MESSAGE);
res.setCharacterEncoding("UTF-8");
res.setContentType(ContentTypes.OUTPUT_JSON_CONTENT_TYPE);
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java Tue Apr 21 19:02:36 2009
@@ -38,6 +38,8 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import javax.servlet.http.HttpServletResponse;
+
/**
* Tests BasicHandleRregistry
*/
@@ -89,7 +91,7 @@
fail("Expect exception for missing method");
} catch (ExecutionException t) {
assertSame(t.getCause().getClass(), ProtocolException.class);
- Assert.assertEquals(((ProtocolException) t.getCause()).getError(), ResponseError.NOT_IMPLEMENTED);
+ Assert.assertEquals(((ProtocolException) t.getCause()).getCode(), HttpServletResponse.SC_NOT_IMPLEMENTED);
} catch (Throwable t) {
fail("Unexpected exception " + t.toString());
}
@@ -103,7 +105,7 @@
fail("Expect exception for missing method");
} catch (ExecutionException t) {
assertSame(t.getCause().getClass(), ProtocolException.class);
- Assert.assertEquals(((ProtocolException) t.getCause()).getError(), ResponseError.NOT_IMPLEMENTED);
+ Assert.assertEquals(((ProtocolException) t.getCause()).getCode(), HttpServletResponse.SC_NOT_IMPLEMENTED);
} catch (Throwable t) {
fail("Unexpected exception " + t.toString());
}
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/TestHandler.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/TestHandler.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/TestHandler.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/TestHandler.java Tue Apr 21 19:02:36 2009
@@ -27,6 +27,8 @@
import java.util.Map;
import java.util.concurrent.Future;
+import javax.servlet.http.HttpServletResponse;
+
/**
* Simple test handler implementation. Can be used standalone or to wrap a mock
* delegate.
@@ -90,7 +92,7 @@
if (mock != null) {
return mock.futureException(req);
}
- return ImmediateFuture.errorInstance(new ProtocolException(ResponseError.BAD_REQUEST,
+ return ImmediateFuture.errorInstance(new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
FAILURE_MESSAGE, new Throwable()));
}
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/InvalidationHandler.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/InvalidationHandler.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/InvalidationHandler.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/InvalidationHandler.java Tue Apr 21 19:02:36 2009
@@ -23,15 +23,16 @@
import org.apache.shindig.protocol.BaseRequestItem;
import org.apache.shindig.protocol.Operation;
import org.apache.shindig.protocol.ProtocolException;
-import org.apache.shindig.protocol.ResponseError;
import org.apache.shindig.protocol.Service;
-import com.google.common.collect.Sets;
-import com.google.inject.Inject;
-
import java.util.List;
import java.util.Set;
+import javax.servlet.http.HttpServletResponse;
+
+import com.google.common.collect.Sets;
+import com.google.inject.Inject;
+
/**
* Handle cache invalidation API calls
*
@@ -53,10 +54,9 @@
@Operation(httpMethods = {"POST","GET"}, path = "/invalidate")
public void invalidate(BaseRequestItem request) {
-
if (StringUtils.isEmpty(request.getToken().getAppId()) &&
StringUtils.isEmpty(request.getToken().getAppUrl())) {
- throw new ProtocolException(ResponseError.BAD_REQUEST,
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
"Cannot invalidate content without specifying application");
}
@@ -80,7 +80,7 @@
// Assume key is a gadget spec, message bundle or other resource
// owned by the gadget
if (!isBackendInvalidation) {
- throw new ProtocolException(ResponseError.BAD_REQUEST,
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
"Cannot flush application resources from a gadget. " +
"Must use OAuth consumer request");
}
@@ -91,7 +91,7 @@
continue;
}
if (!isBackendInvalidation && !key.equals(request.getToken().getViewerId())) {
- throw new ProtocolException(ResponseError.BAD_REQUEST,
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
"Cannot invalidate the content for a user other than the viewer from a gadget.");
}
userIds.add(key);
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpRequestHandler.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpRequestHandler.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpRequestHandler.java Tue Apr 21 19:02:36 2009
@@ -33,18 +33,19 @@
import org.apache.shindig.protocol.BaseRequestItem;
import org.apache.shindig.protocol.Operation;
import org.apache.shindig.protocol.ProtocolException;
-import org.apache.shindig.protocol.ResponseError;
import org.apache.shindig.protocol.Service;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletResponse;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.inject.Inject;
-import java.util.Map;
-import java.util.Set;
-import java.util.Collection;
-
/**
* An alternate implementation of the Http proxy service using the standard API dispatcher for REST
* / JSON-RPC calls. The basic form of the request is as follows
@@ -141,8 +142,8 @@
private void assertNoBody(HttpApiRequest httpRequest, String method) {
if (httpRequest.body != null) {
- throw new ProtocolException(ResponseError.BAD_REQUEST,
- "Request body not supported for " + method);
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
+ "Request body not supported for " + method);
}
}
@@ -154,7 +155,7 @@
private HttpApiResponse execute(String method, HttpApiRequest httpApiRequest,
SecurityToken token) {
if (httpApiRequest.url == null) {
- throw new ProtocolException(ResponseError.BAD_REQUEST, "Url parameter is missing");
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "Url parameter is missing");
}
// Canonicalize the path
@@ -179,7 +180,7 @@
// Extract the gadget URI from the request or the security token
Uri gadgetUri = getGadgetUri(token, httpApiRequest);
if (gadgetUri == null) {
- throw new ProtocolException(ResponseError.BAD_REQUEST,
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
"Gadget URI not specified in request");
}
req.setGadget(gadgetUri);
@@ -226,9 +227,11 @@
}
return httpApiResponse;
} catch (GadgetException ge) {
- throw new ProtocolException(ResponseError.INTERNAL_ERROR, ge.getMessage());
+ throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ ge.getMessage(), ge);
} catch (RewritingException re) {
- throw new ProtocolException(ResponseError.INTERNAL_ERROR, re.getMessage());
+ throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ re.getMessage(), re);
}
}
@@ -238,7 +241,8 @@
url = new UriBuilder(url).setScheme("http").toUri();
} else if (!"http".equals(url.getScheme()) && !"https"
.equals(url.getScheme())) {
- throw new ProtocolException(ResponseError.BAD_REQUEST, "Only HTTP and HTTPS are supported");
+ throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
+ "Only HTTP and HTTPS are supported");
}
return url;
}
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/AppDataHandler.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/AppDataHandler.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/AppDataHandler.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/AppDataHandler.java Tue Apr 21 19:02:36 2009
@@ -19,18 +19,19 @@
import org.apache.shindig.protocol.HandlerPreconditions;
import org.apache.shindig.protocol.Operation;
-import org.apache.shindig.protocol.ResponseError;
import org.apache.shindig.protocol.Service;
import org.apache.shindig.social.opensocial.spi.AppDataService;
import org.apache.shindig.social.opensocial.spi.SocialSpiException;
import org.apache.shindig.social.opensocial.spi.UserId;
-import com.google.inject.Inject;
-
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;
+import javax.servlet.http.HttpServletResponse;
+
+import com.google.inject.Inject;
+
@Service(name = "appdata", path = "/{userId}+/{groupId}/{appId}")
public class AppDataHandler {
@@ -97,7 +98,7 @@
Map<String, String> values = request.getTypedParameter("data", Map.class);
for (String key : values.keySet()) {
if (!isValidKey(key)) {
- throw new SocialSpiException(ResponseError.BAD_REQUEST,
+ throw new SocialSpiException(HttpServletResponse.SC_BAD_REQUEST,
"One or more of the app data keys are invalid: " + key);
}
}
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/MessageHandler.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/MessageHandler.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/MessageHandler.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/MessageHandler.java Tue Apr 21 19:02:36 2009
@@ -31,6 +31,8 @@
import java.util.List;
import java.util.concurrent.Future;
+import javax.servlet.http.HttpServletResponse;
+
@Service(name = "messages", path="/{userId}+/{msgCollId}/{messageIds}+")
public class MessageHandler {
@@ -51,7 +53,10 @@
HandlerPreconditions.requireNotEmpty(userIds, "No userId specified");
HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported");
- if (msgCollId == null) throw new SocialSpiException(ResponseError.BAD_REQUEST, "A message collection is required");
+ if (msgCollId == null) {
+ throw new SocialSpiException(HttpServletResponse.SC_BAD_REQUEST,
+ "A message collection is required");
+ }
HandlerPreconditions.requireNotEmpty(messageIds, "No message IDs specified");
@@ -134,12 +139,18 @@
UserId user = request.getUsers().iterator().next();
- if (msgCollId == null) throw new SocialSpiException(ResponseError.BAD_REQUEST, "A message collection is required");
+ if (msgCollId == null) {
+ throw new SocialSpiException(HttpServletResponse.SC_BAD_REQUEST,
+ "A message collection is required");
+ }
if (messageIds.size() == 0) {
// No message IDs specified, this is a PUT to a message collection
MessageCollection msgCollection = request.getTypedParameter("entity", MessageCollection.class);
- if (msgCollection == null) throw new SocialSpiException(ResponseError.BAD_REQUEST, "cannot parse message collection");
+ if (msgCollection == null) {
+ throw new SocialSpiException(HttpServletResponse.SC_BAD_REQUEST,
+ "cannot parse message collection");
+ }
// TODO, do more validation.
@@ -151,7 +162,10 @@
Message message = request.getTypedParameter("entity", Message.class);
// TODO, do more validation.
- if (message == null || message.getId() == null) throw new SocialSpiException(ResponseError.BAD_REQUEST, "cannot parse message or missing ID");
+ if (message == null || message.getId() == null) {
+ throw new SocialSpiException(HttpServletResponse.SC_BAD_REQUEST,
+ "cannot parse message or missing ID");
+ }
return service.modifyMessage(user, msgCollId, messageIds.get(0), message, request.getToken());
}
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/SocialSpiException.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/SocialSpiException.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/SocialSpiException.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/spi/SocialSpiException.java Tue Apr 21 19:02:36 2009
@@ -19,18 +19,17 @@
package org.apache.shindig.social.opensocial.spi;
import org.apache.shindig.protocol.ProtocolException;
-import org.apache.shindig.protocol.ResponseError;
/**
* Convenience subclass of ProtocolException to ease transition
*/
public class SocialSpiException extends ProtocolException {
- public SocialSpiException(ResponseError error, String errorMessage, Throwable cause) {
+ public SocialSpiException(int error, String errorMessage, Throwable cause) {
super(error, errorMessage, cause);
}
- public SocialSpiException(ResponseError error, String errorMessage) {
+ public SocialSpiException(int error, String errorMessage) {
super(error, errorMessage);
}
}
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/service/SampleContainerHandler.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/service/SampleContainerHandler.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/service/SampleContainerHandler.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/service/SampleContainerHandler.java Tue Apr 21 19:02:36 2009
@@ -24,18 +24,19 @@
import org.apache.shindig.common.util.ImmediateFuture;
import org.apache.shindig.protocol.Operation;
import org.apache.shindig.protocol.RequestItem;
-import org.apache.shindig.protocol.ResponseError;
import org.apache.shindig.protocol.Service;
import org.apache.shindig.social.opensocial.spi.SocialSpiException;
import org.apache.shindig.social.sample.spi.JsonDbOpensocialService;
-
-import com.google.inject.Inject;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.concurrent.Future;
+import javax.servlet.http.HttpServletResponse;
+
+import com.google.inject.Inject;
+
@Service(name = "samplecontainer", path = "/{type}/{doevil}")
public class SampleContainerHandler {
@@ -66,11 +67,11 @@
String stateFile = request.getParameter("fileurl");
service.setDb(new JSONObject(fetchStateDocument(stateFile)));
} catch (JSONException e) {
- throw new SocialSpiException(ResponseError.BAD_REQUEST,
+ throw new SocialSpiException(HttpServletResponse.SC_BAD_REQUEST,
"The json state file was not valid json", e);
}
} else if (type.equals("setevilness")) {
- throw new SocialSpiException(ResponseError.NOT_IMPLEMENTED,
+ throw new SocialSpiException(HttpServletResponse.SC_NOT_IMPLEMENTED,
"evil data has not been implemented yet");
}
Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java Tue Apr 21 19:02:36 2009
@@ -23,14 +23,13 @@
import org.apache.shindig.common.util.ImmediateFuture;
import org.apache.shindig.common.util.ResourceLoader;
import org.apache.shindig.protocol.DataCollection;
-import org.apache.shindig.protocol.ResponseError;
import org.apache.shindig.protocol.RestfulCollection;
import org.apache.shindig.protocol.conversion.BeanConverter;
import org.apache.shindig.protocol.model.SortOrder;
import org.apache.shindig.social.opensocial.model.Activity;
import org.apache.shindig.social.opensocial.model.Message;
-import org.apache.shindig.social.opensocial.model.Person;
import org.apache.shindig.social.opensocial.model.MessageCollection;
+import org.apache.shindig.social.opensocial.model.Person;
import org.apache.shindig.social.opensocial.spi.ActivityService;
import org.apache.shindig.social.opensocial.spi.AppDataService;
import org.apache.shindig.social.opensocial.spi.CollectionOptions;
@@ -39,14 +38,6 @@
import org.apache.shindig.social.opensocial.spi.PersonService;
import org.apache.shindig.social.opensocial.spi.SocialSpiException;
import org.apache.shindig.social.opensocial.spi.UserId;
-
-import com.google.common.collect.ImmutableSortedSet;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.google.inject.name.Named;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -59,6 +50,16 @@
import java.util.Set;
import java.util.concurrent.Future;
+import javax.servlet.http.HttpServletResponse;
+
+import com.google.common.collect.ImmutableSortedSet;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.google.inject.name.Named;
+
/**
* Implementation of supported services backed by a JSON DB.
*/
@@ -115,8 +116,9 @@
private static final String PASSWORDS_TABLE = "passwords";
@Inject
- public JsonDbOpensocialService(@Named("shindig.canonical.json.db")String jsonLocation,
- @Named("shindig.bean.converter.json")BeanConverter converter) throws Exception {
+ public JsonDbOpensocialService(@Named("shindig.canonical.json.db")
+ String jsonLocation, @Named("shindig.bean.converter.json")
+ BeanConverter converter) throws Exception {
String content = IOUtils.toString(ResourceLoader.openResource(jsonLocation), "UTF-8");
this.db = new JSONObject(content);
this.converter = converter;
@@ -130,9 +132,9 @@
this.db = db;
}
- public Future<RestfulCollection<Activity>> getActivities(Set<UserId> userIds,
- GroupId groupId, String appId, Set<String> fields, CollectionOptions options, SecurityToken token)
- throws SocialSpiException {
+ public Future<RestfulCollection<Activity>> getActivities(Set<UserId> userIds, GroupId groupId,
+ String appId, Set<String> fields, CollectionOptions options, SecurityToken token)
+ throws SocialSpiException {
List<Activity> result = Lists.newArrayList();
try {
Set<String> idSet = getIdSet(userIds, groupId, token);
@@ -151,13 +153,14 @@
}
return ImmediateFuture.newInstance(new RestfulCollection<Activity>(result));
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
- public Future<RestfulCollection<Activity>> getActivities(UserId userId,
- GroupId groupId, String appId, Set<String> fields, CollectionOptions options,
- Set<String> activityIds, SecurityToken token) throws SocialSpiException {
+ public Future<RestfulCollection<Activity>> getActivities(UserId userId, GroupId groupId,
+ String appId, Set<String> fields, CollectionOptions options, Set<String> activityIds,
+ SecurityToken token) throws SocialSpiException {
List<Activity> result = Lists.newArrayList();
try {
String user = userId.getUserId(token);
@@ -173,13 +176,13 @@
}
return ImmediateFuture.newInstance(new RestfulCollection<Activity>(result));
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
- public Future<Activity> getActivity(UserId userId,
- GroupId groupId, String appId, Set<String> fields, String activityId, SecurityToken token)
- throws SocialSpiException {
+ public Future<Activity> getActivity(UserId userId, GroupId groupId, String appId,
+ Set<String> fields, String activityId, SecurityToken token) throws SocialSpiException {
try {
String user = userId.getUserId(token);
if (db.getJSONObject(ACTIVITIES_TABLE).has(user)) {
@@ -193,9 +196,10 @@
}
}
- throw new SocialSpiException(ResponseError.BAD_REQUEST, "Activity not found");
+ throw new SocialSpiException(HttpServletResponse.SC_BAD_REQUEST, "Activity not found");
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
@@ -214,16 +218,18 @@
}
}
db.getJSONObject(ACTIVITIES_TABLE).put(user, newList);
- // TODO. This seems very odd that we return no useful response in this case
+ // TODO. This seems very odd that we return no useful response in this
+ // case
// There is no way to represent not-found
// if (found) { ??
- //}
+ // }
}
}
// What is the appropriate response here??
return ImmediateFuture.newInstance(null);
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
@@ -244,13 +250,13 @@
jsonArray.put(jsonObject);
return ImmediateFuture.newInstance(null);
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
- public Future<RestfulCollection<Person>> getPeople(Set<UserId> userIds,
- GroupId groupId, CollectionOptions options, Set<String> fields, SecurityToken token)
- throws SocialSpiException {
+ public Future<RestfulCollection<Person>> getPeople(Set<UserId> userIds, GroupId groupId,
+ CollectionOptions options, Set<String> fields, SecurityToken token) throws SocialSpiException {
List<Person> result = Lists.newArrayList();
try {
JSONArray people = db.getJSONArray(PEOPLE_TABLE);
@@ -273,7 +279,7 @@
}
if (GroupId.Type.self == groupId.getType() && result.isEmpty()) {
- throw new SocialSpiException(ResponseError.BAD_REQUEST, "Person not found");
+ throw new SocialSpiException(HttpServletResponse.SC_BAD_REQUEST, "Person not found");
}
// We can pretend that by default the people are in top friends order
@@ -292,33 +298,34 @@
int last = options.getFirst() + options.getMax();
result = result.subList(options.getFirst(), Math.min(last, totalSize));
- return ImmediateFuture.newInstance(new RestfulCollection<Person>(
- result, options.getFirst(), totalSize));
+ return ImmediateFuture.newInstance(new RestfulCollection<Person>(result, options.getFirst(),
+ totalSize));
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
- public Future<Person> getPerson(UserId id, Set<String> fields,
- SecurityToken token) throws SocialSpiException {
+ public Future<Person> getPerson(UserId id, Set<String> fields, SecurityToken token)
+ throws SocialSpiException {
try {
JSONArray people = db.getJSONArray(PEOPLE_TABLE);
for (int i = 0; i < people.length(); i++) {
JSONObject person = people.getJSONObject(i);
- if (id != null && person.get(Person.Field.ID.toString())
- .equals(id.getUserId(token))) {
+ if (id != null && person.get(Person.Field.ID.toString()).equals(id.getUserId(token))) {
Person personObj = filterFields(person, fields, Person.class);
- Map<String, Object> appData = getPersonAppData(
- person.getString(Person.Field.ID.toString()), fields);
+ Map<String, Object> appData = getPersonAppData(person.getString(Person.Field.ID
+ .toString()), fields);
personObj.setAppData(appData);
-
+
return ImmediateFuture.newInstance(personObj);
}
}
- throw new SocialSpiException(ResponseError.BAD_REQUEST, "Person not found");
+ throw new SocialSpiException(HttpServletResponse.SC_BAD_REQUEST, "Person not found");
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
@@ -328,13 +335,13 @@
JSONObject personData = db.getJSONObject(DATA_TABLE).optJSONObject(id);
if (personData != null) {
if (fields.contains(Person.Field.APP_DATA.toString())) {
- appData = Maps.newHashMap();
- @SuppressWarnings("unchecked")
- Iterator<String> keys = personData.keys();
- while (keys.hasNext()) {
- String key = keys.next();
- appData.put(key, personData.get(key));
- }
+ appData = Maps.newHashMap();
+ @SuppressWarnings("unchecked")
+ Iterator<String> keys = personData.keys();
+ while (keys.hasNext()) {
+ String key = keys.next();
+ appData.put(key, personData.get(key));
+ }
} else {
String appDataPrefix = Person.Field.APP_DATA.toString() + ".";
for (String field : fields) {
@@ -342,7 +349,7 @@
if (appData == null) {
appData = Maps.newHashMap();
}
-
+
String appDataField = field.substring(appDataPrefix.length());
if (personData.has(appDataField)) {
appData.put(appDataField, personData.get(appDataField));
@@ -351,15 +358,16 @@
}
}
}
-
+
return appData;
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
- public Future<DataCollection> getPersonData(Set<UserId> userIds, GroupId groupId,
- String appId, Set<String> fields, SecurityToken token) throws SocialSpiException {
+ public Future<DataCollection> getPersonData(Set<UserId> userIds, GroupId groupId, String appId,
+ Set<String> fields, SecurityToken token) throws SocialSpiException {
try {
Map<String, Map<String, String>> idToData = Maps.newHashMap();
Set<String> idSet = getIdSet(userIds, groupId, token);
@@ -369,16 +377,15 @@
personData = new JSONObject();
} else {
if (!fields.isEmpty()) {
- personData = new JSONObject(
- db.getJSONObject(DATA_TABLE).getJSONObject(id),
- fields.toArray(new String[fields.size()]));
+ personData = new JSONObject(db.getJSONObject(DATA_TABLE).getJSONObject(id), fields
+ .toArray(new String[fields.size()]));
} else {
personData = db.getJSONObject(DATA_TABLE).getJSONObject(id);
}
}
// TODO: We can use the converter here to do this for us
-
+
// JSONObject keys are always strings
@SuppressWarnings("unchecked")
Iterator<String> keys = personData.keys();
@@ -391,7 +398,8 @@
}
return ImmediateFuture.newInstance(new DataCollection(idToData));
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
@@ -417,15 +425,18 @@
db.getJSONObject(DATA_TABLE).put(user, newPersonData);
return ImmediateFuture.newInstance(null);
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
public Future<Void> updatePersonData(UserId userId, GroupId groupId, String appId,
Set<String> fields, Map<String, String> values, SecurityToken token)
throws SocialSpiException {
- // TODO: this seems redundant. No need to pass both fields and a map of field->value
- // TODO: According to rest, yes there is. If a field is in the param list but not in the map
+ // TODO: this seems redundant. No need to pass both fields and a map of
+ // field->value
+ // TODO: According to rest, yes there is. If a field is in the param list
+ // but not in the map
// that means it is a delete
try {
@@ -440,31 +451,36 @@
}
return ImmediateFuture.newInstance(null);
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
/**
* Post a message for a set of users.
*
- * @param userId The user sending the message.
- * @param appId The application sending the message.
+ * @param userId
+ * The user sending the message.
+ * @param appId
+ * The application sending the message.
* @param msgCollId
- * @param message The message to post.
+ * @param message
+ * The message to post.
*/
public Future<Void> createMessage(UserId userId, String appId, String msgCollId, Message message,
- SecurityToken token) throws SocialSpiException {
+ SecurityToken token) throws SocialSpiException {
for (String recipient : message.getRecipients()) {
- try {
- JSONArray outbox = db.getJSONObject(MESSAGE_TABLE).getJSONArray(recipient);
- if (outbox == null) {
- outbox = new JSONArray();
- db.getJSONObject(MESSAGE_TABLE).put(recipient, outbox);
- }
+ try {
+ JSONArray outbox = db.getJSONObject(MESSAGE_TABLE).getJSONArray(recipient);
+ if (outbox == null) {
+ outbox = new JSONArray();
+ db.getJSONObject(MESSAGE_TABLE).put(recipient, outbox);
+ }
outbox.put(message);
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
@@ -472,81 +488,88 @@
}
public Future<RestfulCollection<MessageCollection>> getMessageCollections(UserId userId,
- Set<String> fields, CollectionOptions options, SecurityToken token) throws SocialSpiException
- {
+ Set<String> fields, CollectionOptions options, SecurityToken token) throws SocialSpiException {
try {
- List<MessageCollection> result = Lists.newArrayList();
- JSONObject messageCollections = db.getJSONObject(MESSAGE_TABLE).getJSONObject(userId.getUserId(token));
- for (String msgCollId : JSONObject.getNames(messageCollections)) {
- JSONObject msgColl = messageCollections.getJSONObject(msgCollId);
- msgColl.put("id", msgCollId);
- JSONArray messages = msgColl.getJSONArray("messages");
- int numMessages = (messages == null) ? 0 : messages.length();
- msgColl.put("total", String.valueOf(numMessages));
- msgColl.put("unread", String.valueOf(numMessages));
+ List<MessageCollection> result = Lists.newArrayList();
+ JSONObject messageCollections = db.getJSONObject(MESSAGE_TABLE).getJSONObject(
+ userId.getUserId(token));
+ for (String msgCollId : JSONObject.getNames(messageCollections)) {
+ JSONObject msgColl = messageCollections.getJSONObject(msgCollId);
+ msgColl.put("id", msgCollId);
+ JSONArray messages = msgColl.getJSONArray("messages");
+ int numMessages = (messages == null) ? 0 : messages.length();
+ msgColl.put("total", String.valueOf(numMessages));
+ msgColl.put("unread", String.valueOf(numMessages));
-
- result.add(filterFields(msgColl, fields, MessageCollection.class));
- }
- return ImmediateFuture.newInstance(new RestfulCollection<MessageCollection>(result));
+ result.add(filterFields(msgColl, fields, MessageCollection.class));
+ }
+ return ImmediateFuture.newInstance(new RestfulCollection<MessageCollection>(result));
} catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
}
}
-
public Future<Void> deleteMessages(UserId userId, String msgCollId, List<String> ids,
SecurityToken token) throws SocialSpiException {
- throw new SocialSpiException(ResponseError.NOT_IMPLEMENTED, "this functionality is not yet available");
-
+ throw new SocialSpiException(HttpServletResponse.SC_NOT_IMPLEMENTED,
+ "this functionality is not yet available");
}
/**
* Gets the messsages in an user's queue.
*/
- public Future<RestfulCollection<Message>> getMessages(UserId userId, String msgCollId, Set<String> fields,
- List<String> msgIds, CollectionOptions options, SecurityToken token) throws SocialSpiException {
- try {
- List<Message> result = Lists.newArrayList();
- JSONArray messages = db.getJSONObject(MESSAGE_TABLE).getJSONObject(userId.getUserId(token)).getJSONObject(msgCollId).getJSONArray("messages");
+ public Future<RestfulCollection<Message>> getMessages(UserId userId, String msgCollId,
+ Set<String> fields, List<String> msgIds, CollectionOptions options, SecurityToken token)
+ throws SocialSpiException {
+ try {
+ List<Message> result = Lists.newArrayList();
+ JSONArray messages = db.getJSONObject(MESSAGE_TABLE).getJSONObject(userId.getUserId(token))
+ .getJSONObject(msgCollId).getJSONArray("messages");
- // TODO: special case @all
+ // TODO: special case @all
- if (messages == null) {
- throw new SocialSpiException(ResponseError.BAD_REQUEST, "message collection" + msgCollId + " not found");
- }
-
- // TODO: filter and sort outbox.
- for (int i = 0; i < messages.length(); i++) {
- JSONObject msg = messages.getJSONObject(i);
- result.add(filterFields(msg, fields, Message.class));
- }
-
- return ImmediateFuture.newInstance(new RestfulCollection<Message>(result));
-
- } catch (JSONException je) {
- throw new SocialSpiException(ResponseError.INTERNAL_ERROR, je.getMessage(), je);
+ if (messages == null) {
+ throw new SocialSpiException(HttpServletResponse.SC_BAD_REQUEST, "message collection"
+ + msgCollId + " not found");
}
+
+ // TODO: filter and sort outbox.
+ for (int i = 0; i < messages.length(); i++) {
+ JSONObject msg = messages.getJSONObject(i);
+ result.add(filterFields(msg, fields, Message.class));
+ }
+
+ return ImmediateFuture.newInstance(new RestfulCollection<Message>(result));
+
+ } catch (JSONException je) {
+ throw new SocialSpiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
+ je);
+ }
}
- public Future<MessageCollection> createMessageCollection(UserId userId, MessageCollection msgCollection, SecurityToken token)
- throws SocialSpiException {
- throw new SocialSpiException(ResponseError.NOT_IMPLEMENTED, "this functionality is not yet available");
+ public Future<MessageCollection> createMessageCollection(UserId userId,
+ MessageCollection msgCollection, SecurityToken token) throws SocialSpiException {
+ throw new SocialSpiException(HttpServletResponse.SC_NOT_IMPLEMENTED,
+ "this functionality is not yet available");
}
- public Future<Void> modifyMessage(UserId userId, String msgCollId, String messageId, Message message, SecurityToken token)
- throws SocialSpiException {
- throw new SocialSpiException(ResponseError.NOT_IMPLEMENTED, "this functionality is not yet available");
+ public Future<Void> modifyMessage(UserId userId, String msgCollId, String messageId,
+ Message message, SecurityToken token) throws SocialSpiException {
+ throw new SocialSpiException(HttpServletResponse.SC_NOT_IMPLEMENTED,
+ "this functionality is not yet available");
}
- public Future<Void> modifyMessageCollection(UserId userId, MessageCollection msgCollection, SecurityToken token)
- throws SocialSpiException {
- throw new SocialSpiException(ResponseError.NOT_IMPLEMENTED, "this functionality is not yet available");
+ public Future<Void> modifyMessageCollection(UserId userId, MessageCollection msgCollection,
+ SecurityToken token) throws SocialSpiException {
+ throw new SocialSpiException(HttpServletResponse.SC_NOT_IMPLEMENTED,
+ "this functionality is not yet available");
}
- public Future<Void> deleteMessageCollection(UserId userId, String msgCollId, SecurityToken token)
+ public Future<Void> deleteMessageCollection(UserId userId, String msgCollId, SecurityToken token)
throws SocialSpiException {
- throw new SocialSpiException(ResponseError.NOT_IMPLEMENTED, "this functionality is not yet available");
+ throw new SocialSpiException(HttpServletResponse.SC_NOT_IMPLEMENTED,
+ "this functionality is not yet available");
}
/**
@@ -556,7 +579,7 @@
try {
return db.getJSONObject(PASSWORDS_TABLE).getString(username);
} catch (JSONException e) {
- return null;
+ return null;
}
}
@@ -573,19 +596,19 @@
Set<String> returnVal = Sets.newLinkedHashSet();
switch (group.getType()) {
- case all:
- case friends:
- case groupId:
- if (db.getJSONObject(FRIEND_LINK_TABLE).has(userId)) {
- JSONArray friends = db.getJSONObject(FRIEND_LINK_TABLE).getJSONArray(userId);
- for (int i = 0; i < friends.length(); i++) {
- returnVal.add(friends.getString(i));
- }
+ case all:
+ case friends:
+ case groupId:
+ if (db.getJSONObject(FRIEND_LINK_TABLE).has(userId)) {
+ JSONArray friends = db.getJSONObject(FRIEND_LINK_TABLE).getJSONArray(userId);
+ for (int i = 0; i < friends.length(); i++) {
+ returnVal.add(friends.getString(i));
}
- break;
- case self:
- returnVal.add(userId);
- break;
+ }
+ break;
+ case self:
+ returnVal.add(userId);
+ break;
}
return returnVal;
}
@@ -602,15 +625,14 @@
return ids;
}
-
private JSONObject convertFromActivity(Activity activity, Set<String> fields)
throws JSONException {
// TODO Not using fields yet
return new JSONObject(converter.convertToString(activity));
}
-
- private <T> T filterFields(JSONObject object, Set<String> fields, Class<T> clz) throws JSONException {
+ private <T> T filterFields(JSONObject object, Set<String> fields, Class<T> clz)
+ throws JSONException {
if (!fields.isEmpty()) {
// Create a copy with just the specified fields
object = new JSONObject(object, fields.toArray(new String[fields.size()]));
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/AppDataHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/AppDataHandlerTest.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/AppDataHandlerTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/AppDataHandlerTest.java Tue Apr 21 19:02:36 2009
@@ -26,17 +26,12 @@
import org.apache.shindig.protocol.DefaultHandlerRegistry;
import org.apache.shindig.protocol.HandlerExecutionListener;
import org.apache.shindig.protocol.HandlerRegistry;
-import org.apache.shindig.protocol.ResponseError;
import org.apache.shindig.protocol.RestHandler;
import org.apache.shindig.protocol.conversion.BeanJsonConverter;
import org.apache.shindig.social.opensocial.spi.AppDataService;
import org.apache.shindig.social.opensocial.spi.GroupId;
import org.apache.shindig.social.opensocial.spi.SocialSpiException;
import org.apache.shindig.social.opensocial.spi.UserId;
-
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
import org.easymock.classextension.EasyMock;
import java.io.StringReader;
@@ -47,6 +42,11 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import javax.servlet.http.HttpServletResponse;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
public class AppDataHandlerTest extends EasyMockTestCase {
private BeanJsonConverter converter;
@@ -193,7 +193,8 @@
operation.execute(params, new StringReader(jsonAppData), token, converter).get();
fail();
} catch (ExecutionException ee) {
- assertEquals(((SocialSpiException)ee.getCause()).getError(), ResponseError.BAD_REQUEST);
+ assertEquals(((SocialSpiException)ee.getCause()).getCode(),
+ HttpServletResponse.SC_BAD_REQUEST);
// was expecting an Exception
}
verify();
@@ -222,7 +223,8 @@
operation.execute(params, new StringReader(jsonAppData), token, converter).get();
fail();
} catch (ExecutionException ee) {
- assertEquals(((SocialSpiException)ee.getCause()).getError(), ResponseError.BAD_REQUEST);
+ assertEquals(((SocialSpiException)ee.getCause()).getCode(),
+ HttpServletResponse.SC_BAD_REQUEST);
}
verify();
}
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/ResponseItemTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/ResponseItemTest.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/ResponseItemTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/ResponseItemTest.java Tue Apr 21 19:02:36 2009
@@ -17,16 +17,17 @@
*/
package org.apache.shindig.social.opensocial.service;
-import org.apache.shindig.protocol.ResponseError;
-import org.apache.shindig.protocol.ResponseItem;
-
import static junit.framework.Assert.assertFalse;
import static junitx.framework.Assert.assertNotEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
+
+import org.apache.shindig.protocol.ResponseItem;
import org.junit.Test;
+import javax.servlet.http.HttpServletResponse;
+
/**
* Tests Response Item equality methods.
@@ -35,9 +36,12 @@
@Test
public void testEquals() {
- ResponseItem responseItem = new ResponseItem(ResponseError.BAD_REQUEST, "message1");
- ResponseItem responseItemSame = new ResponseItem(ResponseError.BAD_REQUEST, "message1");
- ResponseItem responseItemDifferent = new ResponseItem(ResponseError.FORBIDDEN, "message2");
+ ResponseItem responseItem = new ResponseItem(
+ HttpServletResponse.SC_BAD_REQUEST, "message1");
+ ResponseItem responseItemSame = new ResponseItem(
+ HttpServletResponse.SC_BAD_REQUEST, "message1");
+ ResponseItem responseItemDifferent =
+ new ResponseItem(HttpServletResponse.SC_FORBIDDEN, "message2");
ResponseItem simpleResponse = new ResponseItem("simple");
ResponseItem simpleResponseSame = new ResponseItem("simple");
ResponseItem simpleResponseDifferent = new ResponseItem("simpleDiffernt");
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java?rev=767255&r1=767254&r2=767255&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java Tue Apr 21 19:02:36 2009
@@ -21,7 +21,6 @@
import org.apache.shindig.auth.SecurityToken;
import org.apache.shindig.common.testing.FakeGadgetToken;
import org.apache.shindig.protocol.DataCollection;
-import org.apache.shindig.protocol.ResponseError;
import org.apache.shindig.protocol.RestfulCollection;
import org.apache.shindig.protocol.model.FilterOperation;
import org.apache.shindig.protocol.model.SortOrder;
@@ -34,14 +33,17 @@
import org.apache.shindig.social.opensocial.spi.SocialSpiException;
import org.apache.shindig.social.opensocial.spi.UserId;
+import java.util.Collections;
+
+import javax.servlet.http.HttpServletResponse;
+
+import junit.framework.TestCase;
+
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
-import junit.framework.TestCase;
-
-import java.util.Collections;
/**
* Test the JSONOpensocialService
@@ -190,7 +192,7 @@
Sets.newHashSet("appId", "body", "mediaItems"), APP_ID, new FakeGadgetToken()).get();
fail();
} catch (SocialSpiException sse) {
- assertEquals(ResponseError.BAD_REQUEST, sse.getError());
+ assertEquals(HttpServletResponse.SC_BAD_REQUEST, sse.getCode());
}
}