Package de.kosmos_lab.web.client
Class AuthedHTTPClient
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.client.HttpClient
-
- de.kosmos_lab.web.client.AuthedHTTPClient
-
- All Implemented Interfaces:
org.eclipse.jetty.util.component.Container,org.eclipse.jetty.util.component.Destroyable,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.Dumpable.DumpableContainer,org.eclipse.jetty.util.component.LifeCycle
- Direct Known Subclasses:
MyTestClient
public abstract class AuthedHTTPClient extends org.eclipse.jetty.client.HttpClient
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener
-
-
Constructor Summary
Constructors Constructor Description AuthedHTTPClient(String baseurl)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidauthorizeRequest(org.eclipse.jetty.client.api.Request request)implement this method to add your login information to the requestabstract voidclearToken()org.eclipse.jetty.client.api.RequestcreateRequest(String url, org.eclipse.jetty.http.HttpMethod method)create a request to the given url with the given method, if the url is not a complete url the baseurl will be prependedStringgetBase()get the base urlintgetMaxRetries()get the max amount of retriesprotected org.eclipse.jetty.client.api.ContentResponsegetResponse(String url, org.eclipse.jetty.http.HttpMethod method, int maxRetries, Integer expectedStatus)protected org.eclipse.jetty.client.api.ContentResponsegetResponse(String url, org.eclipse.jetty.http.HttpMethod method, Integer expectedStatus)create a new request with empty body and default retriesprotected org.eclipse.jetty.client.api.ContentResponsegetResponse(String url, org.eclipse.jetty.http.HttpMethod method, Object body, int maxRetries, Integer expectedStatus)get the response for a given result, if 401 is returned the jwt will be renewed, and it will be tried againprotected org.eclipse.jetty.client.api.ContentResponsegetResponse(String url, org.eclipse.jetty.http.HttpMethod method, Object body, Integer expectedStatus)abstract StringgetToken()abstract booleanrefreshToken()implement this method to get a new token from the systemvoidsetMaxRetries(int maxRetries)set the max amount of retries (defaults to 3)-
Methods inherited from class org.eclipse.jetty.client.HttpClient
copyRequest, createOrigin, doStart, doStop, dump, findProtocolHandler, FORM, FORM, GET, GET, getAcceptEncodingField, getAddressResolutionTimeout, getAuthenticationStore, getBindAddress, getByteBufferPool, getConnectTimeout, getContentDecoderFactories, getCookieStore, getDefaultRequestContentType, getDestinations, getExecutor, getHttpCompliance, getIdleTimeout, getMaxConnectionsPerDestination, getMaxRedirects, getMaxRequestsQueuedPerDestination, getName, getProtocolHandlers, getProxyConfiguration, getRequestBufferSize, getRequestListeners, getResponseBufferSize, getScheduler, getSocketAddressResolver, getSslContextFactory, getTransport, getUserAgentField, isConnectBlocking, isDefaultPort, isFollowRedirects, isRemoveIdleDestinations, isSchemeSecure, isStrictEventOrdering, isTCPNoDelay, isUseInputDirectByteBuffers, isUseOutputDirectByteBuffers, newConnection, newHttpRequest, newRequest, newRequest, newRequest, newSslClientConnectionFactory, normalizeHost, normalizePort, POST, POST, removeDestination, resolveDestination, resolveDestination, send, setAddressResolutionTimeout, setAuthenticationStore, setBindAddress, setByteBufferPool, setConnectBlocking, setConnectTimeout, setCookieStore, setDefaultRequestContentType, setExecutor, setFollowRedirects, setHttpCompliance, setIdleTimeout, setMaxConnectionsPerDestination, setMaxRedirects, setMaxRequestsQueuedPerDestination, setName, setRemoveIdleDestinations, setRequestBufferSize, setResponseBufferSize, setScheduler, setSocketAddressResolver, setStrictEventOrdering, setTCPNoDelay, setUseInputDirectByteBuffers, setUseOutputDirectByteBuffers, setUserAgentField
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
authorizeRequest
public abstract void authorizeRequest(@Nonnull org.eclipse.jetty.client.api.Request request) throws LoginFailedExceptionimplement this method to add your login information to the request- Parameters:
request-- Throws:
LoginFailedException
-
createRequest
@Nonnull public org.eclipse.jetty.client.api.Request createRequest(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method)create a request to the given url with the given method, if the url is not a complete url the baseurl will be prepended- Parameters:
url- the url to usemethod- the method to use- Returns:
- a Request object
-
getBase
@Nonnull public String getBase()
get the base url- Returns:
- the base url
-
getMaxRetries
public int getMaxRetries()
get the max amount of retries- Returns:
- the amount of retries
-
getResponse
protected org.eclipse.jetty.client.api.ContentResponse getResponse(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method, int maxRetries, @CheckForNull Integer expectedStatus) throws RequestFailedException- Throws:
RequestFailedException
-
getResponse
protected org.eclipse.jetty.client.api.ContentResponse getResponse(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method, @CheckForNull Object body, @CheckForNull Integer expectedStatus) throws RequestFailedException- Throws:
RequestFailedException
-
getToken
public abstract String getToken()
-
setMaxRetries
public void setMaxRetries(int maxRetries)
set the max amount of retries (defaults to 3)- Parameters:
maxRetries- the new amount of retries
-
getResponse
@Nonnull protected org.eclipse.jetty.client.api.ContentResponse getResponse(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method, @CheckForNull Object body, int maxRetries, @CheckForNull Integer expectedStatus) throws RequestFailedExceptionget the response for a given result, if 401 is returned the jwt will be renewed, and it will be tried again- Parameters:
url-method-body- the body we want to send (can be null)maxRetries- the amount of tests to try againexpectedStatus-- Returns:
- Throws:
RequestFailedException
-
clearToken
public abstract void clearToken()
-
getResponse
protected org.eclipse.jetty.client.api.ContentResponse getResponse(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method, @Nullable Integer expectedStatus) throws RequestFailedExceptioncreate a new request with empty body and default retries- Parameters:
url-method-expectedStatus-- Returns:
- Throws:
RequestFailedException
-
refreshToken
public abstract boolean refreshToken() throws LoginFailedExceptionimplement this method to get a new token from the system- Throws:
LoginFailedException
-
-