org.fcrepo.client
Class FedoraClient

java.lang.Object
  extended by org.fcrepo.client.FedoraClient
All Implemented Interfaces:
Constants

public class FedoraClient
extends Object
implements Constants

General-purpose utility class for Fedora clients. Provides methods to get SOAP stubs for Fedora APIs. Also serves as one-stop-shopping for issuing HTTP requests using Apache's HttpClient. Provides option for client to handle HTTP redirects (notably 302 status that occurs with SSL auto-redirects at server.)

Author:
Chris Wilper, Sandy Payette

Nested Class Summary
 class FedoraClient.SOAPEndpoint
          Class for storing a Fedora SOAP endpoint, which consists of an endpoint name and a URL.
 
Nested classes/interfaces inherited from interface org.fcrepo.common.Constants
Constants.FedoraHome
 
Field Summary
static String FEDORA_URI_PREFIX
           
 boolean FOLLOW_REDIRECTS
          Whether to automatically follow HTTP redirects.
 int MAX_CONNECTIONS_PER_HOST
          Maxiumum http connections per host (for REST calls only).
 int MAX_TOTAL_CONNECTIONS
          Maxiumum total http connections (for REST calls only).
 int SOCKET_TIMEOUT_SECONDS
          Seconds to wait while waiting for data over the socket (SO_TIMEOUT).
 int TIMEOUT_SECONDS
          Seconds to wait before a connection is established.
 
Fields inherited from interface org.fcrepo.common.Constants
ACCESS, ACTION, API, ATOM_APIM1_0, ATOM_ZIP1_1, ATOM1_1, AUDIT, AUDIT1_0, BATCH_MODIFY, BATCH_MODIFY1_1, BE_SECURITY, BE_SECURITY1_0, BINDING_SPEC, DATASTREAM, DC, DISSEMINATOR, DS_COMPOSITE_MODEL, DS_COMPOSITE_MODEL1_0, DS_INPUT_SPEC1_0, DS_INPUT_SPEC1_1, ENVIRONMENT, FCFG, FEDORA, FEDORA_APP_CONTEXT_NAME, FEDORA_DEFAULT_APP_CONTEXT, FEDORA_HOME, FOXML, FOXML1_0, FOXML1_0_LEGACY, FOXML1_1, HTTP_REQUEST, MANAGEMENT, METHOD_MAP, METS, METS_EXT, METS_EXT1_0, METS_EXT1_0_LEGACY, METS_EXT1_1, MODEL, MULGARA, OAI_DC, OAI_DC2_0, OAI_FRIENDS, OAI_FRIENDS2_0, OAI_IDENTIFIER, OAI_IDENTIFIER2_0, OAI_PMH, OAI_PMH2_0, OAI_PROV, OAI_PROV2_0, OBJ_DATASTREAMS1_0, OBJ_HISTORY1_0, OBJ_ITEMS1_0, OBJ_METHODS1_0, OBJ_PROFILE1_0, OBJ_VALIDATION1_0, OBJECT, OLD_XLINK, PID_LIST1_0, RDF, RDF_XSD, RECOVERY, RELS_EXT, RELS_EXT1_0, RELS_INT1_0, REPO_DESC1_0, RESOURCE, SDEF, SDEF_METHOD_MAP1_0, SDEP, SDEP_METHOD_MAP1_0, SDEP_METHOD_MAP1_1, SERVICE_PROFILE, SOAP, SOAP_ENC, SUBJECT, TYPES, VIEW, WSDL, WSDL_HTTP, WSDL_MIME, XACML_POLICY, XACML_POLICY1_0, XLINK, XML_XSD, XMLNS, XSI
 
Constructor Summary
FedoraClient(String baseURL, String user, String pass)
           
 
Method Summary
 HttpInputStream get(String locator, boolean failIfNotOK)
          Get an HTTP resource with the response as an InputStream, given a resource locator that either begins with 'info:fedora/' , 'http://', or '/'.
 HttpInputStream get(String locator, boolean failIfNotOK, boolean followRedirects)
          Get an HTTP resource with the response as an InputStream, given a resource locator that either begins with 'info:fedora/' , 'http://', or '/'.
 HttpInputStream get(URL url, boolean failIfNotOK)
          Get an HTTP resource with the response as an InputStream, given a URL.
 HttpInputStream get(URL url, boolean failIfNotOK, boolean followRedirects)
          Get an HTTP resource with the response as an InputStream, given a URL.
 FedoraAPIA getAPIA()
          Get a new SOAP stub for API-A.
 URL getAPIAEndpointURL()
           
 FedoraAPIAMTOM getAPIAMTOM()
           
 URL getAPIAMTOMEndpointURL()
           
 FedoraAPIM getAPIM()
          Get a new SOAP stub for API-M.
 URL getAPIMEndpointURL()
           
 FedoraAPIMMTOM getAPIMMTOM()
           
 URL getAPIMMTOMEndpointURL()
           
