public FeatureRegistry get(String repository) throws GadgetException { if (repository == null) { return registry; } throw new GadgetException(Code.INVALID_PARAMETER, "Repository is not supported", HttpResponse.SC_BAD_REQUEST); } }
(resourceUri != null ? resourceUri.toString() : "n/a") + " made to wrong domain " + host; LOG.info(msg); throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, msg, HttpResponse.SC_BAD_REQUEST); response = ServletUtil.errorResponse(new GadgetException(e.getCode(), e.getMessage(), HttpServletResponse.SC_BAD_REQUEST));
/** * @return An HttpResponse object wrapping the given GadgetException. */ public static HttpResponse errorResponse(GadgetException e) { return new HttpResponseBuilder().setHttpStatusCode(e.getHttpStatusCode()) .setResponseString(e.getMessage() != null ? e.getMessage() : "").create(); }
@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() : ""); } }
if (ge.getCause() instanceof ParseException) { LOG.log(Level.WARNING, "Caja CSS parse failure: " + ge.getCause().getMessage() + " for " + source); return Collections.emptyList(); } else { throw new RewritingException(ge, ge.getHttpStatusCode());
@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 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()); } }
public boolean outputError(Uri uri, GadgetException e) throws IOException { println(formatError("outputError", e, uri)); return e.getHttpStatusCode() == HttpResponse.SC_INTERNAL_SERVER_ERROR; }
public void process(Node result, Element tag, TemplateProcessor processor) { String code = getValueFromTag(tag, ATTR_CODE, processor, String.class); if ((code == null) || "".equals(code)) { return; } try { parser.parseFragment(code, result); } catch (GadgetException ge) { try { StringBuilder sb = new StringBuilder("Error: "); HtmlSerialization.printEscapedText(ge.getMessage(), sb); Node comment = result.getOwnerDocument().createComment(sb.toString()); result.appendChild(comment); } catch (IOException e) { throw new RuntimeException(e); } } } }
throw new RewritingException(e.getLocalizedMessage(), e, e.getHttpStatusCode());
@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 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 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()); } }
if (ge.getCause() instanceof ParseException) { if (LOG.isLoggable(Level.INFO)) { LOG.logp(Level.WARNING, classname, "rewrite", MessageKeys.CAJA_CSS_PARSE_FAILURE, new Object[] {ge.getCause().getMessage(),source}); throw new RewritingException(ge, ge.getHttpStatusCode());
public boolean outputError(Uri uri, GadgetException e) throws IOException { print(formatError(e, uri)); return e.getHttpStatusCode() == HttpResponse.SC_INTERNAL_SERVER_ERROR; }
public void process(Node result, Element tag, TemplateProcessor processor) { String code = getValueFromTag(tag, ATTR_CODE, processor, String.class); if ((code == null) || "".equals(code)) { return; } try { parser.parseFragment(code, result); } catch (GadgetException ge) { try { StringBuilder sb = new StringBuilder("Error: "); HtmlSerialization.printEscapedText(ge.getMessage(), sb); Node comment = result.getOwnerDocument().createComment(sb.toString()); result.appendChild(comment); } catch (IOException e) { throw new RuntimeException(e); } } } }
throw new RewritingException(e.getLocalizedMessage(), e, e.getHttpStatusCode());
/** * @return An HttpResponse object wrapping the given GadgetException. */ public static HttpResponse errorResponse(GadgetException e) { return new HttpResponseBuilder().setHttpStatusCode(e.getHttpStatusCode()) .setResponseString(e.getMessage() != null ? e.getMessage() : "").create(); }
public HttpResponse fetch(HttpRequest request) throws GadgetException { fetchCount++; this.request = request; if (response == null) { throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT); } return response; } }
(resourceUri != null ? resourceUri.toString() : "n/a") + " made to wrong domain " + host; LOG.info(msg); throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, msg, HttpResponse.SC_BAD_REQUEST); response = ServletUtil.errorResponse(new GadgetException(e.getCode(), e.getMessage(), HttpServletResponse.SC_BAD_REQUEST));