Package io.vantiq.client.internal
Class VantiqSession
java.lang.Object
io.vantiq.client.internal.VantiqSession
Internal class that manages the authenticated access and interface
to the Vantiq REST API.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final okhttp3.MediaTypestatic final intstatic final com.google.gson.Gsonstatic final okhttp3.MediaType -
Constructor Summary
ConstructorsConstructorDescriptionVantiqSession(String server) VantiqSession(String server, int apiVersion) VantiqSession(String server, int apiVersion, okhttp3.Authenticator proxyAuthenticator) VantiqSession(String server, okhttp3.Authenticator proxyAuthenticator) -
Method Summary
Modifier and TypeMethodDescriptionvoidAcknowledge the receipt of a reliable messageauthenticate(String username, String password, ResponseHandler responseHandler) Authenticates onto the Vantiq server with the provided credentials.voidclose()Closes the WebSocket to the Vantiq server.Perform a HTTP DELETE request against a given pathdownload(String path, ResponseHandler responseHandler) Downloads the given file.Perform a HTTP GET request against a given pathReturns the current access token.intReturns the API version usedlongGets the connect timeout for the connectionReturns the current idToken.longReturns the read timeout for the connectionReturns the server URL of the Vantiq system.Returns the current target namespace token.Returns the user associated with the connectionlongReturns the write timeout for the connectionbooleanReturns if the current session is authenticated.Perform a HTTP POST request against a specific pathPerform a HTTP PUT request for a specific pathrawGet(String fullPath, Map<String, String> queryParams, Map<String, String> extraHeaders, ResponseHandler responseHandler) Perform a HTTP GET request against a given raw pathrefresh(String accessToken, ResponseHandler responseHandler) Refreshes the supplied accessTokenrevoke(String accessToken, ResponseHandler responseHandler) Authenticates onto the Vantiq server with the provided credentials.voidsetAccessToken(String accessToken) Sets the access token for use in future requests to the Vantiq server.voidsetConnectTimeout(long timeout) Sets the connect timeout for the connectionvoidsetReadTimeout(long timeout) Sets the read timeout for the connectionvoidSets the server URL of the Vantiq system.voidsetTargetNamespace(String targetNamespace) Sets the target namespace for use in future requests to the Vantiq server.voidsetUsername(String username) Sets the user associated with the connection.voidsetWriteTimeout(long timeout) Sets the write timeout for the connectionvoidsubscribe(String path, SubscriptionCallback callback, boolean enablePings, Map<String, Object> parameters) Subscribes to a specific Vantiq event based on the given path.voidUnsubscribes to all current subscriptions by closing the WebSocket to the Vantiq server.upload(String path, File file, String contentType, String documentPath, Map<String, String> queryParams, ResponseHandler responseHandler) Uploads the given file.
-
Field Details
-
APPLICATION_JSON
public static final okhttp3.MediaType APPLICATION_JSON -
PLAIN_TEXT
public static final okhttp3.MediaType PLAIN_TEXT -
gson
public static final com.google.gson.Gson gson -
DEFAULT_API_VERSION
public static final int DEFAULT_API_VERSION- See Also:
-
-
Constructor Details
-
VantiqSession
-
VantiqSession
-
VantiqSession
-
VantiqSession
-
-
Method Details
-
isAuthenticated
public boolean isAuthenticated()Returns if the current session is authenticated.- Returns:
- true if authenticated successfully
-
setAccessToken
Sets the access token for use in future requests to the Vantiq server. This can be a normal or long-lived token. Since the access token is explicitly set, we assume the session is authenticated if the access token is not null.- Parameters:
accessToken- The access token to set
-
setTargetNamespace
Sets the target namespace for use in future requests to the Vantiq server.- Parameters:
targetNamespace- The target namespace to set
-
getIdToken
Returns the current idToken. If not authenticated, this is null.- Returns:
- The idToken or null if not an authenticated session or an old Vantiq server
-
getAccessToken
Returns the current access token. If not authenticated, this is null.- Returns:
- The access token used for requests or null if not an authenticated session.
-
getTargetNamespace
Returns the current target namespace token.- Returns:
- The target namespace used for requests
-
getUsername
Returns the user associated with the connection- Returns:
- The username
-
setUsername
Sets the user associated with the connection.- Parameters:
username- The username
-
setServer
Sets the server URL of the Vantiq system.- Parameters:
server- The server URL
-
getServer
Returns the server URL of the Vantiq system.- Returns:
- The server URL
-
getApiVersion
public int getApiVersion()Returns the API version used- Returns:
- The API version
-
setReadTimeout
public void setReadTimeout(long timeout) Sets the read timeout for the connection- Parameters:
timeout- The timeout duration in milliseconds
-
getReadTimeout
public long getReadTimeout()Returns the read timeout for the connection- Returns:
- The timeout duration in milliseconds
-
setWriteTimeout
public void setWriteTimeout(long timeout) Sets the write timeout for the connection- Parameters:
timeout- The timeout duration in milliseconds
-
getWriteTimeout
public long getWriteTimeout()Returns the write timeout for the connection- Returns:
- The timeout duration in milliseconds
-
setConnectTimeout
public void setConnectTimeout(long timeout) Sets the connect timeout for the connection- Parameters:
timeout- The timeout duration in milliseconds
-
getConnectTimeout
public long getConnectTimeout()Gets the connect timeout for the connection- Returns:
- The timeout duration in milliseconds
-
authenticate
public VantiqResponse authenticate(String username, String password, ResponseHandler responseHandler) Authenticates onto the Vantiq server with the provided credentials. After this call completes, the credentials are not stored.- Parameters:
username- The username for the Vantiq serverpassword- The password for the Vantiq serverresponseHandler- The response handler that is called upon completion. If null, then the call is performed synchronously and the response is provided as the returned value.- Returns:
- The response from the Vantiq server
-
revoke
Authenticates onto the Vantiq server with the provided credentials. After this call completes, the credentials are not stored.- Parameters:
accessToken- The accessToken to be revokedresponseHandler- The response handler that is called upon completion. If null, then the call is performed synchronously and the response is provided as the returned value.- Returns:
- The response from the Vantiq server
-
refresh
Refreshes the supplied accessToken- Parameters:
accessToken- The accessToken to be refreshedresponseHandler- The response handler that is called upon completion. If null, then the call is performed synchronously and the response is provided as the returned value.- Returns:
- The response from the Vantiq server
-
rawGet
public VantiqResponse rawGet(String fullPath, Map<String, String> queryParams, Map<String, String> extraHeaders, ResponseHandler responseHandler) Perform a HTTP GET request against a given raw path- Parameters:
fullPath- The unencoded partial path for the GET (without any query parameters)queryParams- The unencoded query parameters included in the requestextraHeaders- optional headersresponseHandler- The response handler that is called upon completion. If null, then the call is performed synchronously and the response is provided as the returned value.- Returns:
- The response from the Vantiq server
-
get
public VantiqResponse get(String path, Map<String, String> queryParams, ResponseHandler responseHandler) Perform a HTTP GET request against a given path- Parameters:
path- The unencoded partial path for the GET (without any query parameters)queryParams- The unencoded query parameters included in the requestresponseHandler- The response handler that is called upon completion. If null, then the call is performed synchronously and the response is provided as the returned value.- Returns:
- The response from the Vantiq server
-
post
public VantiqResponse post(String path, Map<String, String> queryParams, String body, ResponseHandler responseHandler) Perform a HTTP POST request against a specific path- Parameters:
path- The unencoded partial path for the POST (without any query parameters)queryParams- The unencoded query parameters included in the requestbody- The JSON encoding string included in the body of the requestresponseHandler- The response handler that is called upon completion. If null, then the call is performed synchronously and the response is provided as the returned value.- Returns:
- The response from the Vantiq server
-
put
public VantiqResponse put(String path, Map<String, String> queryParams, String body, ResponseHandler responseHandler) Perform a HTTP PUT request for a specific path- Parameters:
path- The unencoded partial path for the PUT (without any query parameters)queryParams- The unencoded query parameters included in the requestbody- The JSON encoding string included in the body of the requestresponseHandler- The response handler that is called upon completion. If null, then the call is performed synchronously and the response is provided as the returned value.- Returns:
- The response from the Vantiq server
-
delete
public VantiqResponse delete(String path, Map<String, String> queryParams, ResponseHandler responseHandler) Perform a HTTP DELETE request against a given path- Parameters:
path- The unencoded partial path for the DELETE (without any query parameters)queryParams- The unencoded query parameters included in the requestresponseHandler- The response handler that is called upon completion. If null, then the call is performed synchronously and the response is provided as the returned value.- Returns:
- The response from the Vantiq server
-
upload
public VantiqResponse upload(String path, File file, String contentType, String documentPath, Map<String, String> queryParams, ResponseHandler responseHandler) Uploads the given file.- Parameters:
path- The path for the resource to upload into (usually "/resources/documents", "/resources/images" or "resources/videos")file- The file to uploadcontentType- The MIME type of the file uploadeddocumentPath- The path of the file in the Vantiq systemqueryParams- The unencoded query parameters included in the requestresponseHandler- The response handler that is called upon completion. If null, then the call is performed synchronously and the response is provided as the returned value.- Returns:
- The response from the Vantiq server
-
download
Downloads the given file. The response body will be a stream that can be used to download the content of the file.- Parameters:
path- The path of the file to downloadresponseHandler- The response handler that is called upon completion. If null, then the call is performed synchronously and the response is provided as the returned value.- Returns:
- The response from the Vantiq server
-
subscribe
public void subscribe(String path, SubscriptionCallback callback, boolean enablePings, Map<String, Object> parameters) Subscribes to a specific Vantiq event based on the given path. A websocket connection is used to listen for the events. If no connection is already established, then a connection is initiated.- Parameters:
path- The path that defines the event (e.g. /resource/id[/operation])callback- The callback that is executed for every event that occurs.enablePings- Indicates if pings should be enabled to ensure the websocket stays openparameters- Parameters
-
ack
public void ack(String requestId, String subscriptionId, Double sequenceId, Double partitionId) throws IOException Acknowledge the receipt of a reliable message- Parameters:
requestId- Request IdsubscriptionId- Subscription IdsequenceId- Sequence IdpartitionId- Partition Id- Throws:
IOException- If request fails
-
unsubscribeAll
public void unsubscribeAll()Unsubscribes to all current subscriptions by closing the WebSocket to the Vantiq server. -
close
public void close()Closes the WebSocket to the Vantiq server.
-