Package org.yamcs.client.base
Class RestClient
java.lang.Object
org.yamcs.client.base.RestClient
A simple Yamcs Rest client to help with basic requests.
-
Constructor Summary
ConstructorDescriptionRestClient
(ServerURL serverURL) Creates a rest client that communications using protobuf -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCookie
(io.netty.handler.codec.http.cookie.Cookie c) authorizeKerberos
(SpnegoInfo info) 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.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.doBulkRequest
(io.netty.handler.codec.http.HttpMethod method, String resource, BulkRestDataReceiver receiver) doBulkSendRequest
(String resource, io.netty.handler.codec.http.HttpMethod method) CompletableFuture<byte[]>
Performs a request with an empty body.CompletableFuture<byte[]>
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.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>
boolean
boolean
void
void
loginWithAuthorizationCode
(String authorizationCode) static int
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
setCredentials
(Credentials credentials) void
setInsecureTls
(boolean insecureTls) if true and https connections are used, do not verify server certificatevoid
setMaxResponseLength
(int size) void
setSendMediaType
(String sendMediaType) void
setUserAgent
(String userAgent)
-
Constructor Details
-
RestClient
Creates a rest client that communications using protobuf
-
-
Method Details
-
login
- Throws:
ClientException
-
loginWithAuthorizationCode
- Throws:
ClientException
-
authorizeKerberos
- Throws:
ClientException
-
doRequest
public CompletableFuture<byte[]> doRequest(String resource, io.netty.handler.codec.http.HttpMethod method) Performs a request with an empty body. Works using protobuf- Parameters:
resource
-method
-- Returns:
- a the response body
-
doRequest
public 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. Note that the response body will be limited to 10485760 - in case the server sends more than that, the CompletableFuture will completed with an error (the get() method will throw an Exception); the partial response will not be available.- Parameters:
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.- Returns:
- the response body
- Throws:
IllegalArgumentException
- when the resource specification is invalid
-
doRequest
public 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. To be used when performing protobuf requests.- Parameters:
resource
-method
-message
-- Returns:
- future containing protobuf encoded data
-
doRequest
public 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. To be used when performing protobuf requests.- Parameters:
resource
-method
-body
- protobuf encoded data.- Returns:
- future containing protobuf encoded data
-
doBaseRequest
public 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. To be used when performing protobuf requests.- Parameters:
resource
-method
-body
- protobuf encoded data.- Returns:
- future containing protobuf encoded data
-
doBulkRequest
public CompletableFuture<Void> doBulkRequest(io.netty.handler.codec.http.HttpMethod method, String resource, BulkRestDataReceiver receiver) -
doBulkRequest
public 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. The potentially large result is split into messages based on the VarInt size preceding each message. The maximum size of each individual message is limited to 10485760- Parameters:
method
-resource
-receiver
-- Returns:
- future that is completed when the request is finished
- Throws:
RuntimeException
- if the uri + resource does not form a correct URL
-
readVarInt32
- Throws:
ClientException
-
setSendMediaType
-
setAcceptMediaType
-
setMaxResponseLength
public void setMaxResponseLength(int size) -
setUserAgent
-
close
public void close() -
isAutoclose
public boolean isAutoclose() -
getCredentials
-
setCredentials
-
setAutoclose
public 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. Otherwise it has to be done manually - but then the same object can be used to perform multiple requests.- Parameters:
autoclose
-
-
addCookie
public void addCookie(io.netty.handler.codec.http.cookie.Cookie c) -
getCookies
-
doBulkSendRequest
public CompletableFuture<BulkRestDataSender> doBulkSendRequest(String resource, io.netty.handler.codec.http.HttpMethod method) -
isInsecureTls
public boolean isInsecureTls() -
setInsecureTls
public void setInsecureTls(boolean insecureTls) if true and https connections are used, do not verify server certificate- Parameters:
insecureTls
-
-
setCaCertFile
In case of https connections, this file contains the CA certificates that are used to verify server certificate. If this is not set, java will use the default mechanism with the trustStore that can be configured via the javax.net.ssl.trustStore system property.- Parameters:
caCertFile
-- Throws:
IOException
GeneralSecurityException
-