/** * Hook for executing a JSON RPC fetch for social data. Subclasses can override * to provide special handling (e.g., directly invoking a local API) * * @param request the social request * @return the response to the request * @throws GadgetException if there are errors processing the gadget spec */ protected HttpResponse executeSocialRequest(HttpRequest request) throws GadgetException { return requestPipeline.execute(request); }
public void run() { try { requestPipeline.execute(request); } catch (GadgetException e) { logger.log(Level.WARNING, "Triggered fetch failed for " + request, e); } } });
private void expectDeleteAndReturnBody(AuthType authType, String response) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("DELETE").setAuthType(authType); expect(pipeline.execute(req)).andReturn(new HttpResponse(response)); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("DELETE"); }
private void expectDeleteAndReturnBody(AuthType authType, String response) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("DELETE").setAuthType(authType); expect(pipeline.execute(req)).andReturn(new HttpResponse(response)); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("DELETE"); }
private void expectHead(AuthType authType) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("HEAD").setAuthType(authType); expect(pipeline.execute(req)).andReturn(new HttpResponse("")); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("HEAD"); }
private void expectPostAndReturnBody(AuthType authType, String postData, String response) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("POST") .setPostBody(postData.getBytes("UTF-8")) .setAuthType(authType) .addHeader("Content-Type", "application/x-www-form-urlencoded"); expect(pipeline.execute(req)).andReturn(new HttpResponse(response)); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("POST"); expect(request.getParameter(MakeRequestHandler.POST_DATA_PARAM)) .andReturn(postData); }
@Test(expected = GadgetException.class) public void specFetchedEmptyContent() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpResponse response = new HttpResponse(""); expect(pipeline.execute(request)).andReturn(response); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); }
private void expectGetAndReturnData(Uri url, String data) throws Exception { HttpRequest req = new HttpRequest(url); HttpResponse resp = new HttpResponseBuilder().setResponse(data.getBytes()).create(); expect(pipeline.execute(req)).andReturn(resp).anyTimes(); }
private void expectGetAndReturnData(Uri url, String data) throws Exception { HttpRequest req = new HttpRequest(url); HttpResponse resp = new HttpResponseBuilder().setResponse(data.getBytes()).create(); expect(pipeline.execute(req)).andReturn(resp).anyTimes(); }
private void expectGetAndReturnData(String url, byte[] data) throws Exception { HttpRequest req = new HttpRequest(Uri.parse(url)); HttpResponse resp = new HttpResponseBuilder().setResponse(data).create(); expect(pipeline.execute(req)).andReturn(resp); }
private void expectGetAndReturnHeaders(String url, Map<String, List<String>> headers) throws Exception { HttpRequest req = new HttpRequest(Uri.parse(url)); HttpResponse resp = new HttpResponseBuilder().addAllHeaders(headers).create(); expect(pipeline.execute(req)).andReturn(resp); }
@Test public void getExactBundle() throws Exception { HttpResponse response = new HttpResponse(BASIC_BUNDLE); expect(pipeline.execute(isA(HttpRequest.class))).andReturn(response); replay(pipeline); MessageBundle bundle = bundleFactory.getBundle(gadgetSpec, LOCALE, true, ContainerConfig.DEFAULT_CONTAINER, null); assertEquals(MSG_0_VALUE, bundle.getMessages().get(MSG_0_NAME)); assertEquals(MSG_1_VALUE, bundle.getMessages().get(MSG_1_NAME)); assertEquals(MSG_2_VALUE, bundle.getMessages().get(MSG_2_NAME)); assertEquals(MSG_3_VALUE, bundle.getMessages().get(MSG_3_NAME)); }
@Test public void testDoGetHttpError() throws Exception { setupGet(); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoGetHttpError() throws Exception { setupGet(); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void specFetched() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpResponse response = new HttpResponse(LOCAL_SPEC_XML); expect(pipeline.execute(request)).andReturn(response); replay(pipeline); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, true)); assertEquals(LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }
@Test public void specFetchedWithBom() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpResponse response = new HttpResponse("" + LOCAL_SPEC_XML); expect(pipeline.execute(request)).andReturn(response); replay(pipeline); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, true)); assertEquals(LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }
@Test public void specFetchedWithBom() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpResponse response = new HttpResponse("" + LOCAL_SPEC_XML); expect(pipeline.execute(request)).andReturn(response); replay(pipeline); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, true)); assertEquals(LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }
@Test public void testBadHttpResponseIsPropagated() throws Exception { HttpRequest internalRequest = new HttpRequest(REQUEST_URL); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.error()); replay(); handler.fetch(request, recorder); JSONObject results = extractJsonFromResponse(); assertEquals(HttpResponse.SC_INTERNAL_SERVER_ERROR, results.getInt("rc")); assertTrue(rewriter.responseWasRewritten()); }
@Test public void testWithBadTtl() throws Exception { String url = "http://example.org/file.evil"; String domain = "example.org"; setupProxyRequestMock(domain, url, false, -1, null, null); HttpRequest req = new HttpRequestCache(Uri.parse(url)).setCacheTtl(-1).setIgnoreCache(false); HttpResponse resp = new HttpResponse("Hello"); expect(pipeline.execute(req)).andReturn(resp); replay(); proxyHandler.fetch(request); verify(); }
@Test public void authTypeNoneWasCached() throws Exception { HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE); HttpResponse cached = new HttpResponse("cached"); cache.data.put(DEFAULT_URI, cached); HttpResponse response = pipeline.execute(request); assertEquals(cached, response); assertEquals(1, cache.readCount); assertEquals(0, cache.writeCount); assertEquals(0, fetcher.fetchCount); }