public class RestClient extends Object
| Constructor and Description |
|---|
RestClient(String host,
int port,
boolean tls,
String context)
Creates a rest client that communications using protobuf
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCookie(io.netty.handler.codec.http.cookie.Cookie c) |
void |
close() |
CompletableFuture<byte[]> |
doBaseRequest(String resource,
io.netty.handler.codec.http.HttpMethod method,
byte[] body)
Perform asynchronously the request indicated by the HTTP method and return the result as a future providing byte
array.
|
CompletableFuture<Void> |
doBulkRequest(io.netty.handler.codec.http.HttpMethod method,
String resource,
BulkRestDataReceiver receiver) |
CompletableFuture<Void> |
doBulkRequest(io.netty.handler.codec.http.HttpMethod method,
String resource,
byte[] body,
BulkRestDataReceiver receiver)
Performs a bulk request and provides the result piece by piece to the receiver.
|
CompletableFuture<BulkRestDataSender> |
doBulkSendRequest(String resource,
io.netty.handler.codec.http.HttpMethod method) |
CompletableFuture<byte[]> |
doRequest(String resource,
io.netty.handler.codec.http.HttpMethod method)
Performs a request with an empty body.
|
CompletableFuture<byte[]> |
doRequest(String resource,
io.netty.handler.codec.http.HttpMethod method,
byte[] body)
Perform asynchronously the request indicated by the HTTP method and return the result as a future providing byte
array.
|
CompletableFuture<byte[]> |
doRequest(String resource,
io.netty.handler.codec.http.HttpMethod method,
com.google.protobuf.Message message)
Perform asynchronously the request indicated by the HTTP method and return the result as a future providing byte
array.
|
CompletableFuture<String> |
doRequest(String resource,
io.netty.handler.codec.http.HttpMethod method,
String body)
Perform asynchronously the request indicated by the HTTP method and return the result as a future providing byte
array.
|
List<io.netty.handler.codec.http.cookie.Cookie> |
getCookies() |
Credentials |
getCredentials() |
boolean |
isAutoclose() |
boolean |
isInsecureTls() |
void |
login(String username,
char[] password) |
void |
loginWithAuthorizationCode(String authorizationCode) |
static int |
readVarInt32(ByteBuffer bb) |
void |
setAcceptMediaType(String acceptMediaType) |
void |
setAutoclose(boolean autoclose)
if autoclose is set, the httpClient will be automatically closed at the end of the request, so the netty
eventgroup is shutdown.
|
void |
setCaCertFile(String caCertFile)
In case of https connections, this file contains the CA certificates that are used to verify server certificate.
|
void |
setInsecureTls(boolean insecureTls)
if true and https connections are used, do not verify server certificate
|
void |
setMaxResponseLength(int size) |
void |
setSendMediaType(String sendMediaType) |
public void login(String username, char[] password) throws ClientException
ClientExceptionpublic void loginWithAuthorizationCode(String authorizationCode) throws ClientException
ClientExceptionpublic CompletableFuture<byte[]> doRequest(String resource, io.netty.handler.codec.http.HttpMethod method)
resource - method - public CompletableFuture<String> doRequest(String resource, io.netty.handler.codec.http.HttpMethod method, String body)
resource - the url and query parameters after the "/api" part.method - http method to usebody - the body of the request. Can be used even for the GET requests although strictly not allowed by the
HTTP standard.IllegalArgumentException - when the resource specification is invalidpublic CompletableFuture<byte[]> doRequest(String resource, io.netty.handler.codec.http.HttpMethod method, com.google.protobuf.Message message)
resource - method - message - public CompletableFuture<byte[]> doRequest(String resource, io.netty.handler.codec.http.HttpMethod method, byte[] body)
resource - method - body - protobuf encoded data.public CompletableFuture<byte[]> doBaseRequest(String resource, io.netty.handler.codec.http.HttpMethod method, byte[] body)
resource - method - body - protobuf encoded data.public CompletableFuture<Void> doBulkRequest(io.netty.handler.codec.http.HttpMethod method, String resource, BulkRestDataReceiver receiver)
public CompletableFuture<Void> doBulkRequest(io.netty.handler.codec.http.HttpMethod method, String resource, byte[] body, BulkRestDataReceiver receiver)
method - resource - receiver - RuntimeException - if the uri + resource does not form a correct URLpublic static int readVarInt32(ByteBuffer bb) throws ClientException
ClientExceptionpublic void setSendMediaType(String sendMediaType)
public void setAcceptMediaType(String acceptMediaType)
public void setMaxResponseLength(int size)
public void close()
public boolean isAutoclose()
public Credentials getCredentials()
public void setAutoclose(boolean autoclose)
autoclose - public void addCookie(io.netty.handler.codec.http.cookie.Cookie c)
public List<io.netty.handler.codec.http.cookie.Cookie> getCookies()
public CompletableFuture<BulkRestDataSender> doBulkSendRequest(String resource, io.netty.handler.codec.http.HttpMethod method)
public boolean isInsecureTls()
public void setInsecureTls(boolean insecureTls)
insecureTls - public void setCaCertFile(String caCertFile) throws IOException, GeneralSecurityException
caCertFile - IOExceptionGeneralSecurityExceptionCopyright © 2022 Space Applications Services. All rights reserved.