Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enable configuration of JMS message host, port, and context
  • Loading branch information
Andrew Woods committed Aug 27, 2013
1 parent ad1b907 commit 619a8b4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
24 changes: 18 additions & 6 deletions fcrepo-jms/src/main/java/org/fcrepo/jms/legacy/LegacyMethod.java
Expand Up @@ -51,9 +51,6 @@
*/
public class LegacyMethod {

// TODO Figure out where to get the base url
private static final String BASE_URL = "http://localhost:8080/rest";

private static final Properties FEDORA_TYPES = new Properties();

public static final String FEDORA_ID_SCHEME = "xsd:string";
Expand Down Expand Up @@ -176,9 +173,9 @@ public void setContent(final String content) {
*/
public void setUserId(String val) {
if (val == null) {
delegate.addAuthor("unknown", null, BASE_URL);
delegate.addAuthor("unknown", null, getBaseURL());
} else {
delegate.addAuthor(val, null, BASE_URL);
delegate.addAuthor(val, null, getBaseURL());
}
}

Expand Down Expand Up @@ -215,7 +212,7 @@ public Date getModified() {
* @param val
*/
public void setMethodName(final String val) {
delegate.setTitle(val).setBaseUri(BASE_URL);
delegate.setTitle(val).setBaseUri(getBaseURL());
}

/**
Expand Down Expand Up @@ -290,6 +287,21 @@ public String getDsId() {
return getLabelledCategory(DSID_CATEGORY_LABEL);
}

protected String getBaseURL() {
StringBuilder url = new StringBuilder();
String host = System.getProperty("fcrepo.host", "localhost");
String port = System.getProperty("fcrepo.port", "8080");
String ctxt = System.getProperty("fcrepo.ctxt", "rest");

url.append(port.equalsIgnoreCase("443") ? "https://" : "http://");
url.append(host);
url.append(":");
url.append(port);
url.append("/");
url.append(ctxt);
return url.toString();
}

/**
* TODO
*
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.fcrepo.jms.legacy;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
Expand All @@ -41,8 +42,6 @@
import org.apache.abdera.model.Person;
import org.apache.abdera.model.Text;
import org.fcrepo.jcr.FedoraJcrTypes;
import org.fcrepo.jms.legacy.EntryFactory;
import org.fcrepo.jms.legacy.LegacyMethod;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -180,4 +179,37 @@ public void testWriteTo() throws IOException {
testObj.writeTo(mockWriter);
verify(mockDelegate).writeTo(mockWriter);
}

@Test
public void testGetBaseURL() {
String url = testObj.getBaseURL();
assertNotNull(url);
assertEquals("http://localhost:8080/rest", url);

final String host = "my-host";
System.setProperty("fcrepo.host", host);

url = testObj.getBaseURL();
assertNotNull(url);
assertEquals("http://" + host + ":8080/rest", url);

final String port = "443";
System.setProperty("fcrepo.port", port);

url = testObj.getBaseURL();
assertNotNull(url);
assertEquals("https://" + host + ":" + port + "/rest", url);

final String ctxt = "sleep";
System.setProperty("fcrepo.ctxt", ctxt);

url = testObj.getBaseURL();
assertNotNull(url);
assertEquals("https://" + host + ":" + port + "/" + ctxt, url);

System.clearProperty("fcrepo.host");
System.clearProperty("fcrepo.port");
System.clearProperty("fcrepo.ctxt");
}

}

0 comments on commit 619a8b4

Please sign in to comment.