Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 942C52009EE for ; Wed, 18 May 2016 21:57:18 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 92EED160A15; Wed, 18 May 2016 19:57:18 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E572E1609B0 for ; Wed, 18 May 2016 21:57:17 +0200 (CEST) Received: (qmail 43102 invoked by uid 500); 18 May 2016 19:57:17 -0000 Mailing-List: contact dev-help@quarks.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@quarks.incubator.apache.org Delivered-To: mailing list dev@quarks.incubator.apache.org Received: (qmail 43090 invoked by uid 99); 18 May 2016 19:57:16 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 May 2016 19:57:16 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 8ACF0C9AA5 for ; Wed, 18 May 2016 19:57:16 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -5.446 X-Spam-Level: X-Spam-Status: No, score=-5.446 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id r0eLKpv0cxoS for ; Wed, 18 May 2016 19:57:15 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id B2CF15FB0A for ; Wed, 18 May 2016 19:57:14 +0000 (UTC) Received: (qmail 41664 invoked by uid 99); 18 May 2016 19:57:13 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 May 2016 19:57:13 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 7954C2C1F6D for ; Wed, 18 May 2016 19:57:13 +0000 (UTC) Date: Wed, 18 May 2016 19:57:13 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@quarks.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (QUARKS-96) Add an HTTP POST utility method. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 18 May 2016 19:57:18 -0000 [ https://issues.apache.org/jira/browse/QUARKS-96?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15289690#comment-15289690 ] ASF GitHub Bot commented on QUARKS-96: -------------------------------------- Github user dlaboss commented on a diff in the pull request: https://github.com/apache/incubator-quarks/pull/106#discussion_r63770856 --- Diff: connectors/http/src/test/java/quarks/test/connectors/http/HttpTest.java --- @@ -170,4 +288,80 @@ public void testJsonGet() throws Exception { assertTrue(endCondition.getResult().toString(), endCondition.valid()); } + + @Test + public void testJsonPost() throws Exception { + + DirectProvider ep = new DirectProvider(); + + Topology topology = ep.newTopology(); + + final String url = "http://httpbin.org/post"; + + JsonObject body = new JsonObject(); + body.addProperty("foo", "abc"); + body.addProperty("bar", 42); + + TStream stream = topology.collection(Arrays.asList(body)); + TStream rc = HttpStreams.postJson( + stream, HttpClients::noAuthentication, t -> url, + t -> body); + + TStream resStream = rc.map(j -> { + assertTrue(j.has("request")); + assertTrue(j.has("response")); + JsonObject req = j.getAsJsonObject("request"); + JsonObject res = j.getAsJsonObject("response"); + + assertTrue(res.has("status")); + assertTrue(res.has("entity")); + + assertEquals(req, res.getAsJsonObject("entity").getAsJsonObject("json")); + return true; + }); + + rc.print(); + Tester tester = topology.getTester(); + Condition> endCondition = tester.streamContents(resStream, true); + tester.complete(ep, new JsonObject(), endCondition, 10, TimeUnit.SECONDS); + assertTrue(endCondition.getResult().toString(), endCondition.valid()); + } + + @Test + public void testJsonPut() throws Exception { + + DirectProvider ep = new DirectProvider(); + + Topology topology = ep.newTopology(); + + final String url = "http://httpbin.org/put"; + + JsonObject body = new JsonObject(); + body.addProperty("foo", "abc"); + body.addProperty("bar", 42); + + TStream stream = topology.collection(Arrays.asList(body)); + TStream rc = HttpStreams.putJson( + stream, HttpClients::noAuthentication, t -> url, + t -> body); --- End diff -- should be `t -> t` > Add an HTTP POST utility method. > -------------------------------- > > Key: QUARKS-96 > URL: https://issues.apache.org/jira/browse/QUARKS-96 > Project: Quarks > Issue Type: Improvement > Components: Connectors > Reporter: Daniel John Debrunner > Assignee: Dale LaBossiere > Labels: newbie > > HTTPStreams.requests can support any type of request but it would be useful to have a utility method for POST requests, similar to getJson - i.e., a postJson() -- This message was sent by Atlassian JIRA (v6.3.4#6332)