Class 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
      • Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable

        org.eclipse.jetty.util.component.Dumpable.DumpableContainer
      • Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

        org.eclipse.jetty.util.component.LifeCycle.Listener
    • Field Summary

      • Fields inherited from class org.eclipse.jetty.client.HttpClient

        USER_AGENT
      • Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

        FAILED, STARTED, STARTING, STOPPED, STOPPING
      • Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

        KEY
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract void authorizeRequest​(org.eclipse.jetty.client.api.Request request)
      implement this method to add your login information to the request
      abstract void clearToken()  
      org.eclipse.jetty.client.api.Request createRequest​(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 prepended
      String getBase()
      get the base url
      int getMaxRetries()
      get the max amount of retries
      protected org.eclipse.jetty.client.api.ContentResponse getResponse​(String url, org.eclipse.jetty.http.HttpMethod method, int maxRetries, Integer expectedStatus)  
      protected org.eclipse.jetty.client.api.ContentResponse getResponse​(String url, org.eclipse.jetty.http.HttpMethod method, Integer expectedStatus)
      create a new request with empty body and default retries
      protected org.eclipse.jetty.client.api.ContentResponse getResponse​(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 again
      protected org.eclipse.jetty.client.api.ContentResponse getResponse​(String url, org.eclipse.jetty.http.HttpMethod method, Object body, Integer expectedStatus)  
      abstract String getToken()  
      abstract boolean refreshToken()
      implement this method to get a new token from the system
      void setMaxRetries​(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 interface org.eclipse.jetty.util.component.Container

        getCachedBeans, getEventListeners
      • Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

        dumpSelf
      • Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer

        isDumpable
    • Constructor Detail

      • AuthedHTTPClient

        public AuthedHTTPClient​(String baseurl)
                         throws Exception
        Parameters:
        baseurl - the baseurl to connect to
        Throws:
        Exception - the exception is thrown from jetty http client when starting the client
    • Method Detail

      • authorizeRequest

        public abstract void authorizeRequest​(@Nonnull
                                              org.eclipse.jetty.client.api.Request request)
                                       throws LoginFailedException
        implement 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 use
        method - 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
      • 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 RequestFailedException
        get 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 again
        expectedStatus -
        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 RequestFailedException
        create a new request with empty body and default retries
        Parameters:
        url -
        method -
        expectedStatus -
        Returns:
        Throws:
        RequestFailedException