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 boolean addAuthToRequest​(org.eclipse.jetty.client.api.Request request)  
      org.eclipse.jetty.client.api.Request createAuthedDeleteRequest​(String url, org.json.JSONObject body)  
      org.eclipse.jetty.client.api.Request createAuthedPostRequest​(String url, org.json.JSONObject body)  
      org.eclipse.jetty.client.api.Request createAuthedRequest​(String url, org.eclipse.jetty.http.HttpMethod method)
      create a request with Authorization header
      org.eclipse.jetty.client.api.Request createAuthedRequest​(String url, org.eclipse.jetty.http.HttpMethod method, String body)  
      org.eclipse.jetty.client.api.Request createAuthedRequest​(String url, org.eclipse.jetty.http.HttpMethod method, org.json.JSONArray body)  
      org.eclipse.jetty.client.api.Request createAuthedRequest​(String url, org.eclipse.jetty.http.HttpMethod method, org.json.JSONObject body)  
      org.json.JSONArray fetchJSONArray​(String url, org.eclipse.jetty.http.HttpMethod method)
      get the result of calling an URL with the given method
      org.json.JSONObject fetchJSONObject​(String url, org.eclipse.jetty.http.HttpMethod method)  
      org.json.JSONArray getJSONArray​(String url)
      get the result of calling an URL with GET
      org.json.JSONObject getJSONObject​(String url)  
      String getPassword()  
      org.eclipse.jetty.client.api.ContentResponse getResponse​(String url, org.eclipse.jetty.http.HttpMethod method)  
      org.eclipse.jetty.client.api.ContentResponse getResponse​(String url, org.eclipse.jetty.http.HttpMethod method, String body)  
      org.eclipse.jetty.client.api.ContentResponse getResponse​(String url, org.eclipse.jetty.http.HttpMethod method, org.json.JSONArray body)  
      org.eclipse.jetty.client.api.ContentResponse getResponse​(String url, org.eclipse.jetty.http.HttpMethod method, org.json.JSONObject body)  
      org.eclipse.jetty.client.api.ContentResponse getResponse​(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
      String getUserName()  
      abstract String login()  
      org.json.JSONObject postJSONObject​(String url, org.json.JSONObject body)
      post the given body to a specific url
      org.eclipse.jetty.client.api.ContentResponse postJSONObject2​(String url, org.json.JSONObject body)
      post the given body to a specific url
      boolean refreshToken()
      get a new JWT token (try to login)
      void setPassword​(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, 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​(@Nonnull
                                String baseurl,
                                @Nonnull
                                String user,
                                @Nonnull
                                String pass)
                         throws Exception
        create a new Client
        Parameters:
        baseurl - the base url
        user - the password
        pass - the password
        Throws:
        Exception - some catastrophic failure
    • 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 to
        method - 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 call
        method - 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 to
        body - 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 to
        body - 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)