Commit 51ad0ea3 authored by acoburn's avatar acoburn
Browse files

update interface to template service

parent 2583804b
...@@ -6,9 +6,7 @@ dependencies { ...@@ -6,9 +6,7 @@ dependencies {
compile group: 'org.apache.camel', name: 'camel-blueprint', version: camelVersion compile group: 'org.apache.camel', name: 'camel-blueprint', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-jetty9', version: camelVersion compile group: 'org.apache.camel', name: 'camel-jetty9', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-exec', version: camelVersion compile group: 'org.apache.camel', name: 'camel-exec', version: camelVersion
compile(group: 'org.fcrepo.camel', name: 'fcrepo-camel', version: fcrepoCamelVersion) {
exclude(module: 'slf4j-log4j12')
}
testCompile group: 'junit', name: 'junit', version: junitVersion testCompile group: 'junit', name: 'junit', version: junitVersion
testCompile group: 'org.apache.camel', name: 'camel-test-blueprint', version: camelVersion testCompile group: 'org.apache.camel', name: 'camel-test-blueprint', version: camelVersion
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion testCompile group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion
......
...@@ -23,8 +23,6 @@ import static org.apache.camel.Exchange.HTTP_URI; ...@@ -23,8 +23,6 @@ import static org.apache.camel.Exchange.HTTP_URI;
import static org.apache.camel.LoggingLevel.INFO; import static org.apache.camel.LoggingLevel.INFO;
import static org.apache.camel.builder.PredicateBuilder.and; import static org.apache.camel.builder.PredicateBuilder.and;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS; import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_BASE_URL;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_URI;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
import java.io.InputStream; import java.io.InputStream;
...@@ -43,6 +41,8 @@ import org.slf4j.Logger; ...@@ -43,6 +41,8 @@ import org.slf4j.Logger;
*/ */
public class EventRouter extends RouteBuilder { public class EventRouter extends RouteBuilder {
private static final String FEDORA_BASE_URL = "CamelFedoraBaseUrl";
private static final String FEDORA_URI = "CamelFedoraUri";
private static final String IMAGE_OUTPUT = "CamelImageOutput"; private static final String IMAGE_OUTPUT = "CamelImageOutput";
private static final String IMAGE_INPUT = "CamelImageInput"; private static final String IMAGE_INPUT = "CamelImageInput";
private static final String HTTP_ACCEPT = "Accept"; private static final String HTTP_ACCEPT = "Accept";
...@@ -59,14 +59,14 @@ public class EventRouter extends RouteBuilder { ...@@ -59,14 +59,14 @@ public class EventRouter extends RouteBuilder {
from("jetty:http://{{rest.host}}:{{rest.port}}{{rest.prefix}}?" + from("jetty:http://{{rest.host}}:{{rest.port}}{{rest.prefix}}?" +
"sendServerVersion=false&" + "sendServerVersion=false&" +
"httpMethodRestrict=GET,OPTIONS").routeId("ImageRouter") "httpMethodRestrict=GET,OPTIONS").routeId("ImageRouter")
.process(e -> e.getIn().setHeader(FCREPO_URI, .process(e -> e.getIn().setHeader(FEDORA_URI,
e.getIn().getHeader(HTTP_QUERY_CONTEXT, e.getIn().getHeader(HTTP_QUERY_CONTEXT,
e.getIn().getHeader("Apix-Ldp-Resource-Path")))) e.getIn().getHeader("Apix-Ldp-Resource-Path"))))
.setHeader(FCREPO_BASE_URL).simple("{{fcrepo.baseUrl}}") .setHeader(FEDORA_BASE_URL).simple("{{fcrepo.baseUrl}}")
.setHeader(IMAGE_OUTPUT).header(HTTP_ACCEPT) .setHeader(IMAGE_OUTPUT).header(HTTP_ACCEPT)
.removeHeaders(HTTP_ACCEPT) .removeHeaders(HTTP_ACCEPT)
.choice() .choice()
.when(and(header(HTTP_METHOD).isEqualTo("GET"), header(FCREPO_URI).startsWith(header(FCREPO_BASE_URL)))) .when(and(header(HTTP_METHOD).isEqualTo("GET"), header(FEDORA_URI).startsWith(header(FEDORA_BASE_URL))))
.to("direct:get") .to("direct:get")
.when(header(HTTP_METHOD).isEqualTo("OPTIONS")) .when(header(HTTP_METHOD).isEqualTo("OPTIONS"))
.setHeader(CONTENT_TYPE).constant("text/turtle") .setHeader(CONTENT_TYPE).constant("text/turtle")
...@@ -78,7 +78,7 @@ public class EventRouter extends RouteBuilder { ...@@ -78,7 +78,7 @@ public class EventRouter extends RouteBuilder {
.transform(constant("Missing/invalid context parameter")); .transform(constant("Missing/invalid context parameter"));
from("direct:get").routeId("ImageGet") from("direct:get").routeId("ImageGet")
.setHeader(HTTP_URI).header(FCREPO_URI) .setHeader(HTTP_URI).header(FEDORA_URI)
.setHeader(HTTP_METHOD).constant("HEAD") .setHeader(HTTP_METHOD).constant("HEAD")
.to("http4://localhost?authUsername={{fcrepo.authUsername}}" + .to("http4://localhost?authUsername={{fcrepo.authUsername}}" +
"&authPassword={{fcrepo.authPassword}}&throwExceptionOnFailure=false") "&authPassword={{fcrepo.authPassword}}&throwExceptionOnFailure=false")
...@@ -106,7 +106,7 @@ public class EventRouter extends RouteBuilder { ...@@ -106,7 +106,7 @@ public class EventRouter extends RouteBuilder {
from("direct:convert").routeId("ImageConvert") from("direct:convert").routeId("ImageConvert")
.setHeader(HTTP_METHOD).constant("GET") .setHeader(HTTP_METHOD).constant("GET")
.setHeader(HTTP_URI).header(FCREPO_URI) .setHeader(HTTP_URI).header(FEDORA_URI)
.to("http4://localhost?authUsername={{fcrepo.authUsername}}" + .to("http4://localhost?authUsername={{fcrepo.authUsername}}" +
"&authPassword={{fcrepo.authPassword}}&throwExceptionOnFailure=true") "&authPassword={{fcrepo.authPassword}}&throwExceptionOnFailure=true")
.setHeader(IMAGE_INPUT).header(CONTENT_TYPE) .setHeader(IMAGE_INPUT).header(CONTENT_TYPE)
......
...@@ -3,14 +3,13 @@ Amherst College Template Rendering Service ...@@ -3,14 +3,13 @@ Amherst College Template Rendering Service
This service renders fedora resources using a Mustache template. This service renders fedora resources using a Mustache template.
The service becomes available over HTTP on the configured port. For example, The service becomes available over HTTP on the configured port. For example:
in order to retrieve a MODS version of the resource `a/b/c`:
curl localhost:9103/template/a/b/c curl http://localhost:9103/template?context=http://localhost:8080/fcrepo/rest/resource
One can have the module use a customized Mustache template by doing the following: One can have the module use a customized Mustache template by doing the following:
curl localhost:9103/template/a/b/c?templateUri=/path/to/template/template2.mustache curl "http://localhost:9103/template?context=http://localhost:8080/fcrepo/rest/resource&templateUri=/path/to/template/template2.mustache"
Building Building
-------- --------
...@@ -54,7 +53,7 @@ The prefix for the service ...@@ -54,7 +53,7 @@ The prefix for the service
The fedora baseUrl value The fedora baseUrl value
fcrepo.baseUrl=localhost:8080/fcrepo/rest fcrepo.baseUrl=http://localhost:8080/fcrepo/rest
The location of the mustache template The location of the mustache template
...@@ -64,9 +63,9 @@ The content-type of the rendered template ...@@ -64,9 +63,9 @@ The content-type of the rendered template
mustache.contentType=text/html mustache.contentType=text/html
The json+ld context file The LDPath service URL
jsonld.context=https://acdc.amherst.edu/jsonld/context.json ldpath.serviceUrl=http://localhost:9086/ldpath
By editing this file, any currently running routes will be immediately redeployed By editing this file, any currently running routes will be immediately redeployed
with the new values. with the new values.
......
...@@ -8,11 +8,8 @@ dependencies { ...@@ -8,11 +8,8 @@ dependencies {
compile group: 'org.apache.camel', name: 'camel-http4', version: camelVersion compile group: 'org.apache.camel', name: 'camel-http4', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-jackson', version: camelVersion compile group: 'org.apache.camel', name: 'camel-jackson', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-mustache', version: camelVersion compile group: 'org.apache.camel', name: 'camel-mustache', version: camelVersion
compile(group: 'org.fcrepo.camel', name: 'fcrepo-camel', version: fcrepoCamelVersion) {
exclude(module: 'slf4j-log4j12')
}
compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
testCompile group: 'xerces', name: 'xercesImpl', version: xercesVersion
testCompile group: 'junit', name: 'junit', version: junitVersion testCompile group: 'junit', name: 'junit', version: junitVersion
testCompile group: 'org.apache.camel', name: 'camel-test-blueprint', version: camelVersion testCompile group: 'org.apache.camel', name: 'camel-test-blueprint', version: camelVersion
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion testCompile group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion
......
...@@ -23,8 +23,8 @@ import static org.apache.camel.Exchange.HTTP_QUERY; ...@@ -23,8 +23,8 @@ import static org.apache.camel.Exchange.HTTP_QUERY;
import static org.apache.camel.Exchange.HTTP_URI; import static org.apache.camel.Exchange.HTTP_URI;
import static org.apache.camel.Exchange.HTTP_RESPONSE_CODE; import static org.apache.camel.Exchange.HTTP_RESPONSE_CODE;
import static org.apache.camel.LoggingLevel.INFO; import static org.apache.camel.LoggingLevel.INFO;
import static org.apache.camel.builder.PredicateBuilder.and;
import static org.apache.camel.model.dataformat.JsonLibrary.Jackson; import static org.apache.camel.model.dataformat.JsonLibrary.Jackson;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_IDENTIFIER;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
import java.util.List; import java.util.List;
...@@ -37,6 +37,10 @@ import org.slf4j.Logger; ...@@ -37,6 +37,10 @@ import org.slf4j.Logger;
*/ */
public class EventRouter extends RouteBuilder { public class EventRouter extends RouteBuilder {
private static final String FEDORA_URI = "CamelFedoraUri";
private static final String FEDORA_BASE_URL = "CamelFedoraBaseUrl";
private static final String HTTP_QUERY_CONTEXT = "context";
private static final Logger LOGGER = getLogger(EventRouter.class); private static final Logger LOGGER = getLogger(EventRouter.class);
/** /**
...@@ -52,14 +56,15 @@ public class EventRouter extends RouteBuilder { ...@@ -52,14 +56,15 @@ public class EventRouter extends RouteBuilder {
.log("Event Routing Error: ${routeId}"); .log("Event Routing Error: ${routeId}");
from("jetty:http://{{rest.host}}:{{rest.port}}/template?" + from("jetty:http://{{rest.host}}:{{rest.port}}/template?" +
"matchOnUriPrefix=true&httpMethodRestrict=GET,OPTIONS&sendServerVersion=false") "httpMethodRestrict=GET,OPTIONS&sendServerVersion=false")
.routeId("TemplateTransformation") .routeId("TemplateTransformation")
.process(e -> e.getIn().setHeader(FEDORA_URI,
e.getIn().getHeader(HTTP_QUERY_CONTEXT,
e.getIn().getHeader("Apix-Ldp-Resource-Path"))))
.setHeader(FEDORA_BASE_URL).simple("{{fcrepo.baseUrl}}")
.choice() .choice()
.when(header(HTTP_METHOD).isEqualTo("GET")) .when(and(header(HTTP_METHOD).isEqualTo("GET"), header(FEDORA_URI).startsWith(header(FEDORA_BASE_URL))))
.process(e -> e.getIn().setHeader(FCREPO_IDENTIFIER, .log(INFO, LOGGER, "PATH: ${headers[CamelFedoraUri]}")
e.getIn().getHeader("Apix-Ldp-Resource-Path",
e.getIn().getHeader(HTTP_PATH))))
.log(INFO, LOGGER, "PATH: ${headers[CamelFcrepoIdentifier]}")
.removeHeader("breadcrumbId") .removeHeader("breadcrumbId")
.removeHeader("Accept") .removeHeader("Accept")
.removeHeader("User-Agent") .removeHeader("User-Agent")
...@@ -69,19 +74,21 @@ public class EventRouter extends RouteBuilder { ...@@ -69,19 +74,21 @@ public class EventRouter extends RouteBuilder {
.setHeader("Allow").constant("GET,OPTIONS") .setHeader("Allow").constant("GET,OPTIONS")
.to("language:simple:resource:classpath:options.ttl"); .to("language:simple:resource:classpath:options.ttl");
from("direct:getFromFedora") from("direct:getFromFedora").routeId("FetchFromRepository")
.routeId("FetchFromRepository")
.removeHeaders("CamelHttp*") .removeHeaders("CamelHttp*")
.setHeader(HTTP_URI).simple("{{ldpath.serviceUrl}}") .setHeader(HTTP_URI).simple("{{ldpath.serviceUrl}}")
.setHeader(HTTP_QUERY).simple("context={{fcrepo.baseUrl}}${headers[CamelFcrepoIdentifier]}") .setHeader(HTTP_QUERY).simple("context=${headers[CamelFedoraUri]}")
.setHeader(HTTP_METHOD).constant("GET") .setHeader(HTTP_METHOD).constant("GET")
.removeHeaders("CamelFedora*")
.removeHeaders("Host")
.removeHeaders("context")
.removeHeaders("Content-Type")
.removeHeaders("CamelServlet*")
.to("http4://localhost") .to("http4://localhost")
.filter(header(HTTP_RESPONSE_CODE).isEqualTo(200)) .filter(header(HTTP_RESPONSE_CODE).isEqualTo(200))
.to("direct:template"); .to("direct:template");
from("direct:template").routeId("TemplateRoute")
from("direct:template")
.routeId("TemplateRoute")
.setHeader(CONTENT_TYPE).simple("{{mustache.contentType}}") .setHeader(CONTENT_TYPE).simple("{{mustache.contentType}}")
.unmarshal().json(Jackson, List.class) .unmarshal().json(Jackson, List.class)
.setBody(simple("${body[0]}")) .setBody(simple("${body[0]}"))
...@@ -93,8 +100,7 @@ public class EventRouter extends RouteBuilder { ...@@ -93,8 +100,7 @@ public class EventRouter extends RouteBuilder {
/* the MUSTACHE_RESOURCE_URI in header overrides the passed in value below */ /* the MUSTACHE_RESOURCE_URI in header overrides the passed in value below */
.to("mustache:dummy"); .to("mustache:dummy");
from("direct:defaultTemplate") from("direct:defaultTemplate").routeId("DefaultTemplateRoute")
.routeId("DefaultTemplateRoute")
.to("mustache:{{mustache.templateUri}}"); .to("mustache:{{mustache.templateUri}}");
} }
} }
......
...@@ -140,7 +140,6 @@ ...@@ -140,7 +140,6 @@
<feature version="${camelVersionRange}">camel-jetty9</feature> <feature version="${camelVersionRange}">camel-jetty9</feature>
<feature version="${camelVersionRange}">camel-jackson</feature> <feature version="${camelVersionRange}">camel-jackson</feature>
<feature version="${camelVersionRange}">camel-http4</feature> <feature version="${camelVersionRange}">camel-http4</feature>
<feature version="${fcrepoCamelVersionRange}">fcrepo-camel</feature>
<bundle>mvn:edu.amherst.acdc/acrepo-exts-template/${project.version}</bundle> <bundle>mvn:edu.amherst.acdc/acrepo-exts-template/${project.version}</bundle>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment