Skip to content

Commit

Permalink
Implement EZID_PATH and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
mwoodiupui committed Feb 12, 2014
1 parent 93fc282 commit 057b310
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
Expand Up @@ -38,9 +38,9 @@ public class EZIDRequest
{ {
private static final Logger log = LoggerFactory.getLogger(EZIDRequest.class); private static final Logger log = LoggerFactory.getLogger(EZIDRequest.class);


private static final String ID_PATH = "/ezid/id/" + DOI.SCHEME; private static final String ID_PATH = "/id/" + DOI.SCHEME;


private static final String SHOULDER_PATH = "/ezid/shoulder/" + DOI.SCHEME; private static final String SHOULDER_PATH = "/shoulder/" + DOI.SCHEME;


private static final String UTF_8 = "UTF-8"; private static final String UTF_8 = "UTF-8";


Expand All @@ -52,6 +52,8 @@ public class EZIDRequest


private final String host; private final String host;


private final String path;

private final String authority; private final String authority;


/** /**
Expand All @@ -64,14 +66,59 @@ public class EZIDRequest
* @param username an EZID user identity. * @param username an EZID user identity.
* @param password user's password, or {@code null} for none. * @param password user's password, or {@code null} for none.
* @throws URISyntaxException if host or authority is bad. * @throws URISyntaxException if host or authority is bad.
* @deprecated since 4.1
*/ */
@Deprecated
EZIDRequest(String scheme, String host, String authority, String username, String password) EZIDRequest(String scheme, String host, String authority, String username, String password)
throws URISyntaxException throws URISyntaxException
{ {
this.scheme = scheme; this.scheme = scheme;


this.host = host; this.host = host;


this.path = "ezid";

if (authority.charAt(authority.length()-1) == '/')
{
this.authority = authority.substring(0, authority.length()-1);
}
else
{
this.authority = authority;
}

client = new DefaultHttpClient();
if (null != username)
{
URI uri = new URI(scheme, host, path, null);
client.getCredentialsProvider().setCredentials(
new AuthScope(uri.getHost(), uri.getPort()),
new UsernamePasswordCredentials(username, password));
}
}

/**
* Prepare a context for requests concerning a specific identifier or
* authority prefix.
*
* @param scheme URL scheme for access to the EZID service.
* @param host Host name for access to the EZID service.
* @param path Local-path to the EZID service.
* @param authority DOI authority prefix, e.g. "10.5072/FK2".
* @param username an EZID user identity.
* @param password user's password, or {@code null} for none.
* @throws URISyntaxException if host or authority is bad.
*/
EZIDRequest(String scheme, String host, String path,
String authority, String username, String password)
throws URISyntaxException
{
this.scheme = scheme;

this.host = host;

this.path = path;

if (authority.charAt(authority.length()-1) == '/') if (authority.charAt(authority.length()-1) == '/')
{ {
this.authority = authority.substring(0, authority.length()-1); this.authority = authority.substring(0, authority.length()-1);
Expand All @@ -84,7 +131,7 @@ public class EZIDRequest
client = new DefaultHttpClient(); client = new DefaultHttpClient();
if (null != username) if (null != username)
{ {
URI uri = new URI(scheme, host, null, null); URI uri = new URI(scheme, host, path, null);
client.getCredentialsProvider().setCredentials( client.getCredentialsProvider().setCredentials(
new AuthScope(uri.getHost(), uri.getPort()), new AuthScope(uri.getHost(), uri.getPort()),
new UsernamePasswordCredentials(username, password)); new UsernamePasswordCredentials(username, password));
Expand All @@ -103,7 +150,7 @@ public EZIDResponse lookup(String name)
{ {
// GET path // GET path
HttpGet request; HttpGet request;
URI uri = new URI(scheme, host, ID_PATH + authority + name, null); URI uri = new URI(scheme, host, path + ID_PATH + authority + name, null);
log.debug("EZID lookup {}", uri.toASCIIString()); log.debug("EZID lookup {}", uri.toASCIIString());
request = new HttpGet(uri); request = new HttpGet(uri);
HttpResponse response = client.execute(request); HttpResponse response = client.execute(request);
Expand All @@ -123,7 +170,7 @@ public EZIDResponse create(String name, Map<String, String> metadata)
{ {
// PUT path [+metadata] // PUT path [+metadata]
HttpPut request; HttpPut request;
URI uri = new URI(scheme, host, ID_PATH + authority + '/' + name, null); URI uri = new URI(scheme, host, path + ID_PATH + authority + '/' + name, null);
log.debug("EZID create {}", uri.toASCIIString()); log.debug("EZID create {}", uri.toASCIIString());
request = new HttpPut(uri); request = new HttpPut(uri);
if (null != metadata) if (null != metadata)
Expand All @@ -148,7 +195,7 @@ public EZIDResponse mint(Map<String, String> metadata)
{ {
// POST path [+metadata] // POST path [+metadata]
HttpPost request; HttpPost request;
URI uri = new URI(scheme, host, SHOULDER_PATH + authority, null); URI uri = new URI(scheme, host, path + SHOULDER_PATH + authority, null);
log.debug("EZID mint {}", uri.toASCIIString()); log.debug("EZID mint {}", uri.toASCIIString());
request = new HttpPost(uri); request = new HttpPost(uri);
if (null != metadata) if (null != metadata)
Expand Down Expand Up @@ -176,7 +223,7 @@ public EZIDResponse modify(String name, Map<String, String> metadata)
} }
// POST path +metadata // POST path +metadata
HttpPost request; HttpPost request;
URI uri = new URI(scheme, host, ID_PATH + authority + name, null); URI uri = new URI(scheme, host, path + ID_PATH + authority + name, null);
log.debug("EZID modify {}", uri.toASCIIString()); log.debug("EZID modify {}", uri.toASCIIString());
request = new HttpPost(uri); request = new HttpPost(uri);
request.setEntity(new StringEntity(formatMetadata(metadata), UTF_8)); request.setEntity(new StringEntity(formatMetadata(metadata), UTF_8));
Expand All @@ -192,7 +239,7 @@ public EZIDResponse delete(String name)
{ {
// DELETE path // DELETE path
HttpDelete request; HttpDelete request;
URI uri = new URI(scheme, host, ID_PATH + authority + name, null); URI uri = new URI(scheme, host, path + ID_PATH + authority + name, null);
log.debug("EZID delete {}", uri.toASCIIString()); log.debug("EZID delete {}", uri.toASCIIString());
request = new HttpDelete(uri); request = new HttpDelete(uri);
HttpResponse response = client.execute(request); HttpResponse response = client.execute(request);
Expand Down
Expand Up @@ -31,6 +31,7 @@ public class EZIDRequestFactory
{ {
private static String EZID_SCHEME; private static String EZID_SCHEME;
private static String EZID_HOST; private static String EZID_HOST;
private static String EZID_PATH;


/** /**
* Configure an EZID request. * Configure an EZID request.
Expand All @@ -43,11 +44,12 @@ public class EZIDRequestFactory
public EZIDRequest getInstance(String authority, String username, String password) public EZIDRequest getInstance(String authority, String username, String password)
throws URISyntaxException throws URISyntaxException
{ {
return new EZIDRequest(EZID_SCHEME, EZID_HOST, authority, username, password); return new EZIDRequest(EZID_SCHEME, EZID_HOST, EZID_PATH,
authority, username, password);
} }


/** /**
* @param aEZID_SCHEME the EZID URL scheme to set * @param aEZID_SCHEME the EZID URL scheme to set.
*/ */
@Required @Required
public static void setEZID_SCHEME(String aEZID_SCHEME) public static void setEZID_SCHEME(String aEZID_SCHEME)
Expand All @@ -56,11 +58,20 @@ public static void setEZID_SCHEME(String aEZID_SCHEME)
} }


/** /**
* @param aEZID_HOST the EZID host to set * @param aEZID_HOST the EZID host to set.
*/ */
@Required @Required
public static void setEZID_HOST(String aEZID_HOST) public static void setEZID_HOST(String aEZID_HOST)
{ {
EZID_HOST = aEZID_HOST; EZID_HOST = aEZID_HOST;
} }

/**
* @param aEZID_PATH the local path to the EZID API.
*/
@Required
public static void setEZID_PATH(String aEZID_PATH)
{
EZID_PATH = aEZID_PATH;
}
} }
3 changes: 2 additions & 1 deletion dspace/config/spring/api/identifier-service.xml
Expand Up @@ -77,7 +77,8 @@
<property name='requestFactory'> <property name='requestFactory'>
<bean class='org.dspace.identifier.ezid.EZIDRequestFactory'> <bean class='org.dspace.identifier.ezid.EZIDRequestFactory'>
<property name='EZID_SCHEME' value='https'/> <property name='EZID_SCHEME' value='https'/>
<property name='EZID_HOST' value='n2t.net'/> <property name='EZID_HOST' value='ezid.cdlib.org'/>
<property name='EZID_PATH' value=''/>
</bean> </bean>
</property> </property>
<property name='crosswalk'> <property name='crosswalk'>
Expand Down

0 comments on commit 057b310

Please sign in to comment.