Package org.purl.sword.client
Class Client
java.lang.Object
org.purl.sword.client.Client
- All Implemented Interfaces:
SWORDClient
This is an example Client implementation to demonstrate how to connect to a
SWORD server. The client supports BASIC HTTP Authentication. This can be
initialised by setting a username and password.
- Author:
- Neil Taylor
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default connection timeout. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear any user credentials that have been set for this client.void
Clear the proxy setting.getServiceDocument
(String url) Retrieve the service document.getServiceDocument
(String url, String onBehalfOf) Retrieve the service document.Return the status information that was returned from the most recent request sent to the server.postFile
(PostMessage message) Post a file to the server.void
setCredentials
(String username, String password) Set the user credentials that will be used when making the access to the server.void
Set a proxy that should be used by the client when trying to access the server.void
Set a proxy that should be used by the client when trying to access the server.void
Initialise the server that will be used to send the network access.void
setSocketTimeout
(int milliseconds) Set the connection timeout for the socket.void
setUserAgent
(String userAgent)
-
Field Details
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUTThe default connection timeout. This can be modified by using the setSocketTimeout method.- See Also:
-
-
Constructor Details
-
Client
public Client()Create a new Client. The client will not use authentication by default.
-
-
Method Details
-
setServer
Initialise the server that will be used to send the network access.- Specified by:
setServer
in interfaceSWORDClient
- Parameters:
server
- server address/hostnameport
- server port
-
setCredentials
Set the user credentials that will be used when making the access to the server.- Specified by:
setCredentials
in interfaceSWORDClient
- Parameters:
username
- The username.password
- The password.
-
setProxy
Set a proxy that should be used by the client when trying to access the server. If this is not set, the client will attempt to make a direct direct connection to the server. The port is set to 80.- Parameters:
host
- The hostname.
-
setProxy
Set a proxy that should be used by the client when trying to access the server. If this is not set, the client will attempt to make a direct direct connection to the server.- Specified by:
setProxy
in interfaceSWORDClient
- Parameters:
host
- The name of the host.port
- The port.
-
clearProxy
public void clearProxy()Clear the proxy setting. -
clearCredentials
public void clearCredentials()Clear any user credentials that have been set for this client.- Specified by:
clearCredentials
in interfaceSWORDClient
-
setUserAgent
-
setSocketTimeout
public void setSocketTimeout(int milliseconds) Set the connection timeout for the socket.- Parameters:
milliseconds
- The time, expressed as a number of milliseconds.
-
getServiceDocument
Retrieve the service document. The service document is located at the specified URL. This calls getServiceDocument(url,onBehalfOf).- Specified by:
getServiceDocument
in interfaceSWORDClient
- Parameters:
url
- The location of the service document.- Returns:
- The ServiceDocument, or
null
if there was a problem accessing the document. e.g. invalid access. - Throws:
SWORDClientException
- If there is an error accessing the resource.
-
getServiceDocument
public ServiceDocument getServiceDocument(String url, String onBehalfOf) throws SWORDClientException Retrieve the service document. The service document is located at the specified URL. This calls getServiceDocument(url,onBehalfOf).- Specified by:
getServiceDocument
in interfaceSWORDClient
- Parameters:
url
- The location of the service document.onBehalfOf
- The username for the onBehalfOf access.- Returns:
- The ServiceDocument, or
null
if there was a problem accessing the document. e.g. invalid access. - Throws:
SWORDClientException
- If there is an error accessing the resource.
-
getLastUnmarshallInfo
- Returns:
- SWORD validation info
-
postFile
Post a file to the server. The different elements of the post are encoded in the specified message.- Specified by:
postFile
in interfaceSWORDClient
- Parameters:
message
- The message that contains the post information.- Returns:
- A DespoitResponse if the response is successful. If there was an error,
null
should be returned. - Throws:
SWORDClientException
- if there is an error during the post operation.
-
getStatus
Return the status information that was returned from the most recent request sent to the server.- Specified by:
getStatus
in interfaceSWORDClient
- Returns:
- The status code returned from the most recent access.
-