Class Service

  • Direct Known Subclasses:
    AbstractQueryService, ListService, ModelService, WidgetService

    public class Service
    extends java.lang.Object
    This class provides the base level common functionality required to access any InterMine service. It is also designed to act as a base class that can be customised for specific types of InterMine services. It encapsulates all protocol-level interactions with the server.
    • Field Detail

      • VERSION

        public static final Version VERSION
        The version of this client library.
      • resourceUrl

        protected java.net.URL resourceUrl
    • Constructor Detail

      • Service

        public Service​(java.lang.String rootUrl,
                       java.lang.String serviceRelativeUrl,
                       java.lang.String applicationName)
        Constructor. ServiceFactory should be used always to create services and not this constructor.
        Parameters:
        rootUrl - the base URL of all services, it is the common prefix for all services, Example: http://www.flymine.org/service
        serviceRelativeUrl - the part of the URL specific to this service Example: query/results
        applicationName - application name, information for server which application uses this service
    • Method Detail

      • getFactory

        public ServiceFactory getFactory()
        Get the ServiceFactory this service was constructed with.
        Returns:
        The parent service-factory.
      • setFactory

        public void setFactory​(ServiceFactory factory)
        Set the ServiceFactory this service can use to access other services.
        Parameters:
        factory - The parent service-factory.
      • setAuthentication

        @Deprecated
        public void setAuthentication​(java.lang.String userName,
                                      java.lang.String password)
        Deprecated.
        Use token based authentication instead (setAuthentication(String) as this method will cause your user name and password to be transmitted insecurely across HTTP connections.
        Sets the user-name and password for all requests.
        Parameters:
        userName - a user-name
        password - a password
      • setAuthentication

        public void setAuthentication​(java.lang.String token)
        Set the token to be used for authentication. This is the preferred mechanism for authenticating requests to the web-service.
        Parameters:
        token - The token to use for authentication.
      • executeRequest

        public HttpConnection executeRequest​(Request request)
        Open connection and returns connection.
        Parameters:
        request - request
        Returns:
        created connection
      • assureOutputFormatSpecified

        protected void assureOutputFormatSpecified​(Request request)
        Add a format parameter to match the content-type if there is one.
        Parameters:
        request - The request to fool around with.
      • setConnectionTimeout

        public void setConnectionTimeout​(int timeout)
        Sets connection timeout.
        Parameters:
        timeout - timeout
      • getUrl

        public java.lang.String getUrl()
        Returns service URL Example: http://www.flymine.org/flymine/service/query/results
        Returns:
        URL
      • getRootUrl

        public java.lang.String getRootUrl()
        Returns service's root URL. Example: http://www.flymine.org/flymine/service
        Returns:
        URL
      • createGetRequest

        public Request createGetRequest​(java.lang.String url,
                                        ContentType contentType)
        Creates GET request.
        Parameters:
        url - URL of request
        contentType - required content type of response
        Returns:
        created request
      • createPostRequest

        public Request createPostRequest​(java.lang.String requestUrl,
                                         ContentType contentType)
        Creates POST request.
        Parameters:
        requestUrl - URL of request
        contentType - required content type of response
        Returns:
        created request
      • getVersion

        public Version getVersion()
        Returns:
        The client version
      • getApplicationName

        public java.lang.String getApplicationName()
        Returns:
        application name
      • getStringResponse

        protected java.lang.String getStringResponse​(Request request,
                                                     java.lang.Integer retryCount)
        Performs the request and returns the result as a string.
        Parameters:
        request - The Request object
        retryCount - The number of times to retry. If null, the default value of HttpConnection will be used.
        Returns:
        a string containing the body of the response
      • getIntResponse

        protected int getIntResponse​(Request request)
        Performs the request and returns the result as an integer. Suitable when the service returns a single integer number.
        Parameters:
        request - The Request object
        Returns:
        an integer.
      • getAPIVersion

        public int getAPIVersion()
        Returns:
        the server's API version. Will make at most one call, caching the response for future calls.
      • clearCache

        public void clearCache()
        Clear the cache on this object. You might find this useful if you have a persistent application with long-lived instances of this class (more than 24 hours or so). You may wish in such circumstances to periodically clear the cache to avoid stale data.