private static String formatError(GadgetException excep, Uri uri) throws IOException { StringBuilder err = new StringBuilder(); err.append(excep.getCode().toString()); err.append(" concat("); err.append(uri.toString()); err.append(") "); err.append(excep.getMessage()); // Log the errors here for now. We might want different severity levels // for different error codes. LOG.log(Level.INFO, "Concat proxy request failed", err); return err.toString(); }
private static String formatError(String methodname, GadgetException excep, Uri uri) throws IOException { StringBuilder err = new StringBuilder(); err.append("/* ---- Error "); err.append(excep.getCode().toString()); err.append(" concat("); err.append(uri.toString()); err.append(") "); err.append(excep.getMessage()); err.append(" ---- */"); // Log the errors here for now. We might want different severity levels // for different error codes. if (LOG.isLoggable(Level.INFO)) { LOG.logp(Level.INFO, classname, methodname, MessageKeys.CONCAT_PROXY_REQUEST_FAILED, new Object[] {err.toString()}); } return err.toString(); }
private static String formatError(GadgetException excep, Uri uri) throws IOException { StringBuilder err = new StringBuilder(); err.append(excep.getCode().toString()); err.append(" concat("); err.append(uri.toString()); err.append(") "); err.append(excep.getMessage()); // Log the errors here for now. We might want different severity levels // for different error codes. LOG.log(Level.INFO, "Concat proxy request failed", err); return err.toString(); }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { try { makeRequestHandler.fetch(request, response); } catch (GadgetException e) { if (LOG.isLoggable(Level.FINEST)) { LOG.logp(Level.FINEST, classname, "doGet", MessageKeys.HTTP_ERROR_FETCHING, e); } int responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; if (e.getCode() != GadgetException.Code.INTERNAL_SERVER_ERROR) { responseCode = HttpServletResponse.SC_BAD_REQUEST; } response.sendError(responseCode, e.getMessage() != null ? e.getMessage() : ""); } }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { try { makeRequestHandler.fetch(request, response); } catch (GadgetException e) { int responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; if (e.getCode() != GadgetException.Code.INTERNAL_SERVER_ERROR) { responseCode = HttpServletResponse.SC_BAD_REQUEST; } response.sendError(responseCode, e.getMessage() != null ? e.getMessage() : ""); } }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { try { makeRequestHandler.fetch(request, response); } catch (GadgetException e) { int responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; if (e.getCode() != GadgetException.Code.INTERNAL_SERVER_ERROR) { responseCode = HttpServletResponse.SC_BAD_REQUEST; } response.sendError(responseCode, e.getMessage() != null ? e.getMessage() : ""); } }
@Test public void testSetResponseHeadersForceParamInvalid() throws Exception { HttpResponse results = new HttpResponseBuilder().create(); expect(request.getParameter(Param.REFRESH.getKey())).andReturn("foo").anyTimes(); replay(); try { handler.setResponseHeaders(request, recorder, results); } catch (GadgetException e) { assertEquals(GadgetException.Code.INVALID_PARAMETER, e.getCode()); } }
@Test public void testSetResponseHeadersForceParamInvalid() throws Exception { HttpResponse results = new HttpResponseBuilder().create(); expect(request.getParameter(Param.REFRESH.getKey())).andReturn("foo").anyTimes(); replay(); try { handler.setResponseHeaders(request, recorder, results); } catch (GadgetException e) { assertEquals(GadgetException.Code.INVALID_PARAMETER, e.getCode()); } }
@Test public void testSetResponseHeadersForceParamInvalid() throws Exception { HttpResponse results = new HttpResponseBuilder().create(); expect(request.getParameter(Param.REFRESH.getKey())).andReturn("foo").anyTimes(); replay(); try { MakeRequestHandler.setResponseHeaders(request, recorder, results); } catch (GadgetException e) { assertEquals(GadgetException.Code.INVALID_PARAMETER, e.getCode()); } }
@Test public void unavailableFeatureCrashes() throws Exception { Uri featUri = expectResource(xml(BAD_DEP_TPL, "gadget", null, "content")); try { registry = new TestFeatureRegistry(featUri.toString()); } catch (GadgetException e) { assertEquals(GadgetException.Code.INVALID_CONFIG, e.getCode()); } }
@Test public void missingIndexResultsInException() throws Exception { try { registry = new TestFeatureRegistry(makeResourceUri(".txt").toString()); fail("Should have thrown an exception for missing .txt file"); } catch (GadgetException e) { // Expected. Verify code. assertEquals(GadgetException.Code.INVALID_PATH, e.getCode()); } }
@Test public void unavailableFeatureCrashes() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); Uri featUri = builder.expectResource(xml(BAD_DEP_TPL, "gadget", null, "content")); try { registry = builder.build(featUri.toString()); } catch (GadgetException e) { assertEquals(GadgetException.Code.INVALID_CONFIG, e.getCode()); } }
@Test public void unavailableFeatureCrashes() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); Uri featUri = builder.expectResource(xml(BAD_DEP_TPL, "gadget", null, "content")); try { registry = builder.build(featUri.toString()); } catch (GadgetException e) { assertEquals(GadgetException.Code.INVALID_CONFIG, e.getCode()); } }
@Test public void missingIndexResultsInException() throws Exception { try { registry = TestFeatureRegistry.newBuilder().build(makeResourceUri(".txt").toString()); fail("Should have thrown an exception for missing .txt file"); } catch (GadgetException e) { // Expected. Verify code. assertEquals(GadgetException.Code.INVALID_PATH, e.getCode()); } }
@Test public void missingIndexResultsInException() throws Exception { try { registry = TestFeatureRegistry.newBuilder().build(makeResourceUri(".txt").toString()); fail("Should have thrown an exception for missing .txt file"); } catch (GadgetException e) { // Expected. Verify code. assertEquals(GadgetException.Code.INVALID_PATH, e.getCode()); } }
@Test public void GetRequestWithNonWhitelistedGadget() throws Exception { reset(gadgetAdminStore); expect(gadgetAdminStore.isWhitelisted(isA(String.class), isA(String.class))).andReturn(false); replay(); boolean exceptionThrown = false; try { handler.fetch(request, recorder); } catch (GadgetException e) { exceptionThrown = true; assertEquals(403, e.getHttpStatusCode()); assertEquals(GadgetException.Code.NON_WHITELISTED_GADGET, e.getCode()); } assertTrue(exceptionThrown); verify(); }
@Test public void GetRequestWithNonWhitelistedGadget() throws Exception { reset(gadgetAdminStore); expect(gadgetAdminStore.isWhitelisted(isA(String.class), isA(String.class))).andReturn(false); replay(); boolean exceptionThrown = false; try { handler.fetch(request, recorder); } catch (GadgetException e) { exceptionThrown = true; assertEquals(403, e.getHttpStatusCode()); assertEquals(GadgetException.Code.NON_WHITELISTED_GADGET, e.getCode()); } assertTrue(exceptionThrown); verify(); }
@Test public void missingFileResultsInException() throws Exception { try { registry = TestFeatureRegistry.newBuilder().build(new UriBuilder().setScheme("file") .setPath("/is/not/there.foo.xml").toUri().toString()); fail("Should have thrown missing .xml file exception"); } catch (GadgetException e) { // Expected. Verify code. assertEquals(GadgetException.Code.INVALID_CONFIG, e.getCode()); } }
@Test public void missingFileResultsInException() throws Exception { try { registry = TestFeatureRegistry.newBuilder().build(new UriBuilder().setScheme("file") .setPath("/is/not/there.foo.xml").toUri().toString()); fail("Should have thrown missing .xml file exception"); } catch (GadgetException e) { // Expected. Verify code. assertEquals(GadgetException.Code.INVALID_CONFIG, e.getCode()); } }
@Test public void missingFileResultsInException() throws Exception { try { registry = new TestFeatureRegistry(new UriBuilder().setScheme("file") .setPath("/is/not/there.foo.xml").toUri().toString()); fail("Should have thrown missing .xml file exception"); } catch (GadgetException e) { // Expected. Verify code. assertEquals(GadgetException.Code.INVALID_CONFIG, e.getCode()); } }