Commit
… set using by HTTP API from UriInfo baseURL Resolves: https://www.pivotaltracker.com/story/show/72351918
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ | |
import javax.jcr.PathNotFoundException; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.jcr.observation.ObservationManager; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.DELETE; | ||
|
@@ -140,6 +141,29 @@ public class FedoraNodes extends AbstractResource { | |
protected Session session; | ||
|
||
private static final Logger LOGGER = getLogger(FedoraNodes.class); | ||
private boolean baseURLSet = false; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
awoods
|
||
|
||
/** | ||
* Set the baseURL for JMS events. | ||
**/ | ||
private void init( final UriInfo uriInfo ) { | ||
if ( !baseURLSet ) { | ||
// set to true the first time this is run. if there is an exception the first time, there | ||
// will likely be an exception every time. since this is run on each repository update, | ||
// we should fail fast rather than retrying over and over. | ||
baseURLSet = true; | ||
try { | ||
final URI baseURL = uriInfo.getBaseUri(); | ||
LOGGER.debug("FedoraNodes.init(): baseURL = " + baseURL.toString()); | ||
final ObservationManager obs = session.getWorkspace().getObservationManager(); | ||
This comment has been minimized.
Sorry, something went wrong.
cbeer
Contributor
|
||
final String json = "{\"baseURL\":\"" + baseURL.toString() + "\"}"; | ||
obs.setUserData(json); | ||
LOGGER.trace("FedoraNodes.init(): done"); | ||
} catch ( Exception ex ) { | ||
LOGGER.warn("Error setting baseURL", ex); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Retrieve the node headers | ||
|
@@ -357,6 +381,7 @@ public Response updateSparql(@PathParam("path") | |
throws RepositoryException, IOException { | ||
throwIfPathIncludesJcr(pathList, "PATCH"); | ||
|
||
init(uriInfo); | ||
final String path = toPath(pathList); | ||
LOGGER.debug("Attempting to update path: {}", path); | ||
|
||
|
@@ -436,6 +461,7 @@ public Response createOrReplaceObjectRdf( | |
@Context final HttpServletResponse servletResponse) throws RepositoryException, ParseException, | ||
IOException, InvalidChecksumException, URISyntaxException { | ||
throwIfPathIncludesJcr(pathList, "PUT"); | ||
init(uriInfo); | ||
|
||
final String path = toPath(pathList); | ||
LOGGER.debug("Attempting to replace path: {}", path); | ||
|
@@ -521,6 +547,7 @@ public Response createObject(@PathParam("path") | |
throws RepositoryException, ParseException, IOException, | ||
InvalidChecksumException, URISyntaxException { | ||
throwIfPathIncludesJcr(pathList, "POST"); | ||
init(uriInfo); | ||
|
||
String pid; | ||
final String newObjectPath; | ||
|
@@ -700,6 +727,7 @@ public Response createObjectFromFormPost( | |
@FormDataParam("file") final InputStream file | ||
) throws RepositoryException, URISyntaxException, InvalidChecksumException, ParseException, IOException { | ||
throwIfPathIncludesJcr(pathList, "POST with multipart attachment"); | ||
init(uriInfo); | ||
|
||
final MediaType effectiveContentType = file == null ? null : MediaType.APPLICATION_OCTET_STREAM_TYPE; | ||
return createObject(pathList, mixin, null, null, effectiveContentType, slug, servletResponse, uriInfo, file); | ||
|
@@ -719,6 +747,7 @@ public Response deleteObject(@PathParam("path") | |
final List<PathSegment> pathList, | ||
@Context final Request request) throws RepositoryException { | ||
throwIfPathIncludesJcr(pathList, "DELETE"); | ||
init(uriInfo); | ||
|
||
try { | ||
|
||
|
@@ -747,6 +776,7 @@ public Response copyObject(@PathParam("path") final List<PathSegment> path, | |
@HeaderParam("Destination") final String destinationUri) | ||
throws RepositoryException, URISyntaxException { | ||
throwIfPathIncludesJcr(path, "COPY"); | ||
init(uriInfo); | ||
|
||
try { | ||
|
||
|
@@ -794,6 +824,7 @@ public Response moveObject(@PathParam("path") final List<PathSegment> pathList, | |
@Context final Request request) | ||
throws RepositoryException, URISyntaxException { | ||
throwIfPathIncludesJcr(pathList, "MOVE"); | ||
init(uriInfo); | ||
|
||
try { | ||
|
||
|
I think baseURLSet needs to be static -- otherwise it's going to be initialized for each request and the observation manager will be loaded each time. I can reproduce @jcoyne's problem with about 2000 updates, and making baseURLSet fixes it.
@awoods: Reproducing this bug takes around 30 seconds on my machine. Should I go ahead and create an IT to test this anyway?