Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow override of JMS baseUrl with system property fcrepo.jms.baseUrl
  • Loading branch information
whikloj authored and Andrew Woods committed Apr 17, 2015
1 parent c2bd525 commit 8779cf0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
Expand Up @@ -32,8 +32,6 @@
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriInfo;

import java.net.URI;

import static org.slf4j.LoggerFactory.getLogger;

/**
Expand Down Expand Up @@ -80,11 +78,14 @@ public FedoraResource getResourceFromPath(final String externalPath) {
**/
protected void setUpJMSInfo(final UriInfo uriInfo, final HttpHeaders headers) {
try {
final URI baseURL = uriInfo.getBaseUri();
LOGGER.debug("setting baseURL = " + baseURL.toString());
String baseURL = getBaseUrlProperty();
if (baseURL.length() == 0) {
baseURL = uriInfo.getBaseUri().toString();
}
LOGGER.debug("setting baseURL = " + baseURL);
final ObservationManager obs = session().getWorkspace().getObservationManager();
final JsonObject json = new JsonObject();
json.addProperty("baseURL", baseURL.toString());
json.addProperty("baseURL", baseURL);
if (!StringUtils.isBlank(headers.getHeaderString("user-agent"))) {
json.addProperty("userAgent",headers.getHeaderString("user-agent"));
}
Expand All @@ -94,4 +95,17 @@ protected void setUpJMSInfo(final UriInfo uriInfo, final HttpHeaders headers) {
}
}

/**
* Produce a baseURL for JMS events using the system property fcrepo.jms.baseUrl of the form http[s]://host[:port],
* if it exists.
*
* @return String the base Url
*/
protected String getBaseUrlProperty() {
final String propBaseURL = System.getProperty("fcrepo.jms.baseUrl", "");
if (propBaseURL.length() > 0 && propBaseURL.startsWith("http")) {
return uriInfo.getBaseUriBuilder().uri(propBaseURL).toString();
}
return "";
}
}
Expand Up @@ -119,6 +119,8 @@ public class FedoraLdpTest {
private final String binaryDescriptionPath = "/some/other/path";
private FedoraLdp testObj;

private static final String BASEURL_PROP = "fcrepo.jms.baseUrl";

@Mock
private Request mockRequest;

Expand Down Expand Up @@ -832,4 +834,18 @@ public void testSetUpJMSBaseURIs() throws RepositoryException {
testObj.setUpJMSInfo(getUriInfoImpl(), mockHeaders);
verify(mockManager).setUserData(eq(json));
}

@Test
public void testSetUpJMSBaseURIsWithSystemProperty() throws RepositoryException {
System.setProperty(BASEURL_PROP, "https://localhome:8443");

final ObservationManager mockManager = mock(ObservationManager.class);
final Workspace mockWorkspace = mock(Workspace.class);
doReturn(mockWorkspace).when(mockSession).getWorkspace();
doReturn(mockManager).when(mockWorkspace).getObservationManager();
final String json = "{\"baseURL\":\"https://localhome:8443/fcrepo\",\"userAgent\":\"Test UserAgent\"}";

testObj.setUpJMSInfo(getUriInfoImpl(), mockHeaders);
verify(mockManager).setUserData(eq(json));
}
}

0 comments on commit 8779cf0

Please sign in to comment.