static List<String> getCompatibleServerVersions()
           
 org.apache.commons.httpclient.HttpClient getHttpClient()
           
 Date getLastModifiedDate(String locator)
           
 String getResponseAsString(String locator, boolean failIfNotOK, boolean followRedirects)
          Get an HTTP resource with the response as a String instead of an InputStream, given a resource locator that either begins with 'info:fedora/' , 'http://', or '/'.
 Date getServerDate()
          Return the current date as reported by the Fedora server.
 String getServerVersion()
          Get the version reported by the remote Fedora server.
 org.trippi.TupleIterator getTuples(Map<String,String> params)
          Get tuples from the remote resource index.
 String getUploadURL()
          Get the URL to which API-M upload requests will be sent.
static String getVersion()
           
 void reloadPolicies()
           
 String uploadFile(File file)
          Upload the given file to Fedora's upload interface via HTTP POST.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FEDORA_URI_PREFIX

public static final String FEDORA_URI_PREFIX
See Also:
Constant Field Values

TIMEOUT_SECONDS

public int TIMEOUT_SECONDS
Seconds to wait before a connection is established.


SOCKET_TIMEOUT_SECONDS

public int SOCKET_TIMEOUT_SECONDS
Seconds to wait while waiting for data over the socket (SO_TIMEOUT).


MAX_CONNECTIONS_PER_HOST

public int MAX_CONNECTIONS_PER_HOST
Maxiumum http connections per host (for REST calls only).


MAX_TOTAL_CONNECTIONS

public int MAX_TOTAL_CONNECTIONS
Maxiumum total http connections (for REST calls only).


FOLLOW_REDIRECTS

public boolean FOLLOW_REDIRECTS
Whether to automatically follow HTTP redirects.

Constructor Detail

FedoraClient

public FedoraClient(String baseURL,
                    String user,
                    String pass)
             throws MalformedURLException
Throws:
MalformedURLException
Method Detail

getHttpClient

public org.apache.commons.httpclient.HttpClient getHttpClient()

uploadFile

public String uploadFile(File file)
                  throws IOException
Upload the given file to Fedora's upload interface via HTTP POST.

Returns:
the temporary id which can then be passed to API-M requests as a URL. It will look like uploaded://123
Throws:
IOException

getUploadURL

public String getUploadURL()
                    throws IOException
Get the URL to which API-M upload requests will be sent.

Throws:
IOException

get

public HttpInputStream get(String locator,
                           boolean failIfNotOK)
                    throws IOException
Get an HTTP resource with the response as an InputStream, given a resource locator that either begins with 'info:fedora/' , 'http://', or '/'. This method will follow redirects if FOLLOW_REDIRECTS is true. Note that if the HTTP response has no body, the InputStream will be empty. The success of a request can be checked with getResponseCode(). Usually you'll want to see a 200. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for other codes.

Parameters:
locator - A URL, relative Fedora URL, or Fedora URI that we want to do an HTTP GET upon
failIfNotOK - boolean value indicating if an exception should be thrown if we do NOT receive an HTTP 200 response (OK)
Returns:
HttpInputStream the HTTP response
Throws:
IOException

get

public HttpInputStream get(URL url,
                           boolean failIfNotOK)
                    throws IOException
Get an HTTP resource with the response as an InputStream, given a URL. This method will follow redirects if FOLLOW_REDIRECTS is true. Note that if the HTTP response has no body, the InputStream will be empty. The success of a request can be checked with getResponseCode(). Usually you'll want to see a 200. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for other codes.

Parameters:
url - A URL that we want to do an HTTP GET upon
failIfNotOK - boolean value indicating if an exception should be thrown if we do NOT receive an HTTP 200 response (OK)
Returns:
HttpInputStream the HTTP response
Throws:
IOException

get

public HttpInputStream get(String locator,
                           boolean failIfNotOK,
                           boolean followRedirects)
                    throws IOException
Get an HTTP resource with the response as an InputStream, given a resource locator that either begins with 'info:fedora/' , 'http://', or '/'. Note that if the HTTP response has no body, the InputStream will be empty. The success of a request can be checked with getResponseCode(). Usually you'll want to see a 200. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for other codes.

