Package org.intermine.client.core
Class Service
- java.lang.Object
-
- org.intermine.client.core.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 Summary
Fields Modifier and Type Field Description protected java.net.URL
resourceUrl
static Version
VERSION
The version of this client library.
-
Constructor Summary
Constructors Constructor Description Service(java.lang.String rootUrl, java.lang.String serviceRelativeUrl, java.lang.String applicationName)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
assureOutputFormatSpecified(Request request)
Add a format parameter to match the content-type if there is one.void
clearCache()
Clear the cache on this object.Request
createGetRequest(java.lang.String url, ContentType contentType)
Creates GET request.Request
createPostRequest(java.lang.String requestUrl, ContentType contentType)
Creates POST request.HttpConnection
executeRequest(Request request)
Open connection and returns connection.int
getAPIVersion()
java.lang.String
getApplicationName()
ServiceFactory
getFactory()
Get the ServiceFactory this service was constructed with.protected int
getIntResponse(Request request)
Performs the request and returns the result as an integer.java.lang.String
getRootUrl()
Returns service's root URL.protected java.lang.String
getStringResponse(Request request, java.lang.Integer retryCount)
Performs the request and returns the result as a string.java.lang.String
getUrl()
Returns service URL Example: http://www.flymine.org/flymine/service/query/resultsVersion
getVersion()
void
setAuthentication(java.lang.String token)
Set the token to be used for authentication.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.void
setConnectionTimeout(int timeout)
Sets connection timeout.void
setFactory(ServiceFactory factory)
Set the ServiceFactory this service can use to access other services.
-
-
-
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/serviceserviceRelativeUrl
- the part of the URL specific to this service Example: query/resultsapplicationName
- 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-namepassword
- 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 requestcontentType
- 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 requestcontentType
- 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 objectretryCount
- 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.
-
-