Class CuiRestClientBuilder

java.lang.Object
de.cuioss.portal.restclient.CuiRestClientBuilder

public class CuiRestClientBuilder extends Object
Builder for a JAVA MicroProfile based REST client.

To enable log debugging / tracing set package de.cuioss.portal.core.restclient to TRACE level in your logger configuration.

  • Field Details

  • Constructor Details

    • CuiRestClientBuilder

      public CuiRestClientBuilder(de.cuioss.tools.logging.CuiLogger logger)
      Creates a REST client builder.

      Enables the trace-logging, if either the given logger or the CuiRestClientBuilder logger returns true for CuiLogger.isTraceEnabled().

      Parameters:
      logger - for trace-logging.
  • Method Details

    • debugResponse

      public static void debugResponse(Response response, de.cuioss.tools.logging.CuiLogger log)
      Debugs a given Response to the given logger
      Parameters:
      response - must not be null
      log - must not be null
    • connectionMetadata

      public CuiRestClientBuilder connectionMetadata(de.cuioss.portal.configuration.connections.impl.ConnectionMetadata connectionMeta)
      Sets various properties based on the given connectionMeta.
      • service url
      • tracing enabled
      • ssl context
      • login credentials
      • context map
      • hostname verifier
      • connection timeout
      • read timeout
      Returns:
      this builder
    • traceLogEnabled

      public CuiRestClientBuilder traceLogEnabled(boolean value)
      Parameters:
      value - Enable|Disable trace logging capabilities for this REST client. Defaults to CuiLogger.isTraceEnabled() for the given logger. This is unrelated to the distributed tracing capabilities.
      Returns:
      this builder
      See Also:
      • LogClientRequestFilter
      • LogReaderInterceptor
    • register

      public CuiRestClientBuilder register(Object component)
      Parameters:
      component - to be registered
      Returns:
      this builder
      See Also:
    • register

      public CuiRestClientBuilder register(Object component, int priority)
      Parameters:
      component - to be registered
      priority - overwrite value for the components Priority
      Returns:
      this builder
      See Also:
    • property

      Parameters:
      key - property key to be registered
      value - property value to be registered
      Returns:
      this builder
      See Also:
    • enableDefaultExceptionHandler

      Enables the RestEasy default exception mapper for this MP REST client. Per default, this exception mapper is disabled. It registers it with priority Integer.MIN_VALUE, instead of Integer.MAX_VALUE, to allow trace-logging of responses.

      Effect: Every response code of >=400 throws a general WebApplicationException.

      Returns:
      this builder
    • disableDefaultExceptionHandler

      Disables the RestEasy default exception mapper for this MP REST client. Per default, this exception mapper is disabled.

      Effect: Exceptions like BadRequestException are thrown instead of a general WebApplicationException.

      Returns:
      this builder
    • url

      Adds the target url
      Parameters:
      url - to be passed to he contained builder
      Returns:
      this builder
    • url

      Adds the target url
      Parameters:
      url - to be passed to he contained builder
      Returns:
      this builder
    • uri

      Adds the target uri
      Parameters:
      uri - to be passed to he contained builder
      Returns:
      this builder
    • basicAuth

      public CuiRestClientBuilder basicAuth(String username, String password)
      Adds the credentials for basic-auth
      Parameters:
      username - to be passed to he contained builder
      password - to be passed to he contained builder
      Returns:
      this builder
    • bearerAuthToken

      Adds the credentials for bearer-auth
      Parameters:
      token - to be passed to he contained builder
      Returns:
      this builder
    • registerExceptionMapper

      public CuiRestClientBuilder registerExceptionMapper(org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper<?> mapper)
      Adds the ResponseExceptionMapper
      Parameters:
      mapper - to be passed to he contained builder
      Returns:
      this builder
    • sslContext

      Adds the sslContext
      Parameters:
      sslContext - to be passed to he contained builder
      Returns:
      this builder
    • connectTimeout

      public CuiRestClientBuilder connectTimeout(long amount, TimeUnit timeUnit)
      Adds the connection timeout
      Parameters:
      amount - to be passed to he contained builder
      timeUnit - to be passed to he contained builder
      Returns:
      this builder
    • readTimeout

      public CuiRestClientBuilder readTimeout(long amount, TimeUnit timeUnit)
      Adds the read timeout
      Parameters:
      amount - to be passed to he contained builder
      timeUnit - to be passed to he contained builder
      Returns:
      this builder
    • queryParamStyle

      public CuiRestClientBuilder queryParamStyle(org.eclipse.microprofile.rest.client.ext.QueryParamStyle queryParamStyle)
      Adds the QueryParamStyle
      Parameters:
      queryParamStyle - to be passed to he contained builder
      Returns:
      this builder
    • proxyAddress

      public CuiRestClientBuilder proxyAddress(String host, int port)
      Adds the proxy address
      Parameters:
      host - to be passed to he contained builder
      port - to be passed to he contained builder
      Returns:
      this builder
    • followRedirects

      public CuiRestClientBuilder followRedirects(boolean followRedirects)
      Adds the followRedirects
      Parameters:
      followRedirects - to be passed to he contained builder
      Returns:
      this builder
    • hostnameVerifier

      Adds the hostnameVerifier
      Parameters:
      hostnameVerifier - to be passed to he contained builder
      Returns:
      this builder
    • getConfiguration

      Returns:
      the current configuration of the contained builder
    • build

      public <T extends Closeable> T build(Class<T> clazz)
      Create an implementation of the service interface T using the rest client.
      Type Parameters:
      T - the service type
      Parameters:
      clazz - the service interface which also must extend Closeable
      Returns:
      T the service class