private static byte[] getBody(final HttpRequest request) throws UnsupportedEncodingException { return request.getPostBodyAsString().getBytes("UTF-8"); }
@Override public String toString() { StringBuilder buf = new StringBuilder(method); buf.append(' ').append(uri.getPath()) .append(uri.getQuery() == null ? "" : '?' + uri.getQuery()).append("\n\n"); buf.append("Host: ").append(uri.getAuthority()).append('\n'); buf.append("X-Shindig-AuthType: ").append(authType).append('\n'); for (Map.Entry<String, List<String>> entry : headers.entrySet()) { String name = entry.getKey(); for (String value : entry.getValue()) { buf.append(name).append(": ").append(value).append('\n'); } } buf.append('\n'); buf.append(getPostBodyAsString()); return buf.toString(); }
@Override public String toString() { StringBuilder buf = new StringBuilder(method); buf.append(' ').append(uri.getPath()) .append(uri.getQuery() == null ? "" : '?' + uri.getQuery()).append("\n\n"); buf.append("Host: ").append(uri.getAuthority()).append('\n'); buf.append("X-Shindig-AuthType: ").append(authType).append('\n'); for (Map.Entry<String, List<String>> entry : headers.entrySet()) { String name = entry.getKey(); for (String value : entry.getValue()) { buf.append(name).append(": ").append(value).append('\n'); } } buf.append('\n'); buf.append(getPostBodyAsString()); return buf.toString(); }
@Override public String toString() { StringBuilder buf = new StringBuilder(method); buf.append(' ').append(uri.getPath()) .append(uri.getQuery() == null ? "" : '?' + uri.getQuery()).append("\n\n"); buf.append("Host: ").append(uri.getAuthority()).append('\n'); buf.append("X-Shindig-AuthType: ").append(authType).append('\n'); for (Map.Entry<String, List<String>> entry : headers.entrySet()) { String name = entry.getKey(); for (String value : entry.getValue()) { buf.append(name).append(": ").append(value).append('\n'); } } buf.append('\n'); buf.append(getPostBodyAsString()); return buf.toString(); }
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 postBodyCopied() throws Exception { HttpRequest request = new HttpRequest(DEFAULT_URI).setPostBody(POST_BODY.getBytes()); assertEquals(POST_BODY.length(), request.getPostBodyLength()); assertEquals(POST_BODY, IOUtils.toString(request.getPostBody(), "UTF-8")); assertEquals(POST_BODY, request.getPostBodyAsString()); }
@Test public void postBodyCopied() throws Exception { HttpRequest request = new HttpRequest(DEFAULT_URI).setPostBody(POST_BODY.getBytes()); assertEquals(POST_BODY.length(), request.getPostBodyLength()); assertEquals(POST_BODY, IOUtils.toString(request.getPostBody(), "UTF-8")); assertEquals(POST_BODY, request.getPostBodyAsString()); }
@Test public void postBodyCopied() throws Exception { HttpRequest request = new HttpRequest(DEFAULT_URI).setPostBody(POST_BODY.getBytes()); assertEquals(POST_BODY.length(), request.getPostBodyLength()); assertEquals(POST_BODY, IOUtils.toString(request.getPostBody(), "UTF-8")); assertEquals(POST_BODY, request.getPostBodyAsString()); }
@Test public void testCopyRequestData() throws Exception { HttpRequest origRequest = new HttpRequest(Uri.parse("http://www.example.com")); origRequest.setMethod("Post"); String data = "hello world"; origRequest.setPostBody(data.getBytes()); HttpRequest req = new HttpRequest(Uri.parse( "http://www.example.org/data.html")); UriUtils.copyRequestData(origRequest, req); assertEquals(data, req.getPostBodyAsString()); }
@Test public void testCopyRequestData() throws Exception { HttpRequest origRequest = new HttpRequest(Uri.parse("http://www.example.com")); origRequest.setMethod("Post"); String data = "hello world"; origRequest.setPostBody(data.getBytes()); HttpRequest req = new HttpRequest(Uri.parse( "http://www.example.org/data.html")); UriUtils.copyRequestData(origRequest, req); assertEquals(data, req.getPostBodyAsString()); }
@Test public void testCopyRequestData() throws Exception { HttpRequest origRequest = new HttpRequest(Uri.parse("http://www.example.com")); origRequest.setMethod("Post"); String data = "hello world"; origRequest.setPostBody(data.getBytes()); HttpRequest req = new HttpRequest(Uri.parse( "http://www.example.org/data.html")); UriUtils.copyRequestData(origRequest, req); assertEquals(data, req.getPostBodyAsString()); }
@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 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 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()); }