protected boolean isCacheable(HttpRequest request) { if (request.getIgnoreCache()) { return false; } return ("GET".equals(request.getMethod()) || "GET".equals(request.getHeader("X-Method-Override"))); }
protected boolean isCacheable(HttpRequest request) { if (request.getIgnoreCache()) { return false; } return ("GET".equals(request.getMethod()) || "GET".equals(request.getHeader("X-Method-Override"))); }
protected boolean isCacheable(HttpRequest request) { if (request.getIgnoreCache()) { return false; } return ("GET".equals(request.getMethod()) || "GET".equals(request.getHeader("X-Method-Override"))); }
/** * Copies the post data from HttpServletRequest object to HttpRequest object. * @param origRequest Request to copy post data from. * @param req The HttpRequest object to copy post data to. * @throws GadgetException In case of errors. */ public static void copyRequestData(HttpRequest origRequest, HttpRequest req) throws GadgetException { req.setMethod(origRequest.getMethod()); try { if (origRequest.getMethod().equalsIgnoreCase("post")) { req.setPostBody(origRequest.getPostBody()); } } catch (IOException e) { throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e); } }
/** * Copies the post data from HttpServletRequest object to HttpRequest object. * @param origRequest Request to copy post data from. * @param req The HttpRequest object to copy post data to. * @throws GadgetException In case of errors. */ public static void copyRequestData(HttpRequest origRequest, HttpRequest req) throws GadgetException { req.setMethod(origRequest.getMethod()); try { if (origRequest.getMethod().equalsIgnoreCase("post")) { req.setPostBody(origRequest.getPostBody()); } } catch (IOException e) { throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e); } }
/** * Copies the post data from HttpServletRequest object to HttpRequest object. * @param origRequest Request to copy post data from. * @param req The HttpRequest object to copy post data to. * @throws GadgetException In case of errors. */ public static void copyRequestData(HttpRequest origRequest, HttpRequest req) throws GadgetException { req.setMethod(origRequest.getMethod()); try { if (origRequest.getMethod().equalsIgnoreCase("post")) { req.setPostBody(origRequest.getPostBody()); } } catch (IOException e) { throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e); } }
public boolean matches(Object obj) { HttpRequest match = (HttpRequest)obj; return (match.getMethod().equals(req.getMethod()) && match.getUri().equals(req.getUri()) && match.getAuthType().equals(req.getAuthType()) && match.getPostBodyAsString().equals(req.getPostBodyAsString()) && Objects.equal(match.getOAuthArguments(), req.getOAuthArguments()) && match.getHeaders().equals(req.getHeaders())); } }
public boolean matches(Object obj) { HttpRequest match = (HttpRequest)obj; return (match.getMethod().equals(req.getMethod()) && match.getUri().equals(req.getUri()) && match.getAuthType().equals(req.getAuthType()) && match.getPostBodyAsString().equals(req.getPostBodyAsString()) && Objects.equal(match.getOAuthArguments(), req.getOAuthArguments()) && match.getHeaders().equals(req.getHeaders())); } }
public boolean matches(Object obj) { HttpRequest match = (HttpRequest)obj; return (match.getMethod().equals(req.getMethod()) && match.getUri().equals(req.getUri()) && match.getAuthType().equals(req.getAuthType()) && match.getPostBodyAsString().equals(req.getPostBodyAsString()) && Objects.equal(match.getOAuthArguments(), req.getOAuthArguments()) && match.getHeaders().equals(req.getHeaders())); } }
@Test public void renderProxiedWithPreload() throws Exception { List<JSONObject> prefetchedJson = ImmutableList.of(new JSONObject("{id: 'foo', data: 'bar'}")); pipelineExecutor.results = new PipelineExecutor.Results(null, prefetchedJson, null); pipeline.plainResponses.put(EXPECTED_PROXIED_HTML_HREF, new HttpResponse(PROXIED_HTML_CONTENT)); String content = proxyRenderer.render(makeHrefGadget("none")); assertEquals(PROXIED_HTML_CONTENT, content); HttpRequest lastHttpRequest = pipeline.getLastHttpRequest(); assertEquals("POST", lastHttpRequest.getMethod()); assertEquals("application/json;charset=utf-8", lastHttpRequest.getHeader("Content-Type")); String postBody = lastHttpRequest.getPostBodyAsString(); JsonAssert.assertJsonEquals(JsonSerializer.serialize(prefetchedJson), postBody); assertTrue(pipelineExecutor.wasPreloaded); }
@Test public void renderProxiedWithPreload() throws Exception { List<JSONObject> prefetchedJson = ImmutableList.of(new JSONObject("{id: 'foo', data: 'bar'}")); pipelineExecutor.results = new PipelineExecutor.Results(null, prefetchedJson, null); pipeline.plainResponses.put(EXPECTED_PROXIED_HTML_HREF, new HttpResponse(PROXIED_HTML_CONTENT)); String content = proxyRenderer.render(makeHrefGadget("none")); assertEquals(PROXIED_HTML_CONTENT, content); HttpRequest lastHttpRequest = pipeline.getLastHttpRequest(); assertEquals("POST", lastHttpRequest.getMethod()); assertEquals("application/json;charset=utf-8", lastHttpRequest.getHeader("Content-Type")); String postBody = lastHttpRequest.getPostBodyAsString(); JsonAssert.assertJsonEquals(JsonSerializer.serialize(prefetchedJson), postBody); assertTrue(pipelineExecutor.wasPreloaded); }
@Test public void renderProxiedWithPreload() throws Exception { List<JSONObject> prefetchedJson = ImmutableList.of(new JSONObject("{id: 'foo', data: 'bar'}")); pipelineExecutor.results = new PipelineExecutor.Results(null, prefetchedJson, null); pipeline.plainResponses.put(EXPECTED_PROXIED_HTML_HREF, new HttpResponse(PROXIED_HTML_CONTENT)); String content = proxyRenderer.render(makeHrefGadget("none")); assertEquals(PROXIED_HTML_CONTENT, content); HttpRequest lastHttpRequest = pipeline.getLastHttpRequest(); assertEquals("POST", lastHttpRequest.getMethod()); assertEquals("application/json;charset=utf-8", lastHttpRequest.getHeader("Content-Type")); String postBody = lastHttpRequest.getPostBodyAsString(); JsonAssert.assertJsonEquals(JsonSerializer.serialize(prefetchedJson), postBody); assertTrue(pipelineExecutor.wasPreloaded); }
@Test public void testHttpPreloadWithGetParams() throws Exception { GadgetSpec spec = new GadgetSpec(GADGET_URL, XML_WITH_HTTP_REQUEST_AND_GET_PARAMS); String httpResult = "{foo: 'bar'}"; RecordingRequestPipeline pipeline = new RecordingRequestPipeline(httpResult); PipelinedDataPreloader preloader = new PipelinedDataPreloader(pipeline, containerConfig); view = "profile"; Gadget gadget = new Gadget() .setContext(context) .setSpec(spec) .setCurrentView(spec.getView("profile")); PipelinedData.Batch batch = getBatch(gadget); Collection<Callable<PreloadedData>> tasks = preloader.createPreloadTasks( context, batch); tasks.iterator().next().call(); // Should have only fetched one request assertEquals(1, pipeline.requests.size()); HttpRequest request = pipeline.requests.get(0); assertEquals(HTTP_REQUEST_URL + '?' + PARAMS, request.getUri().toString()); assertEquals("GET", request.getMethod()); }
@Test public void testHttpPreloadWithGetParams() throws Exception { GadgetSpec spec = new GadgetSpec(GADGET_URL, XML_WITH_HTTP_REQUEST_AND_GET_PARAMS); String httpResult = "{foo: 'bar'}"; RecordingRequestPipeline pipeline = new RecordingRequestPipeline(httpResult); PipelinedDataPreloader preloader = new PipelinedDataPreloader(pipeline, containerConfig); view = "profile"; Gadget gadget = new Gadget() .setContext(context) .setSpec(spec) .setCurrentView(spec.getView("profile")); PipelinedData.Batch batch = getBatch(gadget); Collection<Callable<PreloadedData>> tasks = preloader.createPreloadTasks( context, batch); tasks.iterator().next().call(); // Should have only fetched one request assertEquals(1, pipeline.requests.size()); HttpRequest request = pipeline.requests.get(0); assertEquals(HTTP_REQUEST_URL + '?' + PARAMS, request.getUri().toString()); assertEquals("GET", request.getMethod()); }
@Test public void testHttpPreloadWithPostParams() throws Exception { GadgetSpec spec = new GadgetSpec(GADGET_URL, XML_WITH_HTTP_REQUEST_AND_PARAMS); String httpResult = "{foo: 'bar'}"; RecordingRequestPipeline pipeline = new RecordingRequestPipeline(httpResult); PipelinedDataPreloader preloader = new PipelinedDataPreloader(pipeline, containerConfig); view = "profile"; Gadget gadget = new Gadget() .setContext(context) .setSpec(spec) .setCurrentView(spec.getView("profile")); PipelinedData.Batch batch = getBatch(gadget); Collection<Callable<PreloadedData>> tasks = preloader.createPreloadTasks( context, batch); tasks.iterator().next().call(); // Should have only fetched one request assertEquals(1, pipeline.requests.size()); HttpRequest request = pipeline.requests.get(0); assertEquals(HTTP_REQUEST_URL, request.getUri().toString()); assertEquals("POST", request.getMethod()); assertEquals(PARAMS, request.getPostBodyAsString()); }
@Test public void testHtmlAccelHandlesPost() throws Exception { String url = "http://example.org/data.html"; String data = "<html><body>This is error page</body></html>"; ((FakeCaptureRewriter) rewriter).setContentToRewrite(data); Capture<HttpRequest> req = new Capture<HttpRequest>(); HttpResponse resp = new HttpResponseBuilder() .setResponse(data.getBytes()) .setHeader("Content-Type", "text/html") .create(); expect(pipeline.execute(capture(req))).andReturn(resp).once(); expectPostRequest("", url, "hello=world"); replay(); servlet.doPost(request, recorder); verify(); assertEquals(data, recorder.getResponseAsString()); assertEquals(200, recorder.getHttpStatusCode()); assertTrue(rewriter.responseWasRewritten()); assertEquals("POST", req.getValue().getMethod()); assertEquals("hello=world", req.getValue().getPostBodyAsString()); }
@Test public void testHtmlAccelHandlesPost() throws Exception { String url = "http://example.org/data.html"; String data = "<html><body>This is error page</body></html>"; ((FakeCaptureRewriter) rewriter).setContentToRewrite(data); Capture<HttpRequest> req = new Capture<HttpRequest>(); HttpResponse resp = new HttpResponseBuilder() .setResponse(data.getBytes()) .setHeader("Content-Type", "text/html") .create(); expect(pipeline.execute(capture(req))).andReturn(resp).once(); expectPostRequest("", url, "hello=world"); replay(); servlet.doPost(request, recorder); verify(); assertEquals(data, recorder.getResponseAsString()); assertEquals(200, recorder.getHttpStatusCode()); assertTrue(rewriter.responseWasRewritten()); assertEquals("POST", req.getValue().getMethod()); assertEquals("hello=world", req.getValue().getPostBodyAsString()); }
@Test public void testHtmlAccelHandlesPost() throws Exception { String url = "http://example.org/data.html"; String data = "<html><body>This is error page</body></html>"; ((FakeCaptureRewriter) rewriter).setContentToRewrite(data); Capture<HttpRequest> req = new Capture<HttpRequest>(); HttpResponse resp = new HttpResponseBuilder() .setResponse(data.getBytes()) .setHeader("Content-Type", "text/html") .create(); expect(pipeline.execute(capture(req))).andReturn(resp).once(); expectPostRequest("", url, "hello=world"); replay(); servlet.doPost(request, recorder); verify(); assertEquals(data, recorder.getResponseAsString()); assertEquals(200, recorder.getHttpStatusCode()); assertTrue(rewriter.responseWasRewritten()); assertEquals("POST", req.getValue().getMethod()); assertEquals("hello=world", req.getValue().getPostBodyAsString()); }
@Test public void testGetAuthorizationRequest_5() throws Exception { final ClientCredentialsGrantTypeHandler fixture = ClientCredentialsGrantTypeHandlerTest.ccgth; final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_ClientCredentials(); final String completeAuthorizationUrl = "xxx"; final HttpRequest result = fixture.getAuthorizationRequest(accessor, completeAuthorizationUrl); Assert.assertNotNull(result); final String postBody = result.getPostBodyAsString(); Assert.assertNotNull(postBody); Assert.assertEquals( "client_id=clientId1&client_secret=clientSecret1&grant_type=client_credentials", postBody); Assert.assertNotNull( result.getSecurityToken() ); Assert.assertTrue( result.getSecurityToken().isAnonymous() ); Assert.assertEquals( accessor.getGadgetUri(), result.getSecurityToken().getAppUrl() ); Assert.assertEquals("POST", result.getMethod()); }
@Test public void testGetAuthorizationRequest_5() throws Exception { final ClientCredentialsGrantTypeHandler fixture = ClientCredentialsGrantTypeHandlerTest.ccgth; final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_ClientCredentials(); final String completeAuthorizationUrl = "xxx"; final HttpRequest result = fixture.getAuthorizationRequest(accessor, completeAuthorizationUrl); Assert.assertNotNull(result); final String postBody = result.getPostBodyAsString(); Assert.assertNotNull(postBody); Assert.assertEquals( "client_id=clientId1&client_secret=clientSecret1&grant_type=client_credentials", postBody); Assert.assertNotNull( result.getSecurityToken() ); Assert.assertTrue( result.getSecurityToken().isAnonymous() ); Assert.assertEquals( accessor.getGadgetUri(), result.getSecurityToken().getAppUrl() ); Assert.assertEquals("POST", result.getMethod()); }