public class HttpStreams
extends java.lang.Object
Constructor and Description |
---|
HttpStreams() |
Modifier and Type | Method and Description |
---|---|
static TStream<com.google.gson.JsonObject> |
deleteJson(TStream<com.google.gson.JsonObject> stream,
Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator,
Function<com.google.gson.JsonObject,java.lang.String> uri)
Make an HTTP DELETE request with JsonObject.
|
static TStream<com.google.gson.JsonObject> |
getJson(TStream<com.google.gson.JsonObject> stream,
Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator,
Function<com.google.gson.JsonObject,java.lang.String> uri)
Make an HTTP GET request with JsonObject.
|
static TStream<com.google.gson.JsonObject> |
postJson(TStream<com.google.gson.JsonObject> stream,
Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator,
Function<com.google.gson.JsonObject,java.lang.String> uri,
UnaryOperator<com.google.gson.JsonObject> body)
Make an HTTP POST request with JsonObject.
|
static TStream<com.google.gson.JsonObject> |
putJson(TStream<com.google.gson.JsonObject> stream,
Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator,
Function<com.google.gson.JsonObject,java.lang.String> uri,
UnaryOperator<com.google.gson.JsonObject> body)
Make an HTTP PUT request with JsonObject.
|
static <T,R> TStream<R> |
requests(TStream<T> stream,
Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator,
Function<T,java.lang.String> method,
Function<T,java.lang.String> uri,
BiFunction<T,org.apache.http.client.methods.CloseableHttpResponse,R> response)
Make an HTTP request for each tuple on a stream.
|
static <T,R> TStream<R> |
requestsWithBody(TStream<T> stream,
Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator,
Function<T,java.lang.String> method,
Function<T,java.lang.String> uri,
Function<T,org.apache.http.HttpEntity> body,
BiFunction<T,org.apache.http.client.methods.CloseableHttpResponse,R> response)
Make an HTTP request with body for each tuple.
|
public static TStream<com.google.gson.JsonObject> getJson(TStream<com.google.gson.JsonObject> stream, Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator, Function<com.google.gson.JsonObject,java.lang.String> uri)
DirectProvider ep = new DirectProvider();
Topology topology = ep.newTopology();
final String url = "http://httpbin.org/get?";
JsonObject request1 = new JsonObject();
request1.addProperty("a", "abc");
request1.addProperty("b", "42");
TStream<JsonObject> stream = topology.collection(Arrays.asList(request1));
TStream<JsonObject> rc = HttpStreams.getJson(stream,
HttpClients::noAuthentication,
t -> url + "a=" + t.get("a").getAsString() + "&b="
+ t.get("b").getAsString());
stream
- - JsonObject TStream.clientCreator
- - CloseableHttpClient supplier preferably created using HttpClients
uri
- - URI function which returns URI stringrequests(TStream, Supplier, Function, Function, BiFunction)
public static TStream<com.google.gson.JsonObject> deleteJson(TStream<com.google.gson.JsonObject> stream, Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator, Function<com.google.gson.JsonObject,java.lang.String> uri)
DirectProvider ep = new DirectProvider();
Topology topology = ep.newTopology();
final String url = "http://httpbin.org/delete?";
JsonObject request = new JsonObject();
request.addProperty("a", "abc");
request.addProperty("b", "42");
TStream<JsonObject> stream = topology.collection(Arrays.asList(request));
TStream<JsonObject> rc = HttpStreams.deleteJson(stream,
HttpClients::noAuthentication,
t -> url + "a=" + t.get("a").getAsString() + "&b="
+ t.get("b").getAsString());
stream
- - JsonObject TStream.clientCreator
- - CloseableHttpClient supplier preferably created using HttpClients
uri
- - URI function which returns URI stringrequests(TStream, Supplier, Function, Function, BiFunction)
public static TStream<com.google.gson.JsonObject> postJson(TStream<com.google.gson.JsonObject> stream, Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator, Function<com.google.gson.JsonObject,java.lang.String> uri, UnaryOperator<com.google.gson.JsonObject> body)
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<JsonObject> stream = topology.collection(Arrays.asList(body));
TStream<JsonObject> rc = HttpStreams.postJson(stream,
HttpClients::noAuthentication, t -> url, t -> t);
stream
- - JsonObject TStream.clientCreator
- - CloseableHttpClient supplier preferably created using HttpClients
uri
- - URI function which returns URI stringbody
- - Function that returns JsonObject which will be set as a body for the request.requestsWithBody(TStream, Supplier, Function, Function, Function, BiFunction)
public static TStream<com.google.gson.JsonObject> putJson(TStream<com.google.gson.JsonObject> stream, Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator, Function<com.google.gson.JsonObject,java.lang.String> uri, UnaryOperator<com.google.gson.JsonObject> body)
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<JsonObject> stream = topology.collection(Arrays.asList(body));
TStream<JsonObject> rc = HttpStreams.putJson(stream,
HttpClients::noAuthentication, t -> url, t -> t);
stream
- - JsonObject TStream.clientCreator
- - CloseableHttpClient supplier preferably created using HttpClients
uri
- - URI function which returns URI stringbody
- - Function that returns JsonObject which will be set as a body for the request.requestsWithBody(TStream, Supplier, Function, Function, Function, BiFunction)
public static <T,R> TStream<R> requests(TStream<T> stream, Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator, Function<T,java.lang.String> method, Function<T,java.lang.String> uri, BiFunction<T,org.apache.http.client.methods.CloseableHttpResponse,R> response)
clientCreator
is invoked once to create a new HTTP client
to make the requests.
method
is invoked for each tuple to define the method
to be used for the HTTP request driven by the tuple. A fixed method
can be declared using a function such as:
t -> HttpGet.METHOD_NAME
uri
is invoked for each tuple to define the URI
to be used for the HTTP request driven by the tuple. A fixed method
can be declared using a function such as:
t -> "http://www.example.com"
response
is invoked after each request that did not throw an exception.
It is passed the input tuple and the HTTP response. The function must completely
consume the entity stream for the response. The return value is present on
the stream returned by this method if it is non-null. A null return results
in no tuple on the returned stream.
T
- Tuple type for input streamR
- Tuple type for output streamstream
- Stream to invoke HTTP requests.clientCreator
- Function to create a HTTP client.method
- Function to define the HTTP method.uri
- Function to define the URI.response
- Function to process the response.response
function.HttpClients
,
HttpResponders
public static <T,R> TStream<R> requestsWithBody(TStream<T> stream, Supplier<org.apache.http.impl.client.CloseableHttpClient> clientCreator, Function<T,java.lang.String> method, Function<T,java.lang.String> uri, Function<T,org.apache.http.HttpEntity> body, BiFunction<T,org.apache.http.client.methods.CloseableHttpResponse,R> response)
T
- Tuple type for input streamR
- Tuple type for output streamstream
- Stream to invoke HTTP requests.clientCreator
- Function to create a HTTP client.method
- Function to define the HTTP method.uri
- Function to define the URI.body
- Function to define the HTTP request bodyresponse
- Function to process the response.response
function.requests(TStream, Supplier, Function, Function, BiFunction)
,
HttpClients
,
HttpResponders
Copyright © 2016 The Apache Software Foundation. All Rights Reserved - bbe71fa-20161201-1641