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, String token)AuthedHTTPClient(String baseurl, String user, String pass)create a new Client
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract booleanaddAuthToRequest(org.eclipse.jetty.client.api.Request request)org.eclipse.jetty.client.api.RequestcreateAuthedDeleteRequest(String url, org.json.JSONObject body)org.eclipse.jetty.client.api.RequestcreateAuthedPostRequest(String url, org.json.JSONObject body)org.eclipse.jetty.client.api.RequestcreateAuthedRequest(String url, org.eclipse.jetty.http.HttpMethod method)create a request with Authorization headerorg.eclipse.jetty.client.api.RequestcreateAuthedRequest(String url, org.eclipse.jetty.http.HttpMethod method, String body)org.eclipse.jetty.client.api.RequestcreateAuthedRequest(String url, org.eclipse.jetty.http.HttpMethod method, org.json.JSONArray body)org.eclipse.jetty.client.api.RequestcreateAuthedRequest(String url, org.eclipse.jetty.http.HttpMethod method, org.json.JSONObject body)org.json.JSONArrayfetchJSONArray(String url, org.eclipse.jetty.http.HttpMethod method)get the result of calling an URL with the given methodorg.json.JSONObjectfetchJSONObject(String url, org.eclipse.jetty.http.HttpMethod method)org.json.JSONArraygetJSONArray(String url)get the result of calling an URL with GETorg.json.JSONObjectgetJSONObject(String url)StringgetPassword()org.eclipse.jetty.client.api.ContentResponsegetResponse(String url, org.eclipse.jetty.http.HttpMethod method)org.eclipse.jetty.client.api.ContentResponsegetResponse(String url, org.eclipse.jetty.http.HttpMethod method, String body)org.eclipse.jetty.client.api.ContentResponsegetResponse(String url, org.eclipse.jetty.http.HttpMethod method, org.json.JSONArray body)org.eclipse.jetty.client.api.ContentResponsegetResponse(String url, org.eclipse.jetty.http.HttpMethod method, org.json.JSONObject body)org.eclipse.jetty.client.api.ContentResponsegetResponse(org.eclipse.jetty.client.api.Request request)get the response for a given result, if 401 is returned the jwt will be renewed and it will be tried againStringgetUserName()abstract Stringlogin()org.json.JSONObjectpostJSONObject(String url, org.json.JSONObject body)post the given body to a specific urlorg.eclipse.jetty.client.api.ContentResponsepostJSONObject2(String url, org.json.JSONObject body)post the given body to a specific urlbooleanrefreshToken()get a new JWT token (try to login)voidsetPassword(String pass)-
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, getDestinationIdleTimeout, 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, setDestinationIdleTimeout, 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
-
createAuthedDeleteRequest
@CheckForNull public org.eclipse.jetty.client.api.Request createAuthedDeleteRequest(@Nonnull String url, @CheckForNull org.json.JSONObject body)
-
createAuthedPostRequest
@CheckForNull public org.eclipse.jetty.client.api.Request createAuthedPostRequest(@Nonnull String url, @CheckForNull org.json.JSONObject body)
-
createAuthedRequest
@CheckForNull public org.eclipse.jetty.client.api.Request createAuthedRequest(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method)create a request with Authorization header- Parameters:
url- the url to connect tomethod- the method to use- Returns:
-
createAuthedRequest
@CheckForNull public org.eclipse.jetty.client.api.Request createAuthedRequest(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method, @CheckForNull org.json.JSONObject body)
-
createAuthedRequest
@CheckForNull public org.eclipse.jetty.client.api.Request createAuthedRequest(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method, @CheckForNull org.json.JSONArray body)
-
createAuthedRequest
@CheckForNull public org.eclipse.jetty.client.api.Request createAuthedRequest(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method, @CheckForNull String body)
-
fetchJSONArray
@CheckForNull public org.json.JSONArray fetchJSONArray(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method)get the result of calling an URL with the given method- Parameters:
url- the URL to callmethod- the method to use [GET,POST,DELETE,PUT...]- Returns:
-
fetchJSONObject
@CheckForNull public org.json.JSONObject fetchJSONObject(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method)
-
getJSONArray
@CheckForNull public org.json.JSONArray getJSONArray(@Nonnull String url)get the result of calling an URL with GET- Parameters:
url- the URL to call- Returns:
-
getJSONObject
@CheckForNull public org.json.JSONObject getJSONObject(String url)
-
getPassword
@CheckForNull public String getPassword()
-
getResponse
@CheckForNull public org.eclipse.jetty.client.api.ContentResponse getResponse(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method, @CheckForNull String body)
-
getResponse
@CheckForNull public org.eclipse.jetty.client.api.ContentResponse getResponse(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method, @CheckForNull org.json.JSONObject body)
-
getResponse
@CheckForNull public org.eclipse.jetty.client.api.ContentResponse getResponse(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method, @CheckForNull org.json.JSONArray body)
-
getResponse
@CheckForNull public org.eclipse.jetty.client.api.ContentResponse getResponse(@Nonnull String url, @Nonnull org.eclipse.jetty.http.HttpMethod method)
-
addAuthToRequest
public abstract boolean addAuthToRequest(@CheckForNull org.eclipse.jetty.client.api.Request request)
-
getResponse
@CheckForNull public org.eclipse.jetty.client.api.ContentResponse getResponse(@CheckForNull org.eclipse.jetty.client.api.Request request)get the response for a given result, if 401 is returned the jwt will be renewed and it will be tried again- Parameters:
request- the request to parse- Returns:
-
getUserName
@CheckForNull public String getUserName()
-
login
@CheckForNull public abstract String login()
-
postJSONObject
@CheckForNull public org.json.JSONObject postJSONObject(@Nonnull String url, @CheckForNull org.json.JSONObject body)post the given body to a specific url- Parameters:
url- the url to post it tobody- the body to post- Returns:
- the JSONObject returned from
-
postJSONObject2
@CheckForNull public org.eclipse.jetty.client.api.ContentResponse postJSONObject2(@Nonnull String url, @CheckForNull org.json.JSONObject body)post the given body to a specific url- Parameters:
url- the url to post it tobody- the body to post- Returns:
- the JSONObject returned from
-
refreshToken
public boolean refreshToken()
get a new JWT token (try to login)- Returns:
- true if login was successful
-
setPassword
public void setPassword(@Nonnull String pass)
-
-