Package nl.vpro.api.client.resteasy
Class AbstractApiClient
- java.lang.Object
-
- nl.vpro.api.client.resteasy.AbstractApiClient
-
- All Implemented Interfaces:
AutoCloseable
,AbstractApiClientMXBean
public abstract class AbstractApiClient extends Object implements AbstractApiClientMXBean, AutoCloseable
- Since:
- 3.0
- Author:
- Roelof Jan Koekoek
-
-
Field Summary
Fields Modifier and Type Field Description protected javax.ws.rs.core.MediaType
accept
protected List<Locale>
acceptableLanguages
protected String
baseUrl
protected boolean
browserCache
protected Integer
bucketCount
protected ClassLoader
classLoader
protected Duration
connectionInPoolTTL
protected Duration
connectionRequestTimeout
protected Duration
connectTimeout
protected javax.ws.rs.core.MediaType
contentType
protected Map<String,Counter>
counter
protected Duration
countWindow
protected boolean
eager
protected org.slf4j.Logger
log
protected Integer
maxConnections
protected Integer
maxConnectionsNoTimeout
protected Integer
maxConnectionsPerRoute
protected Integer
maxConnectionsPerRouteNoTimeout
protected String
mbeanName
protected Jackson2Mapper
objectMapper
protected boolean
registerMBean
protected Duration
socketTimeout
protected boolean
trustAll
protected String
userAgent
protected Duration
validateAfterInactivity
protected Duration
warnThreshold
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractApiClient(String baseUrl, Duration connectionRequestTimeout, Duration connectTimeout, Duration socketTimeout, Integer maxConnections, Integer maxConnectionsPerRoute, Integer maxConnectionsNoTimeout, Integer maxConnectionsPerRouteNoTimeout, Duration connectionInPoolTTL, Duration countWindow, Integer bucketCount, Duration warnThreshold, List<Locale> acceptableLanguages, javax.ws.rs.core.MediaType accept, javax.ws.rs.core.MediaType contentType, Boolean trustAll, Jackson2Mapper objectMapper, String mbeanName, ClassLoader classLoader, String userAgent, Boolean registerMBean)
Deprecated.protected
AbstractApiClient(String baseUrl, Duration connectionRequestTimeout, Duration connectTimeout, Duration socketTimeout, Integer maxConnections, Integer maxConnectionsPerRoute, Integer maxConnectionsNoTimeout, Integer maxConnectionsPerRouteNoTimeout, Duration connectionInPoolTTL, Duration validateAfterInactivity, Duration countWindow, Integer bucketCount, Duration warnThreshold, List<Locale> acceptableLanguages, javax.ws.rs.core.MediaType accept, javax.ws.rs.core.MediaType contentType, Boolean trustAll, Jackson2Mapper objectMapper, String mbeanName, ClassLoader classLoader, String userAgent, Boolean registerMBean, boolean eager)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
appendTestResult(StringBuilder builder, String arg)
protected <T> T
build(Class<T> service)
protected <T> T
build(Class<T> service, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
protected <T> T
build(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service)
protected <T,S,E>
Tbuild(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<S> restEasyService, Class<E> errorClass, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
protected <T,S>
Tbuild(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<S> restEasyInterface, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
protected <T> T
build(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
protected void
buildResteasy(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder builder)
For further building the client you can override this method.protected <T> T
buildWithErrorClass(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<?> errorClass)
protected <T> T
buildWithErrorClass(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<?> errorClass, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
protected <T,S>
TbuildWithErrorClass(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<S> restEasyInterface, Class<?> errorClass)
protected <T,S>
TbuildWithErrorClass(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<S> restEasyInterface, Class<?> errorClass, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
void
clearBrowserCache()
void
close()
protected void
closeClients()
protected org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder
defaultResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine)
protected void
finalize()
javax.ws.rs.core.MediaType
getAccept()
List<Locale>
getAcceptableLanguages()
String
getBaseUrl()
org.jboss.resteasy.client.jaxrs.cache.BrowserCache
getBrowserCache()
Integer
getBucketCount()
org.jboss.resteasy.client.jaxrs.ClientHttpEngine
getClientHttpEngine()
org.jboss.resteasy.client.jaxrs.ClientHttpEngine
getClientHttpEngineNoTimeout()
String
getConnectionInPoolTTL()
String
getConnectionRequestTimeout()
String
getConnectTimeout()
javax.ws.rs.core.MediaType
getContentType()
long
getCount(String method)
String
getCounts()
String
getCountWindowString()
protected String
getInfo()
String
getInitializationInstant()
Integer
getMaxConnections()
Integer
getMaxConnectionsNoTimeout()
Integer
getMaxConnectionsPerRoute()
Integer
getMaxConnectionsPerRouteNoTimeout()
Jackson2Mapper
getObjectMapper()
protected ObjectName
getObjectName()
double
getRate()
String
getSocketTimeout()
protected org.jboss.resteasy.client.jaxrs.ResteasyWebTarget
getTarget(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine)
protected org.jboss.resteasy.client.jaxrs.ResteasyWebTarget
getTarget(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
long
getTotalCount()
static String
getUserAgent(String name, String version)
String
getValidateAfterInactivity()
protected String
getVersion(String prop, ClassLoader loader)
Duration
getWarnThreshold()
String
getWarnThresholdString()
void
invalidate()
void
postConstruct()
protected <T> T
produceIfNull(Supplier<T> supplier, Supplier<T> producer)
Checks whether supplier has null, if so produces it while locking, so it happens only onceprotected <T> T
proxyCounter(Class<T> service, T proxy)
protected <T> T
proxyErrors(Class<T> service, T proxy)
protected <T,E>
TproxyErrors(Class<T> service, T proxy, Class<E> errorClass)
protected <T> T
proxyErrorsAndCount(Class<T> service, T proxy)
protected <T,E>
TproxyErrorsAndCount(Class<T> service, T proxy, Class<E> errorClass)
protected org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder
resteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
protected abstract Stream<Supplier<?>>
services()
void
setAccept(javax.ws.rs.core.MediaType mediaType)
void
setAcceptableLanguages(List<Locale> acceptableLanguages)
void
setBaseUrl(String url)
void
setBrowserCache(boolean browserCache)
void
setBrowserCache(javax.cache.Cache<?,?> browserCache)
Default the client is backed by aLightweightBrowserCache
, you may replace it byJavaxBrowserCache
, backed with a more genericCache
, so that the client can hitch on your preferred caching framework.void
setBrowserCache(org.jboss.resteasy.client.jaxrs.cache.BrowserCache browserCache)
void
setBucketCount(Integer bucketCount)
void
setConnectionInPoolTTL(String connectionInPoolTTLAsAstring)
void
setConnectionRequestTimeout(String connectionRequestTimeout)
void
setConnectTimeout(String connectTimeout)
void
setContentType(javax.ws.rs.core.MediaType mediaType)
void
setCountWindow(Duration countWindow)
void
setCountWindowString(String countWindow)
void
setMaxConnections(Integer maxConnections)
void
setMaxConnectionsNoTimeout(Integer maxConnectionsNoTimeout)
void
setMaxConnectionsPerRoute(Integer maxConnectionsPerRoute)
void
setMaxConnectionsPerRouteNoTimeout(Integer maxConnectionsPerRouteNoTimeout)
void
setObjectMapper(Jackson2Mapper objectMapper)
void
setSocketTimeout(String socketTimeout)
void
setTrustAll(boolean b)
void
setValidateAfterInactivity(String validateAfterInactivityAsString)
void
setWarnThreshold(Duration warnThreshold)
void
setWarnThresholdString(String warnThreshold)
void
shutdown()
String
test(String arg)
protected String
toString(Object service)
-
-
-
Field Detail
-
log
protected org.slf4j.Logger log
-
baseUrl
protected String baseUrl
-
trustAll
protected boolean trustAll
-
connectionRequestTimeout
protected Duration connectionRequestTimeout
-
connectTimeout
protected Duration connectTimeout
-
socketTimeout
protected Duration socketTimeout
-
maxConnections
protected Integer maxConnections
-
maxConnectionsPerRoute
protected Integer maxConnectionsPerRoute
-
maxConnectionsNoTimeout
protected Integer maxConnectionsNoTimeout
-
maxConnectionsPerRouteNoTimeout
protected Integer maxConnectionsPerRouteNoTimeout
-
connectionInPoolTTL
protected Duration connectionInPoolTTL
-
validateAfterInactivity
protected Duration validateAfterInactivity
-
countWindow
protected Duration countWindow
-
bucketCount
protected Integer bucketCount
-
warnThreshold
protected Duration warnThreshold
-
accept
protected javax.ws.rs.core.MediaType accept
-
contentType
protected javax.ws.rs.core.MediaType contentType
-
browserCache
protected boolean browserCache
-
mbeanName
protected String mbeanName
-
registerMBean
protected boolean registerMBean
-
objectMapper
protected Jackson2Mapper objectMapper
-
classLoader
protected ClassLoader classLoader
-
userAgent
protected final String userAgent
-
eager
protected boolean eager
-
-
Constructor Detail
-
AbstractApiClient
@Deprecated protected AbstractApiClient(String baseUrl, Duration connectionRequestTimeout, Duration connectTimeout, Duration socketTimeout, Integer maxConnections, Integer maxConnectionsPerRoute, Integer maxConnectionsNoTimeout, Integer maxConnectionsPerRouteNoTimeout, Duration connectionInPoolTTL, Duration countWindow, Integer bucketCount, Duration warnThreshold, List<Locale> acceptableLanguages, javax.ws.rs.core.MediaType accept, javax.ws.rs.core.MediaType contentType, Boolean trustAll, Jackson2Mapper objectMapper, String mbeanName, ClassLoader classLoader, String userAgent, Boolean registerMBean)
Deprecated.
-
AbstractApiClient
protected AbstractApiClient(String baseUrl, Duration connectionRequestTimeout, Duration connectTimeout, Duration socketTimeout, Integer maxConnections, Integer maxConnectionsPerRoute, Integer maxConnectionsNoTimeout, Integer maxConnectionsPerRouteNoTimeout, Duration connectionInPoolTTL, Duration validateAfterInactivity, Duration countWindow, Integer bucketCount, Duration warnThreshold, List<Locale> acceptableLanguages, javax.ws.rs.core.MediaType accept, javax.ws.rs.core.MediaType contentType, Boolean trustAll, Jackson2Mapper objectMapper, String mbeanName, ClassLoader classLoader, String userAgent, Boolean registerMBean, boolean eager)
-
-
Method Detail
-
postConstruct
@PostConstruct public void postConstruct()
-
getVersion
protected String getVersion(String prop, ClassLoader loader)
-
invalidate
public void invalidate()
- Specified by:
invalidate
in interfaceAbstractApiClientMXBean
-
getInitializationInstant
public String getInitializationInstant()
- Specified by:
getInitializationInstant
in interfaceAbstractApiClientMXBean
-
getConnectionRequestTimeout
public String getConnectionRequestTimeout()
- Specified by:
getConnectionRequestTimeout
in interfaceAbstractApiClientMXBean
-
setConnectionRequestTimeout
public void setConnectionRequestTimeout(String connectionRequestTimeout)
- Specified by:
setConnectionRequestTimeout
in interfaceAbstractApiClientMXBean
-
getConnectTimeout
public String getConnectTimeout()
- Specified by:
getConnectTimeout
in interfaceAbstractApiClientMXBean
-
setConnectTimeout
public void setConnectTimeout(String connectTimeout)
- Specified by:
setConnectTimeout
in interfaceAbstractApiClientMXBean
-
getSocketTimeout
public String getSocketTimeout()
- Specified by:
getSocketTimeout
in interfaceAbstractApiClientMXBean
-
setSocketTimeout
public void setSocketTimeout(String socketTimeout)
- Specified by:
setSocketTimeout
in interfaceAbstractApiClientMXBean
-
test
public final String test(String arg)
- Specified by:
test
in interfaceAbstractApiClientMXBean
-
appendTestResult
protected void appendTestResult(StringBuilder builder, String arg)
-
getAccept
public javax.ws.rs.core.MediaType getAccept()
-
setAccept
public void setAccept(javax.ws.rs.core.MediaType mediaType)
-
getContentType
public javax.ws.rs.core.MediaType getContentType()
-
setContentType
public void setContentType(javax.ws.rs.core.MediaType mediaType)
-
setTrustAll
public void setTrustAll(boolean b)
-
setObjectMapper
public void setObjectMapper(Jackson2Mapper objectMapper)
-
getObjectName
protected ObjectName getObjectName()
-
produceIfNull
protected <T> T produceIfNull(Supplier<T> supplier, Supplier<T> producer)
Checks whether supplier has null, if so produces it while locking, so it happens only once
-
getClientHttpEngine
public org.jboss.resteasy.client.jaxrs.ClientHttpEngine getClientHttpEngine()
-
getClientHttpEngineNoTimeout
public org.jboss.resteasy.client.jaxrs.ClientHttpEngine getClientHttpEngineNoTimeout()
-
setMaxConnections
public void setMaxConnections(Integer maxConnections)
- Specified by:
setMaxConnections
in interfaceAbstractApiClientMXBean
-
setMaxConnectionsPerRoute
public void setMaxConnectionsPerRoute(Integer maxConnectionsPerRoute)
- Specified by:
setMaxConnectionsPerRoute
in interfaceAbstractApiClientMXBean
-
setMaxConnectionsNoTimeout
public void setMaxConnectionsNoTimeout(Integer maxConnectionsNoTimeout)
- Specified by:
setMaxConnectionsNoTimeout
in interfaceAbstractApiClientMXBean
-
setMaxConnectionsPerRouteNoTimeout
public void setMaxConnectionsPerRouteNoTimeout(Integer maxConnectionsPerRouteNoTimeout)
- Specified by:
setMaxConnectionsPerRouteNoTimeout
in interfaceAbstractApiClientMXBean
-
getConnectionInPoolTTL
public String getConnectionInPoolTTL()
- Specified by:
getConnectionInPoolTTL
in interfaceAbstractApiClientMXBean
-
setConnectionInPoolTTL
public void setConnectionInPoolTTL(String connectionInPoolTTLAsAstring)
- Specified by:
setConnectionInPoolTTL
in interfaceAbstractApiClientMXBean
-
getValidateAfterInactivity
public String getValidateAfterInactivity()
- Specified by:
getValidateAfterInactivity
in interfaceAbstractApiClientMXBean
-
setValidateAfterInactivity
public void setValidateAfterInactivity(String validateAfterInactivityAsString)
- Specified by:
setValidateAfterInactivity
in interfaceAbstractApiClientMXBean
-
getCountWindowString
public String getCountWindowString()
- Specified by:
getCountWindowString
in interfaceAbstractApiClientMXBean
-
setCountWindowString
public void setCountWindowString(String countWindow)
- Specified by:
setCountWindowString
in interfaceAbstractApiClientMXBean
-
setCountWindow
public void setCountWindow(Duration countWindow)
-
getBucketCount
public Integer getBucketCount()
- Specified by:
getBucketCount
in interfaceAbstractApiClientMXBean
-
setBucketCount
public void setBucketCount(Integer bucketCount)
- Specified by:
setBucketCount
in interfaceAbstractApiClientMXBean
-
getWarnThresholdString
public String getWarnThresholdString()
- Specified by:
getWarnThresholdString
in interfaceAbstractApiClientMXBean
-
setWarnThresholdString
public void setWarnThresholdString(String warnThreshold)
- Specified by:
setWarnThresholdString
in interfaceAbstractApiClientMXBean
-
setWarnThreshold
public void setWarnThreshold(Duration warnThreshold)
-
build
protected <T,S,E> T build(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<S> restEasyService, Class<E> errorClass, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
-
proxyErrorsAndCount
protected <T> T proxyErrorsAndCount(Class<T> service, T proxy)
-
proxyErrorsAndCount
protected <T,E> T proxyErrorsAndCount(Class<T> service, T proxy, Class<E> errorClass)
-
proxyErrors
protected <T> T proxyErrors(Class<T> service, T proxy)
-
proxyErrors
protected <T,E> T proxyErrors(Class<T> service, T proxy, Class<E> errorClass)
- Type Parameters:
T
- The type of the service interface- Parameters:
service
- The service interfaceproxy
- The current proxy object for the service interfaceerrorClass
- The class representing an error- Returns:
- A new proxy, with the functionality of
ErrorAspect
added.
-
proxyCounter
protected <T> T proxyCounter(Class<T> service, T proxy)
- Type Parameters:
T
- The type of the service interface- Parameters:
service
- The service interfaceproxy
- The current proxy object for the service interface- Returns:
- A new proxy, with the functionality of
CountAspect
added.
-
build
protected <T> T build(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
-
build
protected <T> T build(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service)
-
build
protected <T,S> T build(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<S> restEasyInterface, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
-
buildWithErrorClass
protected <T,S> T buildWithErrorClass(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<S> restEasyInterface, Class<?> errorClass, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
-
buildWithErrorClass
protected <T,S> T buildWithErrorClass(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<S> restEasyInterface, Class<?> errorClass)
-
buildWithErrorClass
protected <T> T buildWithErrorClass(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<?> errorClass, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
-
buildWithErrorClass
protected <T> T buildWithErrorClass(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Class<T> service, Class<?> errorClass)
-
build
protected <T> T build(Class<T> service, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
-
build
protected <T> T build(Class<T> service)
-
resteasyClientBuilder
protected org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder resteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
-
defaultResteasyClientBuilder
protected org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder defaultResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine)
-
buildResteasy
protected void buildResteasy(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder builder)
For further building the client you can override this method. If you need more control you can also use the several 'buildFurther' arguments.
-
getTarget
protected final org.jboss.resteasy.client.jaxrs.ResteasyWebTarget getTarget(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine, Consumer<org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder> buildFurther)
-
getTarget
protected final org.jboss.resteasy.client.jaxrs.ResteasyWebTarget getTarget(org.jboss.resteasy.client.jaxrs.ClientHttpEngine engine)
-
getInfo
protected String getInfo()
-
getBaseUrl
public final String getBaseUrl()
- Specified by:
getBaseUrl
in interfaceAbstractApiClientMXBean
-
setBaseUrl
public void setBaseUrl(String url)
- Specified by:
setBaseUrl
in interfaceAbstractApiClientMXBean
-
getCounts
public String getCounts()
- Specified by:
getCounts
in interfaceAbstractApiClientMXBean
-
getCount
public long getCount(String method)
- Specified by:
getCount
in interfaceAbstractApiClientMXBean
-
getTotalCount
public long getTotalCount()
- Specified by:
getTotalCount
in interfaceAbstractApiClientMXBean
-
getRate
public double getRate()
- Specified by:
getRate
in interfaceAbstractApiClientMXBean
-
getBrowserCache
public org.jboss.resteasy.client.jaxrs.cache.BrowserCache getBrowserCache()
-
clearBrowserCache
public void clearBrowserCache()
-
setBrowserCache
public void setBrowserCache(javax.cache.Cache<?,?> browserCache)
Default the client is backed by aLightweightBrowserCache
, you may replace it byJavaxBrowserCache
, backed with a more genericCache
, so that the client can hitch on your preferred caching framework.
-
setBrowserCache
public void setBrowserCache(org.jboss.resteasy.client.jaxrs.cache.BrowserCache browserCache)
-
setBrowserCache
public void setBrowserCache(boolean browserCache)
-
shutdown
@PreDestroy public void shutdown()
-
finalize
protected void finalize() throws Throwable
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
closeClients
protected void closeClients()
-
getMaxConnections
public Integer getMaxConnections()
- Specified by:
getMaxConnections
in interfaceAbstractApiClientMXBean
-
getMaxConnectionsPerRoute
public Integer getMaxConnectionsPerRoute()
- Specified by:
getMaxConnectionsPerRoute
in interfaceAbstractApiClientMXBean
-
getMaxConnectionsNoTimeout
public Integer getMaxConnectionsNoTimeout()
- Specified by:
getMaxConnectionsNoTimeout
in interfaceAbstractApiClientMXBean
-
getMaxConnectionsPerRouteNoTimeout
public Integer getMaxConnectionsPerRouteNoTimeout()
- Specified by:
getMaxConnectionsPerRouteNoTimeout
in interfaceAbstractApiClientMXBean
-
getWarnThreshold
public Duration getWarnThreshold()
-
getObjectMapper
public Jackson2Mapper getObjectMapper()
-
-