Class VantiqSession

java.lang.Object
io.vantiq.client.internal.VantiqSession

public class VantiqSession extends Object
Internal class that manages the authenticated access and interface to the Vantiq REST API.
  • 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

      public VantiqSession(String server)
    • VantiqSession

      public VantiqSession(String server, okhttp3.Authenticator proxyAuthenticator)
    • VantiqSession

      public VantiqSession(String server, int apiVersion)
    • VantiqSession

      public VantiqSession(String server, int apiVersion, okhttp3.Authenticator proxyAuthenticator)
  • Method Details

    • isAuthenticated

      public boolean isAuthenticated()
      Returns if the current session is authenticated.
      Returns:
      true if authenticated successfully
    • setAccessToken

      public void setAccessToken(String accessToken)
      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

      public void setTargetNamespace(String targetNamespace)
      Sets the target namespace for use in future requests to the Vantiq server.
      Parameters:
      targetNamespace - The target namespace to set
    • getIdToken

      public String 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

      public String 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

      public String getTargetNamespace()
      Returns the current target namespace token.
      Returns:
      The target namespace used for requests
    • getUsername

      public String getUsername()
      Returns the user associated with the connection
      Returns:
      The username
    • setUsername

      public void setUsername(String username)
      Sets the user associated with the connection.
      Parameters:
      username - The username
    • setServer

      public void setServer(String server)
      Sets the server URL of the Vantiq system.
      Parameters:
      server - The server URL
    • getServer

      public String 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 server
      password - The password for the Vantiq server
      responseHandler - 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

      public VantiqResponse revoke(String accessToken, ResponseHandler responseHandler)
      Authenticates onto the Vantiq server with the provided credentials. After this call completes, the credentials are not stored.
      Parameters:
      accessToken - The accessToken to be revoked
      responseHandler - 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

      public VantiqResponse refresh(String accessToken, ResponseHandler responseHandler)
      Refreshes the supplied accessToken
      Parameters:
      accessToken - The accessToken to be refreshed
      responseHandler - 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 request
      extraHeaders - optional headers
      responseHandler - 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 request
      responseHandler - 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 request
      body - The JSON encoding string included in the body of the request
      responseHandler - 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 request
      body - The JSON encoding string included in the body of the request
      responseHandler - 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 request
      responseHandler - 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 upload
      contentType - The MIME type of the file uploaded
      documentPath - The path of the file in the Vantiq system
      queryParams - The unencoded query parameters included in the request
      responseHandler - 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

      public VantiqResponse download(String path, ResponseHandler responseHandler)
      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 download
      responseHandler - 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 open
      parameters - 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 Id
      subscriptionId - Subscription Id
      sequenceId - Sequence Id
      partitionId - 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.