Skip to content
Permalink
Browse files

Using System property to pass baseURL instead of ObservationManager (…

…FCREPO-1272)
  • Loading branch information...
escowles committed Jan 16, 2015
1 parent 41e3fb8 commit 00ad35402210feded8faa5df9f3d90ec0512b42b
@@ -15,6 +15,8 @@
*/
package org.fcrepo.http.api;

import static org.fcrepo.kernel.observer.FedoraEvent.BASE_URL_PROPERTY;

import com.google.common.annotations.VisibleForTesting;
import com.hp.hpl.jena.rdf.model.Resource;
import org.fcrepo.http.commons.AbstractResource;
@@ -26,15 +28,13 @@
import org.slf4j.Logger;

import javax.jcr.Session;
import javax.jcr.observation.ObservationManager;
import javax.ws.rs.core.UriInfo;

import java.net.URI;

import static org.slf4j.LoggerFactory.getLogger;

/**
* @author cabeer
* @author escowles
* @since 10/5/14
*/
abstract public class FedoraBaseResource extends AbstractResource {
@@ -76,11 +76,11 @@ public FedoraResource getResourceFromPath(final String externalPath) {
**/
protected void setUpJMSBaseURIs(final UriInfo uriInfo) {
try {
final URI baseURL = uriInfo.getBaseUri();
LOGGER.debug("setting baseURL = " + baseURL.toString());
final ObservationManager obs = session().getWorkspace().getObservationManager();
final String json = "{\"baseURL\":\"" + baseURL.toString() + "\"}";
obs.setUserData(json);
if (System.getProperty(BASE_URL_PROPERTY) == null) {
final String baseURL = uriInfo.getBaseUri().toString();
LOGGER.debug("setting baseURL = " + baseURL);
System.setProperty(BASE_URL_PROPERTY, baseURL);
}
} catch ( Exception ex ) {
LOGGER.warn("Error setting baseURL", ex);
}
@@ -16,6 +16,7 @@
package org.fcrepo.jms.headers;

import static org.fcrepo.kernel.RdfLexicon.REPOSITORY_NAMESPACE;
import static org.fcrepo.kernel.observer.FedoraEvent.BASE_URL_PROPERTY;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.slf4j.LoggerFactory.getLogger;

@@ -34,8 +35,6 @@
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Iterables;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

/**
* Generates JMS {@link Message}s composed entirely of headers, based entirely
@@ -71,10 +70,8 @@
*/
private void setBaseURL(final FedoraEvent event) {
try {
final String userdata = event.getUserData();
if (!StringUtils.isBlank(userdata)) {
final JsonObject json = new JsonParser().parse(userdata).getAsJsonObject();
String url = json.get("baseURL").getAsString();
if (!StringUtils.isBlank(System.getProperty(BASE_URL_PROPERTY))) {
String url = System.getProperty(BASE_URL_PROPERTY);
while (url.endsWith("/")) {
url = url.substring(0, url.length() - 1);
}
@@ -23,6 +23,7 @@
import static org.fcrepo.jms.headers.DefaultMessageFactory.PROPERTIES_HEADER_NAME;
import static org.fcrepo.jms.headers.DefaultMessageFactory.TIMESTAMP_HEADER_NAME;
import static org.fcrepo.kernel.RdfLexicon.REPOSITORY_NAMESPACE;
import static org.fcrepo.kernel.observer.FedoraEvent.BASE_URL_PROPERTY;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.doThrow;
@@ -97,11 +98,11 @@ private Message doTestBuildMessage(final String baseUrl, final String id) throws
final Long testDate = 46647758568747L;
when(mockEvent.getDate()).thenReturn(testDate);

String url = null;
if (!StringUtils.isBlank(baseUrl)) {
url = "{\"baseURL\":\"" + baseUrl + "\"}";
if (StringUtils.isBlank(baseUrl)) {
System.clearProperty(BASE_URL_PROPERTY);
} else {
System.setProperty(BASE_URL_PROPERTY, baseUrl);
}
when(mockEvent.getUserData()).thenReturn(url);
when(mockEvent.getPath()).thenReturn(id);
final Set<Integer> testTypes = singleton(NODE_ADDED);
final String testReturnType = REPOSITORY_NAMESPACE + EventType.valueOf(NODE_ADDED).toString();
@@ -47,6 +47,7 @@
*/
public class FedoraEvent {

public static final String BASE_URL_PROPERTY = "fcrepo.baseURL";
private Event e;

private Set<Integer> eventTypes = new HashSet<>();

0 comments on commit 00ad354

Please sign in to comment.
You can’t perform that action at this time.