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 8EBAE2004C8 for ; Mon, 9 May 2016 22:03:17 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8D0C61609A8; Mon, 9 May 2016 20:03:17 +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 B0DF916099C for ; Mon, 9 May 2016 22:03:16 +0200 (CEST) Received: (qmail 62398 invoked by uid 500); 9 May 2016 20:03:16 -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 62385 invoked by uid 99); 9 May 2016 20:03:15 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 May 2016 20:03:15 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id C02C2C0DF7 for ; Mon, 9 May 2016 20:03:14 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.021 X-Spam-Level: X-Spam-Status: No, score=-4.021 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=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id R_T6IK9Ss3wR for ; Mon, 9 May 2016 20:03:13 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id E1EA05F475 for ; Mon, 9 May 2016 20:03:13 +0000 (UTC) Received: (qmail 60223 invoked by uid 99); 9 May 2016 20:03:13 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 May 2016 20:03:13 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id D199B2C1F5C for ; Mon, 9 May 2016 20:03:12 +0000 (UTC) Date: Mon, 9 May 2016 20:03:12 +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: Mon, 09 May 2016 20:03:17 -0000 [ https://issues.apache.org/jira/browse/QUARKS-96?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15276924#comment-15276924 ] 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_r62562952 --- Diff: connectors/http/src/main/java/quarks/connectors/http/HttpStreams.java --- @@ -38,12 +40,88 @@ Licensed to the Apache Software Foundation (ASF) under one */ public class HttpStreams { + /** + * Make an HTTP GET request with JsonObject.
+ * + * Method specifically works with JsonObjects. For each JsonObject in the stream, + * HTTP GET request is executed on provided uri. As a result, Response is added to + * the response TStream. + *
+ * + * Sample usage:
+ * + *
    +     * {@code
    +     *     JsonObject request1 = new JsonObject();
    +     *     request1.addProperty("a", "abc");
    +     *     request1.addProperty("b", "42");
    +     *     TStream rc = HttpStreams.getJson(
    +     *             topology.collection(Arrays.asList(request1)),
    +     *             HttpClients::noAuthentication,
    +     *             t -> url + "a=" + t.get("a").getAsString() + "&b="
    +     *                     + t.get("b").getAsString());
    +     * }
    +     * 
+ *
+ * See HttpTest for example. + *
+ * @param stream - JsonObject TStream. + * @param clientCreator - CloseableHttpClient supplier preferably created using {@link HttpClients} + * @param uri - URI function which returns URI string + * @return TStream of JsonObject which contains responses of GET requests + * + * @see HttpStreams#requests(TStream, Supplier, Function, Function, BiFunction) + */ public static TStream getJson(TStream stream, Supplier clientCreator, Function uri) { return HttpStreams.requests(stream, clientCreator, - t -> HttpGet.METHOD_NAME, uri, HttpResponders.json()); + t -> HttpGet.METHOD_NAME, uri, HttpResponders.json()); + } + + /** + * Make an HTTP POST request with JsonObject.
+ * + * Method specifically works with JsonObjects. For each JsonObject in the stream, + * HTTP POST request is executed on provided uri. Request body is filled using + * HttpEntity provided by body function. As a result, Response is added to + * the response TStream.
+ * + * Sample usage:
+ * + *
    +     * {@code
    +     *     JsonObject request = new JsonObject();
    +     *     request.addProperty("a", "abc");
    +     *     request.addProperty("b", "42");
    +     *     TStream rc = HttpStreams.postJson(
    +     *         topology.collection(Arrays.asList(request1)),
    +     *         HttpClients::noAuthentication,
    +     *         t -> url,
    +     *         t -> new ByteArrayEntity(request1.toString().getBytes())
    +     *     );
    +     * }
    +     * 
+ *
+ * See HttpTest for example. + *
+ * @param stream - JsonObject TStream. + * @param clientCreator - CloseableHttpClient supplier preferably created using {@link HttpClients} + * @param uri - URI function which returns URI string + * @param body - Function that returns HttpEntity which will be set as a body for the request. + * @return TStream of JsonObject which contains responses of GET requests + * + * @see HttpStreams#requestsWithBody(TStream, Supplier, Function, Function, Function, BiFunction) + */ + public static TStream postJson(TStream stream, + Supplier clientCreator, + Function uri, + Function body) { --- End diff -- It strikes me that the ``body`` function should instead be ``UnaryOperator`` (a fn that yields a JsonObject (body) from the input JsonObject tuple). I think that's more in line with "keeping the simple simple" for applications exchanging Json-based data. I agree that ``HttpEntity`` is appropriate for ``requestsWithBody()``. Does that make sense? > 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)