protected ResponseItem responseItemFromException(Throwable t) { if (t instanceof ProtocolException) { ProtocolException pe = (ProtocolException) t; if (LOG.isLoggable(Level.INFO)) { LOG.logp(Level.INFO, classname, "responseItemFromException", MessageKeys.API_SERVLET_PROTOCOL_EXCEPTION,pe); } return new ResponseItem(pe.getCode(), pe.getMessage(), pe.getResponse()); } if (LOG.isLoggable(Level.INFO)) { LOG.logp(Level.INFO, classname, "responseItemFromException", MessageKeys.API_SERVLET_EXCEPTION,t); } return new ResponseItem(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, t.getMessage()); }
protected ResponseItem responseItemFromException(Throwable t) { if (t instanceof ProtocolException) { ProtocolException pe = (ProtocolException) t; if (LOG.isLoggable(Level.INFO)) { LOG.logp(Level.INFO, classname, "responseItemFromException", MessageKeys.API_SERVLET_PROTOCOL_EXCEPTION,pe); } return new ResponseItem(pe.getCode(), pe.getMessage(), pe.getResponse()); } if (LOG.isLoggable(Level.INFO)) { LOG.logp(Level.INFO, classname, "responseItemFromException", MessageKeys.API_SERVLET_EXCEPTION,t); } return new ResponseItem(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, t.getMessage()); }
protected ResponseItem responseItemFromException(Throwable t) { if (t instanceof ProtocolException) { ProtocolException pe = (ProtocolException) t; if (LOG.isLoggable(Level.INFO)) { LOG.logp(Level.INFO, classname, "responseItemFromException", MessageKeys.API_SERVLET_PROTOCOL_EXCEPTION,pe); } return new ResponseItem(pe.getCode(), pe.getMessage(), pe.getResponse()); } if (LOG.isLoggable(Level.INFO)) { LOG.logp(Level.INFO, classname, "responseItemFromException", MessageKeys.API_SERVLET_EXCEPTION,t); } return new ResponseItem(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, t.getMessage()); }
protected ResponseItem responseItemFromException(Throwable t) { if (t instanceof ProtocolException) { ProtocolException pe = (ProtocolException) t; LOG.log(Level.INFO, "Returning a response error as result of a protocol exception", pe); return new ResponseItem(pe.getCode(), pe.getMessage(), pe.getResponse()); } LOG.log(Level.WARNING, "Returning a response error as result of an exception", t); return new ResponseItem(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, t.getMessage()); }
protected ResponseItem responseItemFromException(Throwable t) { if (t instanceof ProtocolException) { ProtocolException pe = (ProtocolException) t; LOG.log(Level.INFO, "Returning a response error as result of a protocol exception", pe); return new ResponseItem(pe.getCode(), pe.getMessage(), pe.getResponse()); } LOG.log(Level.WARNING, "Returning a response error as result of an exception", t); return new ResponseItem(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, t.getMessage()); }
@Test public void testRestHandler_serviceDoesntExist() { RestHandler restHandler = registry.getRestHandler("/makebelieve", "GET"); try { Future<?> future = restHandler.execute(Maps.<String, String[]>newHashMap(), null, null, null); future.get(); fail("Expect exception for missing method"); } catch (ExecutionException t) { assertSame(t.getCause().getClass(), ProtocolException.class); Assert.assertEquals(HttpServletResponse.SC_NOT_IMPLEMENTED, ((ProtocolException) t.getCause()).getCode()); } catch (Throwable t) { fail("Unexpected exception " + t.toString()); } }
@Test public void testRestHandler_serviceDoesntExist() { RestHandler restHandler = registry.getRestHandler("/makebelieve", "GET"); try { Future<?> future = restHandler.execute(Maps.<String, String[]>newHashMap(), null, null, null); future.get(); fail("Expect exception for missing method"); } catch (ExecutionException t) { assertSame(t.getCause().getClass(), ProtocolException.class); Assert.assertEquals(HttpServletResponse.SC_NOT_IMPLEMENTED, ((ProtocolException) t.getCause()).getCode()); } catch (Throwable t) { fail("Unexpected exception " + t.toString()); } }
@Test public void testRestHandler_serviceDoesntExist() { RestHandler restHandler = registry.getRestHandler("/makebelieve", "GET"); try { Future<?> future = restHandler.execute(Maps.<String, String[]>newHashMap(), null, null, null); future.get(); fail("Expect exception for missing method"); } catch (ExecutionException t) { assertSame(t.getCause().getClass(), ProtocolException.class); Assert.assertEquals(HttpServletResponse.SC_NOT_IMPLEMENTED, ((ProtocolException) t.getCause()).getCode()); } catch (Throwable t) { fail("Unexpected exception " + t.toString()); } }
@Test public void testRpcHandler_serviceDoesntExist() throws Exception { JSONObject rpc = new JSONObject("{method : makebelieve.get}"); RpcHandler rpcHandler = registry.getRpcHandler(rpc); try { Future<?> future = rpcHandler.execute(null, null, null); future.get(); fail("Expect exception for missing method"); } catch (ExecutionException t) { assertSame(t.getCause().getClass(), ProtocolException.class); Assert.assertEquals(HttpServletResponse.SC_NOT_IMPLEMENTED, ((ProtocolException) t.getCause()).getCode()); } catch (Throwable t) { fail("Unexpected exception " + t.toString()); } }
@Test public void testRestHandler_serviceDoesntExist() { RestHandler restHandler = registry.getRestHandler("/makebelieve", "GET"); try { Future<?> future = restHandler.execute(Maps.<String, String[]>newHashMap(), null, null, null); future.get(); fail("Expect exception for missing method"); } catch (ExecutionException t) { assertSame(t.getCause().getClass(), ProtocolException.class); Assert.assertEquals(HttpServletResponse.SC_NOT_IMPLEMENTED, ((ProtocolException) t.getCause()).getCode()); } catch (Throwable t) { fail("Unexpected exception " + t.toString()); } }
@Test public void testDeleteExpectedActivityEntry() throws Exception { db.deleteActivityEntries(JOHN_DOE, SELF_GROUP, APP_ID, ImmutableSet.of(APP_ID), new FakeGadgetToken()); // Try to fetch the activity try { db.getActivityEntry( JOHN_DOE, SELF_GROUP, APP_ID, ImmutableSet.of("body"), APP_ID, new FakeGadgetToken()).get(); fail(); } catch (ProtocolException sse) { assertEquals(HttpServletResponse.SC_BAD_REQUEST, sse.getCode()); } }
@Test public void testDeleteExpectedActivity() throws Exception { db.deleteActivities(CANON_USER, SELF_GROUP, APP_ID, ImmutableSet.of(APP_ID), new FakeGadgetToken()); // Try to fetch the activity try { db.getActivity( CANON_USER, SELF_GROUP, APP_ID, ImmutableSet.of("appId", "body", "mediaItems"), APP_ID, new FakeGadgetToken()).get(); fail(); } catch (ProtocolException sse) { assertEquals(HttpServletResponse.SC_BAD_REQUEST, sse.getCode()); } }
@Test public void testDeleteExpectedActivity() throws Exception { db.deleteActivities(CANON_USER, SELF_GROUP, APP_ID, ImmutableSet.of(APP_ID), new FakeGadgetToken()); // Try to fetch the activity try { db.getActivity( CANON_USER, SELF_GROUP, APP_ID, ImmutableSet.of("appId", "body", "mediaItems"), APP_ID, new FakeGadgetToken()).get(); fail(); } catch (ProtocolException sse) { assertEquals(HttpServletResponse.SC_BAD_REQUEST, sse.getCode()); } }
@Test public void testDeleteExpectedActivityEntry() throws Exception { db.deleteActivityEntries(JOHN_DOE, SELF_GROUP, APP_ID, ImmutableSet.of(APP_ID), new FakeGadgetToken()); // Try to fetch the activity try { db.getActivityEntry( JOHN_DOE, SELF_GROUP, APP_ID, ImmutableSet.of("body"), APP_ID, new FakeGadgetToken()).get(); fail(); } catch (ProtocolException sse) { assertEquals(HttpServletResponse.SC_BAD_REQUEST, sse.getCode()); } }
@Test public void testDeleteExpectedActivity() throws Exception { db.deleteActivities(CANON_USER, SELF_GROUP, APP_ID, ImmutableSet.of(APP_ID), new FakeGadgetToken()); // Try to fetch the activity try { db.getActivity( CANON_USER, SELF_GROUP, APP_ID, ImmutableSet.of("appId", "body", "mediaItems"), APP_ID, new FakeGadgetToken()).get(); fail(); } catch (ProtocolException sse) { assertEquals(HttpServletResponse.SC_BAD_REQUEST, sse.getCode()); } }
@Test public void testGetInvalidJsonTypedParameter() throws Exception { request.setParameter("anykey", "{name: 'Bob"); int code = 0; try { request.getTypedParameter("anykey", InputData.class); } catch(ProtocolException e) { code = e.getCode(); } assertEquals(HttpServletResponse.SC_BAD_REQUEST, code); }
@Test public void testGetInvalidJsonTypedParameter() throws Exception { request.setParameter("anykey", "{name: 'Bob"); int code = 0; try { request.getTypedParameter("anykey", InputData.class); } catch(ProtocolException e) { code = e.getCode(); } assertEquals(HttpServletResponse.SC_BAD_REQUEST, code); }
@Test public void testGetInvalidJsonTypedParameter() throws Exception { request.setParameter("anykey", "{name: 'Bob"); int code = 0; try { request.getTypedParameter("anykey", InputData.class); } catch(ProtocolException e) { code = e.getCode(); } assertEquals(HttpServletResponse.SC_BAD_REQUEST, code); }
@Test public void testGetInvalidJsonTypedParameter() throws Exception { request.setParameter("anykey", "{name: 'Bob"); int code = 0; try { request.getTypedParameter("anykey", InputData.class); } catch(ProtocolException e) { code = e.getCode(); } assertEquals(HttpServletResponse.SC_BAD_REQUEST, code); }
@Test public void testGetInvalidJsonTypedParameter() throws Exception { request.setParameter("anykey", "{name: 'Bob"); int code = 0; try { request.getTypedParameter("anykey", InputData.class); } catch(ProtocolException e) { code = e.getCode(); } assertEquals(HttpServletResponse.SC_BAD_REQUEST, code); }