private Response executeGraphExtension(final String graphName, final HttpMethod httpMethodRequested) {
ExtensionResponse extResponse;
ExtensionMethod methodToCall;
final ExtensionSegmentSet extensionSegmentSet = parseUriForExtensionSegment(graphName, ExtensionPoint.GRAPH);
// determine if the namespace and extension are enabled for this graph
final RexsterApplicationGraph rag = this.getRexsterApplicationGraph(graphName);
if (rag.isExtensionAllowed(extensionSegmentSet)) {
Object returnValue = null;
// namespace was allowed so try to run the extension
try {
// look for the extension as loaded through serviceloader
List<RexsterExtension> rexsterExtensions = null;
try {
rexsterExtensions = findExtensionClasses(extensionSegmentSet);
} catch (ServiceConfigurationError sce) {
logger.error("ServiceLoader could not find a class referenced in com.tinkerpop.rexster.extension.RexsterExtension.");
final JSONObject error = generateErrorObject(
"Class specified in com.tinkerpop.rexster.extension.RexsterExtension could not be found.",
sce);
throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity(error).build());
}
if (rexsterExtensions == null || rexsterExtensions.size() == 0) {
// extension was not found for some reason
logger.error("The [" + extensionSegmentSet + "] extension was not found for [" + graphName + "]. Check com.tinkerpop.rexster.extension.RexsterExtension file in META-INF.services.");
final JSONObject error = generateErrorObject(
"The [" + extensionSegmentSet + "] extension was not found for [" + graphName + "]");
throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity(error).build());
}
// look up the method on the extension that needs to be called.
methodToCall = findExtensionMethod(rexsterExtensions, ExtensionPoint.GRAPH, extensionSegmentSet.getExtensionMethod(), httpMethodRequested);
if (methodToCall == null) {
// extension method was not found for some reason
if (httpMethodRequested == HttpMethod.OPTIONS) {
// intercept the options call and return the standard business