io.vertx.rxjava.core.http.HttpClientRequest Maven / Gradle / Ivy
/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.rxjava.core.http;
import rx.Observable;
import rx.Single;
import io.vertx.rx.java.RxHelper;
import io.vertx.rx.java.WriteStreamSubscriber;
import io.vertx.rx.java.SingleOnSubscribeAdapter;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;
/**
* Represents a client-side HTTP request.
*
* Instances are created by an {@link io.vertx.rxjava.core.http.HttpClient} instance, via one of the methods corresponding to the
* specific HTTP methods, or the generic request methods. On creation the request will not have been written to the
* wire.
*
* Once a request has been obtained, headers can be set on it, and data can be written to its body if required. Once
* you are ready to send the request, one of the {@link io.vertx.rxjava.core.http.HttpClientRequest#end} methods should be called.
*
* Nothing is actually sent until the request has been internally assigned an HTTP connection.
*
* The {@link io.vertx.rxjava.core.http.HttpClient} instance will return an instance of this class immediately, even if there are no HTTP
* connections available in the pool. Any requests sent before a connection is assigned will be queued
* internally and actually sent when an HTTP connection becomes available from the pool.
*
* The headers of the request are queued for writing either when the {@link io.vertx.rxjava.core.http.HttpClientRequest#end} method is called, or, when the first
* part of the body is written, whichever occurs first.
*
* This class supports both chunked and non-chunked HTTP.
*
* It implements {@link io.vertx.rxjava.core.streams.WriteStream} so it can be used with
* {@link io.vertx.rxjava.core.streams.Pipe} to pipe data with flow control.
*
* An example of using this class is as follows:
*
*
*
* NOTE: This class has been automatically generated from the {@link io.vertx.core.http.HttpClientRequest original} non RX-ified interface using Vert.x codegen.
*/
@RxGen(io.vertx.core.http.HttpClientRequest.class)
public class HttpClientRequest extends io.vertx.rxjava.core.Future implements io.vertx.rxjava.core.streams.WriteStream {
@Override
public String toString() {
return delegate.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
HttpClientRequest that = (HttpClientRequest) o;
return delegate.equals(that.delegate);
}
@Override
public int hashCode() {
return delegate.hashCode();
}
public static final TypeArg __TYPE_ARG = new TypeArg<>( obj -> new HttpClientRequest((io.vertx.core.http.HttpClientRequest) obj),
HttpClientRequest::getDelegate
);
private final io.vertx.core.http.HttpClientRequest delegate;
public HttpClientRequest(io.vertx.core.http.HttpClientRequest delegate) {
super(delegate);
this.delegate = delegate;
}
public HttpClientRequest(Object delegate) {
super((io.vertx.core.http.HttpClientRequest)delegate);
this.delegate = (io.vertx.core.http.HttpClientRequest)delegate;
}
public io.vertx.core.http.HttpClientRequest getDelegate() {
return delegate;
}
private WriteStreamSubscriber subscriber;
public synchronized WriteStreamSubscriber toSubscriber() {
if (subscriber == null) {
Function conv = io.vertx.rxjava.core.buffer.Buffer::getDelegate;
subscriber = RxHelper.toSubscriber(getDelegate(), conv);
}
return subscriber;
}
private static final TypeArg TYPE_ARG_0 = new TypeArg(o1 -> io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)o1), o1 -> o1.getDelegate());
private static final TypeArg TYPE_ARG_1 = new TypeArg(o1 -> io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)o1), o1 -> o1.getDelegate());
private static final TypeArg TYPE_ARG_2 = new TypeArg(o1 -> io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)o1), o1 -> o1.getDelegate());
private static final TypeArg TYPE_ARG_3 = new TypeArg(o1 -> io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)o1), o1 -> o1.getDelegate());
/**
* Same as but with an handler
called when the operation completes
* @param data
* @param handler
*/
public void write(io.vertx.rxjava.core.buffer.Buffer data, Handler> handler) {
delegate.write(data.getDelegate(), handler);
}
/**
* Same as but with an handler
called when the operation completes
* @param data
*/
public void write(io.vertx.rxjava.core.buffer.Buffer data) {
write(data, ar -> { });
}
/**
* Same as but with an handler
called when the operation completes
* @param data
* @return
*/
public Single rxWrite(io.vertx.rxjava.core.buffer.Buffer data) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
write(data, fut);
}));
}
/**
* This will return true
if there are more bytes in the write queue than the value set using {@link io.vertx.rxjava.core.http.HttpClientRequest#setWriteQueueMaxSize}
* @return true
if write queue is full
*/
public boolean writeQueueFull() {
boolean ret = delegate.writeQueueFull();
return ret;
}
/**
* The result of the operation. This will be null if the operation failed.
* @return the result or null if the operation failed.
*/
public io.vertx.rxjava.core.http.HttpClientResponse result() {
io.vertx.rxjava.core.http.HttpClientResponse ret = io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)delegate.result());
return ret;
}
/**
* Alias for {@link io.vertx.rxjava.core.Future#compose}.
* @param mapper
* @return
*/
public io.vertx.rxjava.core.Future flatMap(Function> mapper) {
io.vertx.rxjava.core.Future ret = io.vertx.rxjava.core.Future.newInstance((io.vertx.core.Future)delegate.flatMap(new Function>() {
public io.vertx.core.Future apply(io.vertx.core.http.HttpClientResponse arg) {
io.vertx.rxjava.core.Future ret = mapper.apply(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)arg));
return ret.getDelegate();
}
}), TypeArg.unknown());
return ret;
}
/**
* Compose this future with a mapper
function.
*
* When this future (the one on which compose
is called) succeeds, the mapper
will be called with
* the completed value and this mapper returns another future object. This returned future completion will complete
* the future returned by this method call.
*
* If the mapper
throws an exception, the returned future will be failed with this exception.
*
* When this future fails, the failure will be propagated to the returned future and the mapper
* will not be called.
* @param mapper the mapper function
* @return the composed future
*/
public io.vertx.rxjava.core.Future compose(Function> mapper) {
io.vertx.rxjava.core.Future ret = io.vertx.rxjava.core.Future.newInstance((io.vertx.core.Future)delegate.compose(new Function>() {
public io.vertx.core.Future apply(io.vertx.core.http.HttpClientResponse arg) {
io.vertx.rxjava.core.Future ret = mapper.apply(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)arg));
return ret.getDelegate();
}
}), TypeArg.unknown());
return ret;
}
/**
* Handles a failure of this Future by returning the result of another Future.
* If the mapper fails, then the returned future will be failed with this failure.
* @param mapper A function which takes the exception of a failure and returns a new future.
* @return A recovered future
*/
public io.vertx.rxjava.core.Future recover(Function> mapper) {
io.vertx.rxjava.core.Future ret = io.vertx.rxjava.core.Future.newInstance((io.vertx.core.Future)delegate.recover(new Function>() {
public io.vertx.core.Future apply(java.lang.Throwable arg) {
io.vertx.rxjava.core.Future ret = mapper.apply(arg);
return ret.getDelegate();
}
}), TYPE_ARG_0);
return ret;
}
/**
* Compose this future with a successMapper
and failureMapper
functions.
*
* When this future (the one on which compose
is called) succeeds, the successMapper
will be called with
* the completed value and this mapper returns another future object. This returned future completion will complete
* the future returned by this method call.
*
* When this future (the one on which compose
is called) fails, the failureMapper
will be called with
* the failure and this mapper returns another future object. This returned future completion will complete
* the future returned by this method call.
*
* If any mapper function throws an exception, the returned future will be failed with this exception.
* @param successMapper the function mapping the success
* @param failureMapper the function mapping the failure
* @return the composed future
*/
public io.vertx.rxjava.core.Future compose(Function> successMapper, Function> failureMapper) {
io.vertx.rxjava.core.Future ret = io.vertx.rxjava.core.Future.newInstance((io.vertx.core.Future)delegate.compose(new Function>() {
public io.vertx.core.Future apply(io.vertx.core.http.HttpClientResponse arg) {
io.vertx.rxjava.core.Future ret = successMapper.apply(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)arg));
return ret.getDelegate();
}
}, new Function>() {
public io.vertx.core.Future apply(java.lang.Throwable arg) {
io.vertx.rxjava.core.Future ret = failureMapper.apply(arg);
return ret.getDelegate();
}
}), TypeArg.unknown());
return ret;
}
/**
* Apply a mapper
function on this future.
*
* When this future succeeds, the mapper
will be called with the completed value and this mapper
* returns a value. This value will complete the future returned by this method call.
*
* If the mapper
throws an exception, the returned future will be failed with this exception.
*
* When this future fails, the failure will be propagated to the returned future and the mapper
* will not be called.
* @param mapper the mapper function
* @return the mapped future
*/
public io.vertx.rxjava.core.Future map(Function mapper) {
io.vertx.rxjava.core.Future ret = io.vertx.rxjava.core.Future.newInstance((io.vertx.core.Future)delegate.map(new Function() {
public U apply(io.vertx.core.http.HttpClientResponse arg) {
U ret = mapper.apply(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)arg));
return ret;
}
}), TypeArg.unknown());
return ret;
}
/**
* Apply a mapper
function on this future.
*
* When this future fails, the mapper
will be called with the completed value and this mapper
* returns a value. This value will complete the future returned by this method call.
*
* If the mapper
throws an exception, the returned future will be failed with this exception.
*
* When this future succeeds, the result will be propagated to the returned future and the mapper
* will not be called.
* @param mapper the mapper function
* @return the mapped future
*/
public io.vertx.rxjava.core.Future otherwise(Function mapper) {
io.vertx.rxjava.core.Future ret = io.vertx.rxjava.core.Future.newInstance((io.vertx.core.Future)delegate.otherwise(new Function() {
public io.vertx.core.http.HttpClientResponse apply(java.lang.Throwable arg) {
io.vertx.rxjava.core.http.HttpClientResponse ret = mapper.apply(arg);
return ret.getDelegate();
}
}), TYPE_ARG_1);
return ret;
}
/**
* Map the failure of a future to a specific value
.
*
* When this future fails, this value
will complete the future returned by this method call.
*
* When this future succeeds, the result will be propagated to the returned future.
* @param value the value that eventually completes the mapped future
* @return the mapped future
*/
public io.vertx.rxjava.core.Future otherwise(io.vertx.rxjava.core.http.HttpClientResponse value) {
io.vertx.rxjava.core.Future ret = io.vertx.rxjava.core.Future.newInstance((io.vertx.core.Future)delegate.otherwise(value.getDelegate()), TYPE_ARG_2);
return ret;
}
/**
* Map the failure of a future to null
.
*
* This is a convenience for future.otherwise((T) null)
.
*
* When this future fails, the null
value will complete the future returned by this method call.
*
* When this future succeeds, the result will be propagated to the returned future.
* @return the mapped future
*/
public io.vertx.rxjava.core.Future otherwiseEmpty() {
io.vertx.rxjava.core.Future ret = io.vertx.rxjava.core.Future.newInstance((io.vertx.core.Future)delegate.otherwiseEmpty(), TYPE_ARG_3);
return ret;
}
public io.vertx.rxjava.core.http.HttpClientRequest exceptionHandler(Handler handler) {
delegate.exceptionHandler(handler);
return this;
}
public io.vertx.rxjava.core.http.HttpClientRequest setWriteQueueMaxSize(int maxSize) {
delegate.setWriteQueueMaxSize(maxSize);
return this;
}
public io.vertx.rxjava.core.http.HttpClientRequest drainHandler(Handler handler) {
delegate.drainHandler(handler);
return this;
}
/**
* Set the host value of the HTTP/1.1 host
header or HTTP/2 authority
pseudo header
* The initial value is the same than the server socket address host.
*
Keep in mind that changing this value won't change the actual server socket address for this request.
* @param host the host part of the HTTP/1.1 host
header or HTTP/2 authority
pseudo header
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest setHost(String host) {
delegate.setHost(host);
return this;
}
/**
* @return the host value of the HTTP/1.1 host
header or HTTP/2 authority
pseudo header
*/
public String getHost() {
String ret = delegate.getHost();
return ret;
}
/**
* Set the port value of the HTTP/1.1 host
header or HTTP/2 authority
pseudo header
*
*
Keep in mind that this won't change the actual server socket address for this request.
*
The initial value is the same than the server socket address port.
* @param port the port part of the HTTP/1.1 host
header or HTTP/2 authority
pseudo header
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest setPort(int port) {
delegate.setPort(port);
return this;
}
/**
* @return the port value of the HTTP/1.1 host
header or HTTP/2 authority
pseudo header
*/
public int getPort() {
int ret = delegate.getPort();
return ret;
}
/**
* Set the request to follow HTTP redirects up to {@link io.vertx.core.http.HttpClientOptions}.
* @param followRedirects true
to follow HTTP redirects
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest setFollowRedirects(boolean followRedirects) {
delegate.setFollowRedirects(followRedirects);
return this;
}
/**
* Set the max number of HTTP redirects this request will follow. The default is 0
which means
* no redirects.
* @param maxRedirects the number of HTTP redirect to follow
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest setMaxRedirects(int maxRedirects) {
delegate.setMaxRedirects(maxRedirects);
return this;
}
/**
* If chunked is true then the request will be set into HTTP chunked mode
* @param chunked true if chunked encoding
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest setChunked(boolean chunked) {
delegate.setChunked(chunked);
return this;
}
/**
* @return Is the request chunked?
*/
public boolean isChunked() {
boolean ret = delegate.isChunked();
return ret;
}
/**
* The HTTP method for the request.
* @return
*/
public io.vertx.core.http.HttpMethod getMethod() {
io.vertx.core.http.HttpMethod ret = delegate.getMethod();
return ret;
}
/**
* Set the HTTP method for this request.
* @param method the HTTP method
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest setMethod(io.vertx.core.http.HttpMethod method) {
delegate.setMethod(method);
return this;
}
/**
* @return the absolute URI corresponding to the the HTTP request
*/
public String absoluteURI() {
String ret = delegate.absoluteURI();
return ret;
}
/**
* @return The URI of the request.
*/
public String getURI() {
String ret = delegate.getURI();
return ret;
}
/**
* Set the request uri.
* @param uri the request uri
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest setURI(String uri) {
delegate.setURI(uri);
return this;
}
/**
* @return The path part of the uri. For example /somepath/somemorepath/someresource.foo
*/
public String path() {
String ret = delegate.path();
return ret;
}
/**
* @return the query part of the uri. For example someparam=32&someotherparam=x
*/
public String query() {
String ret = delegate.query();
return ret;
}
/**
* @return The HTTP headers
*/
public io.vertx.rxjava.core.MultiMap headers() {
if (cached_0 != null) {
return cached_0;
}
io.vertx.rxjava.core.MultiMap ret = io.vertx.rxjava.core.MultiMap.newInstance((io.vertx.core.MultiMap)delegate.headers());
cached_0 = ret;
return ret;
}
/**
* Put an HTTP header
* @param name The header name
* @param value The header value
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest putHeader(String name, String value) {
delegate.putHeader(name, value);
return this;
}
/**
* @return the HTTP version for this request
*/
public io.vertx.core.http.HttpVersion version() {
io.vertx.core.http.HttpVersion ret = delegate.version();
return ret;
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#write} but with an handler
called when the operation completes
* @param chunk
* @param handler
*/
public void write(String chunk, Handler> handler) {
delegate.write(chunk, handler);
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#write} but with an handler
called when the operation completes
* @param chunk
*/
public void write(String chunk) {
write(chunk, ar -> { });
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#write} but with an handler
called when the operation completes
* @param chunk
* @return
*/
public Single rxWrite(String chunk) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
write(chunk, fut);
}));
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#write} but with an handler
called when the operation completes
* @param chunk
* @param enc
* @param handler
*/
public void write(String chunk, String enc, Handler> handler) {
delegate.write(chunk, enc, handler);
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#write} but with an handler
called when the operation completes
* @param chunk
* @param enc
*/
public void write(String chunk, String enc) {
write(chunk, enc, ar -> { });
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#write} but with an handler
called when the operation completes
* @param chunk
* @param enc
* @return
*/
public Single rxWrite(String chunk, String enc) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
write(chunk, enc, fut);
}));
}
/**
* If you send an HTTP request with the header Expect
set to the value 100-continue
* and the server responds with an interim HTTP response with a status code of 100
and a continue handler
* has been set using this method, then the handler
will be called.
*
* You can then continue to write data to the request body and later end it. This is normally used in conjunction with
* the {@link io.vertx.rxjava.core.http.HttpClientRequest#sendHead} method to force the request header to be written before the request has ended.
* @param handler
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest continueHandler(Handler handler) {
delegate.continueHandler(handler);
return this;
}
/**
* Like {@link io.vertx.rxjava.core.http.HttpClientRequest#sendHead} but with an handler after headers have been sent. The handler will be called with
* the {@link io.vertx.core.http.HttpVersion} if it can be determined or null otherwise.
* @param completionHandler
* @return
*/
public io.vertx.rxjava.core.http.HttpClientRequest sendHead(Handler> completionHandler) {
delegate.sendHead(completionHandler);
return this;
}
/**
* Like {@link io.vertx.rxjava.core.http.HttpClientRequest#sendHead} but with an handler after headers have been sent. The handler will be called with
* the {@link io.vertx.core.http.HttpVersion} if it can be determined or null otherwise.
* @return
*/
public io.vertx.rxjava.core.http.HttpClientRequest sendHead() {
return
sendHead(ar -> { });
}
/**
* Like {@link io.vertx.rxjava.core.http.HttpClientRequest#sendHead} but with an handler after headers have been sent. The handler will be called with
* the {@link io.vertx.core.http.HttpVersion} if it can be determined or null otherwise.
* @return
*/
public Single rxSendHead() {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
sendHead(fut);
}));
}
/**
* Create an HTTP tunnel to the server.
*
* Send an HTTP request to the server, then configures the transport to exchange
* raw buffers when the server replies with an appropriate response:
*
*
* 200
for HTTP CONNECT
method
* 101
for HTTP/1.1 GET
with Upgrade
connection
header
*
*
* The handler
is called after response headers are received.
*
*
Use {@link io.vertx.rxjava.core.http.HttpClientResponse#netSocket} to get a for the interacting
* more conveniently with the server.
*
*
HTTP/1.1 pipe-lined requests are not supported.
* @param handler the response completion handler
*/
public void connect(Handler> handler) {
delegate.connect(new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Create an HTTP tunnel to the server.
*
* Send an HTTP request to the server, then configures the transport to exchange
* raw buffers when the server replies with an appropriate response:
*
*
* 200
for HTTP CONNECT
method
* 101
for HTTP/1.1 GET
with Upgrade
connection
header
*
*
* The handler
is called after response headers are received.
*
*
Use {@link io.vertx.rxjava.core.http.HttpClientResponse#netSocket} to get a for the interacting
* more conveniently with the server.
*
*
HTTP/1.1 pipe-lined requests are not supported.
*/
public void connect() {
connect(ar -> { });
}
/**
* Create an HTTP tunnel to the server.
*
*
Send an HTTP request to the server, then configures the transport to exchange
* raw buffers when the server replies with an appropriate response:
*
*
* 200
for HTTP CONNECT
method
* 101
for HTTP/1.1 GET
with Upgrade
connection
header
*
*
* The handler
is called after response headers are received.
*
*
Use {@link io.vertx.rxjava.core.http.HttpClientResponse#netSocket} to get a for the interacting
* more conveniently with the server.
*
*
HTTP/1.1 pipe-lined requests are not supported.
* @return
*/
public Single rxConnect() {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
connect(fut);
}));
}
/**
* Send the request with an empty body.
* @param handler the completion handler for the {@link io.vertx.rxjava.core.http.HttpClientResponse}
*/
public void send(Handler> handler) {
delegate.send(new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Send the request with an empty body.
*/
public void send() {
send(ar -> { });
}
/**
* Send the request with an empty body.
* @return
*/
public Single rxSend() {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
send(fut);
}));
}
/**
* Send the request with a string body
.
* @param body
* @param handler the completion handler for the {@link io.vertx.rxjava.core.http.HttpClientResponse}
*/
public void send(String body, Handler> handler) {
delegate.send(body, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Send the request with a string body
.
* @param body
*/
public void send(String body) {
send(body, ar -> { });
}
/**
* Send the request with a string body
.
* @param body
* @return
*/
public Single rxSend(String body) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
send(body, fut);
}));
}
/**
* Send the request with a buffer body
.
* @param body
* @param handler the completion handler for the {@link io.vertx.rxjava.core.http.HttpClientResponse}
*/
public void send(io.vertx.rxjava.core.buffer.Buffer body, Handler> handler) {
delegate.send(body.getDelegate(), new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Send the request with a buffer body
.
* @param body
*/
public void send(io.vertx.rxjava.core.buffer.Buffer body) {
send(body, ar -> { });
}
/**
* Send the request with a buffer body
.
* @param body
* @return
*/
public Single rxSend(io.vertx.rxjava.core.buffer.Buffer body) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
send(body, fut);
}));
}
/**
* Send the request with a stream body
.
*
* If the {@link io.vertx.rxjava.core.http.HttpHeaders} is set then the request assumes this is the
* length of the {stream}, otherwise the request will set a chunked {@link io.vertx.rxjava.core.http.HttpHeaders}.
* @param body
* @param handler the completion handler for the {@link io.vertx.rxjava.core.http.HttpClientResponse}
*/
public void send(io.vertx.rxjava.core.streams.ReadStream body, Handler> handler) {
delegate.send(body.getDelegate(), new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Send the request with a stream body
.
*
* If the {@link io.vertx.rxjava.core.http.HttpHeaders} is set then the request assumes this is the
* length of the {stream}, otherwise the request will set a chunked {@link io.vertx.rxjava.core.http.HttpHeaders}.
* @param body
*/
public void send(io.vertx.rxjava.core.streams.ReadStream body) {
send(body, ar -> { });
}
/**
* Send the request with a stream body
.
*
* If the {@link io.vertx.rxjava.core.http.HttpHeaders} is set then the request assumes this is the
* length of the {stream}, otherwise the request will set a chunked {@link io.vertx.rxjava.core.http.HttpHeaders}.
* @param body
* @return
*/
public Single rxSend(io.vertx.rxjava.core.streams.ReadStream body) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
send(body, fut);
}));
}
/**
* Send the request with a stream body
.
*
* If the {@link io.vertx.rxjava.core.http.HttpHeaders} is set then the request assumes this is the
* length of the {stream}, otherwise the request will set a chunked {@link io.vertx.rxjava.core.http.HttpHeaders}.
* @param body
* @param handler the completion handler for the {@link io.vertx.rxjava.core.http.HttpClientResponse}
*/
public void send(Observable body, Handler> handler) {
delegate.send(io.vertx.rx.java.ReadStreamSubscriber.asReadStream(body,obj -> (io.vertx.core.buffer.Buffer)obj.getDelegate()).resume(), new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Send the request with a stream body
.
*
* If the {@link io.vertx.rxjava.core.http.HttpHeaders} is set then the request assumes this is the
* length of the {stream}, otherwise the request will set a chunked {@link io.vertx.rxjava.core.http.HttpHeaders}.
* @param body
*/
public void send(Observable body) {
send(body, ar -> { });
}
/**
* Send the request with a stream body
.
*
* If the {@link io.vertx.rxjava.core.http.HttpHeaders} is set then the request assumes this is the
* length of the {stream}, otherwise the request will set a chunked {@link io.vertx.rxjava.core.http.HttpHeaders}.
* @param body
* @return
*/
public Single rxSend(Observable body) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
send(body, fut);
}));
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
* @param chunk
* @param handler
*/
public void end(String chunk, Handler> handler) {
delegate.end(chunk, handler);
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
* @param chunk
*/
public void end(String chunk) {
end(chunk, ar -> { });
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
* @param chunk
* @return
*/
public Single rxEnd(String chunk) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
end(chunk, fut);
}));
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
* @param chunk
* @param enc
* @param handler
*/
public void end(String chunk, String enc, Handler> handler) {
delegate.end(chunk, enc, handler);
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
* @param chunk
* @param enc
*/
public void end(String chunk, String enc) {
end(chunk, enc, ar -> { });
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
* @param chunk
* @param enc
* @return
*/
public Single rxEnd(String chunk, String enc) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
end(chunk, enc, fut);
}));
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
* @param chunk
* @param handler
*/
public void end(io.vertx.rxjava.core.buffer.Buffer chunk, Handler> handler) {
delegate.end(chunk.getDelegate(), handler);
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
* @param chunk
*/
public void end(io.vertx.rxjava.core.buffer.Buffer chunk) {
end(chunk, ar -> { });
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
* @param chunk
* @return
*/
public Single rxEnd(io.vertx.rxjava.core.buffer.Buffer chunk) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
end(chunk, fut);
}));
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
* @param handler
*/
public void end(Handler> handler) {
delegate.end(handler);
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
*/
public void end() {
end(ar -> { });
}
/**
* Same as {@link io.vertx.rxjava.core.http.HttpClientRequest#end} but with an handler
called when the operation completes
* @return
*/
public Single rxEnd() {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
end(fut);
}));
}
/**
* Set's the amount of time after which if the request does not return any data within the timeout period an
* {@link java.util.concurrent.TimeoutException} will be passed to the exception handler (if provided) and
* the request will be closed.
*
* Calling this method more than once has the effect of canceling any existing timeout and starting
* the timeout from scratch.
* @param timeoutMs The quantity of time in milliseconds.
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest setTimeout(long timeoutMs) {
delegate.setTimeout(timeoutMs);
return this;
}
/**
* Set a push handler for this request.
*
* The handler is called when the client receives a push promise from the server. The handler can be called
* multiple times, for each push promise.
*
* The handler is called with a read-only {@link io.vertx.rxjava.core.http.HttpClientRequest}, the following methods can be called:
*
*
* - {@link io.vertx.rxjava.core.http.HttpClientRequest#getMethod}
* - {@link io.vertx.rxjava.core.http.HttpClientRequest#getURI}
* - {@link io.vertx.rxjava.core.http.HttpClientRequest#headers}
*
*
* In addition the handler should call the {@link io.vertx.rxjava.core.http.HttpClientRequest#onComplete} method to set an handler to
* process the response.
* @param handler the handler
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest pushHandler(Handler handler) {
delegate.pushHandler(new Handler() {
public void handle(io.vertx.core.http.HttpClientRequest event) {
handler.handle(io.vertx.rxjava.core.http.HttpClientRequest.newInstance((io.vertx.core.http.HttpClientRequest)event));
}
});
return this;
}
/**
* Reset this stream with the error code 0
.
* @return
*/
public boolean reset() {
boolean ret = delegate.reset();
return ret;
}
/**
* Reset this request:
*
*
* - for HTTP/2, this performs send an HTTP/2 reset frame with the specified error
code
* - for HTTP/1.x, this closes the connection when the current request is inflight
*
*
* When the request has not yet been sent, the request will be aborted and false is returned as indicator.
*
* @param code the error code
* @return true
when reset has been performed
*/
public boolean reset(long code) {
boolean ret = delegate.reset(code);
return ret;
}
/**
* Reset this request:
*
*
* - for HTTP/2, send an HTTP/2 reset frame with the specified error
code
* - for HTTP/1.x, close the connection when the current request is inflight
*
*
* When the request has not yet been sent, the request will be aborted and false
is returned as indicator.
*
* @param code the error code
* @param cause an optional cause that can be attached to the error code
* @return true when reset has been performed
*/
public boolean reset(long code, java.lang.Throwable cause) {
boolean ret = delegate.reset(code, cause);
return ret;
}
/**
* @return the {@link io.vertx.rxjava.core.http.HttpConnection} associated with this request
*/
public io.vertx.rxjava.core.http.HttpConnection connection() {
if (cached_1 != null) {
return cached_1;
}
io.vertx.rxjava.core.http.HttpConnection ret = io.vertx.rxjava.core.http.HttpConnection.newInstance((io.vertx.core.http.HttpConnection)delegate.connection());
cached_1 = ret;
return ret;
}
/**
* Write an HTTP/2 frame to the request, allowing to extend the HTTP/2 protocol.
*
* The frame is sent immediatly and is not subject to flow control.
*
* This method must be called after the request headers have been sent and only for the protocol HTTP/2.
* The {@link io.vertx.rxjava.core.http.HttpClientRequest#sendHead} should be used for this purpose.
* @param type the 8-bit frame type
* @param flags the 8-bit frame flags
* @param payload the frame payload
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest writeCustomFrame(int type, int flags, io.vertx.rxjava.core.buffer.Buffer payload) {
delegate.writeCustomFrame(type, flags, payload.getDelegate());
return this;
}
/**
* @return the id of the stream of this response, when it is not yet determined, i.e the request has not been yet sent or it is not supported HTTP/1.x
*/
public int streamId() {
int ret = delegate.streamId();
return ret;
}
/**
* Like {@link io.vertx.rxjava.core.http.HttpClientRequest#writeCustomFrame} but with an {@link io.vertx.rxjava.core.http.HttpFrame}.
* @param frame the frame to write
* @return
*/
public io.vertx.rxjava.core.http.HttpClientRequest writeCustomFrame(io.vertx.rxjava.core.http.HttpFrame frame) {
delegate.writeCustomFrame(frame.getDelegate());
return this;
}
/**
* Sets the priority of the associated stream.
*
* This is not implemented for HTTP/1.x.
* @param streamPriority the priority of this request's stream
* @return
*/
public io.vertx.rxjava.core.http.HttpClientRequest setStreamPriority(io.vertx.core.http.StreamPriority streamPriority) {
delegate.setStreamPriority(streamPriority);
return this;
}
/**
* @return the priority of the associated HTTP/2 stream for HTTP/2 otherwise null
*/
public io.vertx.core.http.StreamPriority getStreamPriority() {
io.vertx.core.http.StreamPriority ret = delegate.getStreamPriority();
return ret;
}
public io.vertx.rxjava.core.http.HttpClientRequest onComplete(Handler> handler) {
delegate.onComplete(new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
public io.vertx.rxjava.core.http.HttpClientRequest onComplete() {
return
onComplete(ar -> { });
}
public Single rxOnComplete() {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
onComplete(fut);
}));
}
public io.vertx.rxjava.core.http.HttpClientRequest onSuccess(Handler handler) {
delegate.onSuccess(new Handler() {
public void handle(io.vertx.core.http.HttpClientResponse event) {
handler.handle(io.vertx.rxjava.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)event));
}
});
return this;
}
public io.vertx.rxjava.core.http.HttpClientRequest onFailure(Handler handler) {
delegate.onFailure(handler);
return this;
}
/**
* Like {@link io.vertx.rxjava.core.http.HttpClientRequest#putHeader} but using CharSequence
* @param name
* @param value
* @return
*/
public io.vertx.rxjava.core.http.HttpClientRequest putHeader(java.lang.CharSequence name, java.lang.CharSequence value) {
delegate.putHeader(name, value);
return this;
}
/**
* Put an HTTP header with multiple values
* @param name The header name
* @param values The header values
* @return @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpClientRequest putHeader(String name, java.lang.Iterable values) {
delegate.putHeader(name, values);
return this;
}
/**
* Like {@link io.vertx.rxjava.core.http.HttpClientRequest#putHeader} but using CharSequence
* @param name
* @param values
* @return
*/
public io.vertx.rxjava.core.http.HttpClientRequest putHeader(java.lang.CharSequence name, java.lang.Iterable values) {
delegate.putHeader(name, values);
return this;
}
private io.vertx.rxjava.core.MultiMap cached_0;
private io.vertx.rxjava.core.http.HttpConnection cached_1;
public static HttpClientRequest newInstance(io.vertx.core.http.HttpClientRequest arg) {
return arg != null ? new HttpClientRequest(arg) : null;
}
}