Class RestServiceClient


  • public class RestServiceClient
    extends java.lang.Object
    Implements an HTTP / REST client.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected RestServiceClient​(java.lang.String baseUri, boolean verifyCertificate, com.smartgridready.ns.v0.RestApiServiceCall serviceCall, com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory)
      Constructs a new instance with empty substitution properties.
      protected RestServiceClient​(java.lang.String baseUri, boolean verifyCertificate, com.smartgridready.ns.v0.RestApiServiceCall serviceCall, com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory, java.util.Map<java.lang.String,​java.lang.String> substitutions)
      Constructs a new instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addHeader​(java.lang.String key, java.lang.String value)
      Adds a new request header.
      com.smartgridready.driver.api.http.GenHttpResponse callService()
      Executes the HTTP request.
      java.lang.String getBaseUri()
      Gets the request's base URI.
      com.smartgridready.ns.v0.RestApiServiceCall getRestServiceCall()
      Gets the SGr specification of the service call.
      boolean isVerifyCertificate()
      Tells if SSL certificates are to be verified.
      static RestServiceClient of​(java.lang.String baseUri, boolean verifyCertificate, com.smartgridready.ns.v0.RestApiServiceCall serviceCall, com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory)
      Creates a new instance.
      static RestServiceClient of​(java.lang.String baseUri, boolean verifyCertificate, com.smartgridready.ns.v0.RestApiServiceCall serviceCall, com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory, java.util.Map<java.lang.String,​java.lang.String> substitutions)
      Creates a new instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RestServiceClient

        protected RestServiceClient​(java.lang.String baseUri,
                                    boolean verifyCertificate,
                                    com.smartgridready.ns.v0.RestApiServiceCall serviceCall,
                                    com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory)
                             throws java.io.IOException
        Constructs a new instance with empty substitution properties.
        Parameters:
        baseUri - the base URI for all service calls
        verifyCertificate - enables or disables SSL certificate validation
        serviceCall - the service call specification
        httpClientFactory - the HTTP client factory implementation
        Throws:
        java.io.IOException - when the specification contains errors
      • RestServiceClient

        protected RestServiceClient​(java.lang.String baseUri,
                                    boolean verifyCertificate,
                                    com.smartgridready.ns.v0.RestApiServiceCall serviceCall,
                                    com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory,
                                    java.util.Map<java.lang.String,​java.lang.String> substitutions)
                             throws java.io.IOException
        Constructs a new instance.
        Parameters:
        baseUri - the base URI for all service calls
        verifyCertificate - enables or disables SSL certificate validation
        serviceCall - the service call specification
        httpClientFactory - the HTTP client factory implementation
        substitutions - the parameter substitutions
        Throws:
        java.io.IOException - when the specification contains errors
    • Method Detail

      • addHeader

        public void addHeader​(java.lang.String key,
                              java.lang.String value)
        Adds a new request header.
        Parameters:
        key - the header name
        value - the header value
      • getBaseUri

        public java.lang.String getBaseUri()
        Gets the request's base URI.
        Returns:
        a string
      • isVerifyCertificate

        public boolean isVerifyCertificate()
        Tells if SSL certificates are to be verified.
        Returns:
        a boolean
      • getRestServiceCall

        public com.smartgridready.ns.v0.RestApiServiceCall getRestServiceCall()
        Gets the SGr specification of the service call.
        Returns:
        an instance of RestApiServiceCall
      • callService

        public com.smartgridready.driver.api.http.GenHttpResponse callService()
                                                                       throws java.io.IOException
        Executes the HTTP request.
        Returns:
        an instance of GenHttpResponse
        Throws:
        java.io.IOException - when an error occurred
      • of

        public static RestServiceClient of​(java.lang.String baseUri,
                                           boolean verifyCertificate,
                                           com.smartgridready.ns.v0.RestApiServiceCall serviceCall,
                                           com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory)
                                    throws java.io.IOException
        Creates a new instance.
        Parameters:
        baseUri - the base URI
        verifyCertificate - SSL certificate will be verified when true
        serviceCall - the SGr specification of the service call
        httpClientFactory - the SGr HTTP client factory
        Returns:
        a new instance of RestServiceClient
        Throws:
        java.io.IOException - when an error occurred
      • of

        public static RestServiceClient of​(java.lang.String baseUri,
                                           boolean verifyCertificate,
                                           com.smartgridready.ns.v0.RestApiServiceCall serviceCall,
                                           com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory,
                                           java.util.Map<java.lang.String,​java.lang.String> substitutions)
                                    throws java.io.IOException
        Creates a new instance.
        Parameters:
        baseUri - the base URI
        verifyCertificate - SSL certificate will be verified when true
        serviceCall - the SGr specification of the service call
        httpClientFactory - the SGr HTTP client factory
        substitutions - substitutions of dynamic request parameters
        Returns:
        a new instance of RestServiceClient
        Throws:
        java.io.IOException - when an error occurred