Parameters:
locator - A URL, relative Fedora URL, or Fedora URI that we want to do an HTTP GET upon
failIfNotOK - boolean value indicating if an exception should be thrown if we do NOT receive an HTTP 200 response (OK)
followRedirects - boolean value indicating whether HTTP redirects should be handled in this method, or be passed along so that they can be handled later.
Returns:
HttpInputStream the HTTP response
Throws:
IOException

get

public HttpInputStream get(URL url,
                           boolean failIfNotOK,
                           boolean followRedirects)
                    throws IOException
Get an HTTP resource with the response as an InputStream, given a URL. Note that if the HTTP response has no body, the InputStream will be empty. The success of a request can be checked with getResponseCode(). Usually you'll want to see a 200. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for other codes.

Parameters:
url - A URL that we want to do an HTTP GET upon
failIfNotOK - boolean value indicating if an exception should be thrown if we do NOT receive an HTTP 200 response (OK)
followRedirects - boolean value indicating whether HTTP redirects should be handled in this method, or be passed along so that they can be handled later.
Returns:
HttpInputStream the HTTP response
Throws:
IOException

getResponseAsString

public String getResponseAsString(String locator,
                                  boolean failIfNotOK,
                                  boolean followRedirects)
                           throws IOException
Get an HTTP resource with the response as a String instead of an InputStream, given a resource locator that either begins with 'info:fedora/' , 'http://', or '/'.

Parameters:
locator - A URL, relative Fedora URL, or Fedora URI that we want to do an HTTP GET upon
failIfNotOK - boolean value indicating if an exception should be thrown if we do NOT receive an HTTP 200 response (OK)
followRedirects - boolean value indicating whether HTTP redirects should be handled in this method, or be passed along so that they can be handled later.
Returns:
String the HTTP response as a string
Throws:
IOException

getAPIA

public FedoraAPIA getAPIA()
                   throws javax.xml.rpc.ServiceException,
                          IOException
Get a new SOAP stub for API-A. If the baseURL for this FedoraClient specifies "http", regular HTTP communication will be attempted first. If the server redirects this client to use HTTPS instead, the redirect will be followed and SSL will be used automatically.

Throws:
javax.xml.rpc.ServiceException
IOException

getAPIAEndpointURL

public URL getAPIAEndpointURL()
                       throws IOException
Throws:
IOException

getAPIAMTOM

public FedoraAPIAMTOM getAPIAMTOM()
                           throws javax.xml.rpc.ServiceException,
                                  IOException
Throws:
javax.xml.rpc.ServiceException
IOException

getAPIAMTOMEndpointURL

public URL getAPIAMTOMEndpointURL()
                           throws IOException
Throws:
IOException

getAPIM

public FedoraAPIM getAPIM()
                   throws javax.xml.rpc.ServiceException,
                          IOException
Get a new SOAP stub for API-M. If the baseURL for this FedoraClient specifies "http", regular HTTP communication will be attempted first. If the server redirects this client to use HTTPS instead, the redirect will be followed and SSL will be used automatically.

Throws:
javax.xml.rpc.ServiceException
IOException

getAPIMEndpointURL

public URL getAPIMEndpointURL()
                       throws IOException
Throws:
IOException

getAPIMMTOM

public FedoraAPIMMTOM getAPIMMTOM()
                           throws javax.xml.rpc.ServiceException,
                                  IOException
Throws:
javax.xml.rpc.ServiceException
IOException

getAPIMMTOMEndpointURL

public URL getAPIMMTOMEndpointURL()
                           throws IOException
Throws:
IOException

getVersion

public static String getVersion()

getCompatibleServerVersions

public static List<String> getCompatibleServerVersions()

getServerVersion

public String getServerVersion()
                        throws IOException
Get the version reported by the remote Fedora server.

Throws:
IOException

getServerDate

public Date getServerDate()
                   throws IOException
Return the current date as reported by the Fedora server.

Throws:
IOException - if the HTTP Date header is not provided by the server for any reason, or it is in the wrong format.

getLastModifiedDate

public Date getLastModifiedDate(String locator)
                         throws IOException
Throws:
IOException

reloadPolicies

public void reloadPolicies()
                    throws IOException
Throws:
IOException

getTuples

public org.trippi.TupleIterator getTuples(Map<String,String> params)
                                   throws IOException
Get tuples from the remote resource index. The map contains String values for parameters that should be passed to the service. Two parameters are required: 1) lang 2) query Two parameters to the risearch service are implied: 1) type = tuples 2) format = sparql See http ://www.fedora.info/download/2.0/userdocs/server/webservices/risearch/# app.tuples

Throws:
IOException


Copyright © 2012 DuraSpace. All Rights Reserved.