org.purl.sword.client
Class Client

java.lang.Object
  extended by org.purl.sword.client.Client
All Implemented Interfaces:
SWORDClient

public class Client
extends Object
implements 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
static int DEFAULT_TIMEOUT
          The default connection timeout.
 
Constructor Summary
Client()
          Create a new Client.
 
Method Summary
 void clearCredentials()
          Clear any user credentials that have been set for this client.
 void clearProxy()
          Clear the proxy setting.
 SwordValidationInfo getLastUnmarshallInfo()
           
 ServiceDocument getServiceDocument(String url)
          Retrieve the service document.
 ServiceDocument getServiceDocument(String url, String onBehalfOf)
          Retrieve the service document.
 Status getStatus()
          Return the status information that was returned from the most recent request sent to the server.
 DepositResponse 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 setProxy(String host)
          Set a proxy that should be used by the client when trying to access the server.
 void setProxy(String host, int port)
          Set a proxy that should be used by the client when trying to access the server.
 void setServer(String server, int port)
          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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TIMEOUT

public static final int DEFAULT_TIMEOUT
The default connection timeout. This can be modified by using the setSocketTimeout method.

See Also:
Constant Field Values
Constructor Detail

Client

public Client()
Create a new Client. The client will not use authentication by default.

Method Detail

setServer

public void setServer(String server,
                      int port)
Initialise the server that will be used to send the network access.

Specified by:
setServer in interface SWORDClient
Parameters:
server -
port -

setCredentials

public void setCredentials(String username,
                           String password)
Set the user credentials that will be used when making the access to the server.

Specified by:
setCredentials in interface SWORDClient
Parameters:
username - The username.
password - The password.

setProxy

public void setProxy(String host)
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

public void setProxy(String host,
                     int port)
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 interface SWORDClient
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 interface SWORDClient

setUserAgent

public void setUserAgent(String userAgent)

setSocketTimeout

public void setSocketTimeout(int milliseconds)
Set the connection timeout for the socket.

Parameters:
milliseconds - The time, expressed as a number of milliseconds.

getServiceDocument

public ServiceDocument getServiceDocument(String url)
                                   throws SWORDClientException
Retrieve the service document. The service document is located at the specified URL. This calls getServiceDocument(url,onBehalfOf).

Specified by:
getServiceDocument in interface SWORDClient
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 interface SWORDClient
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

public SwordValidationInfo getLastUnmarshallInfo()
Returns:

postFile

public DepositResponse postFile(PostMessage message)
                         throws SWORDClientException
Post a file to the server. The different elements of the post are encoded in the specified message.

Specified by:
postFile in interface SWORDClient
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

public Status getStatus()
Return the status information that was returned from the most recent request sent to the server.

Specified by:
getStatus in interface SWORDClient
Returns:
The status code returned from the most recent access.


Copyright © 2011 DuraSpace. All Rights Reserved.