Commit c3057e51 authored by bseeger's avatar bseeger
Browse files

Merge branch 'remove_jsonld_dependency' into 'master'

Replace the usage of acrepo-service-jsonld with acrepo-exts-ldpath

This makes the Template extension much more usable. As a follow-on, we should make the LDPath program configurable, but I want to get this in first.

See merge request !85
parents ba2918db e5406ced
......@@ -11,8 +11,8 @@ dependencies {
compile(group: 'org.fcrepo.camel', name: 'fcrepo-camel', version: fcrepoCamelVersion) {
exclude(module: 'slf4j-log4j12')
}
compile project(':acrepo-services-jsonld')
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: 'org.apache.camel', name: 'camel-test-blueprint', version: camelVersion
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion
......@@ -25,7 +25,7 @@ jar {
vendor project.vendor
license project.license
instruction 'Import-Package', "org.apache.camel,edu.amherst.acdc.services.jsonld,${defaultOsgiImports}"
instruction 'Import-Package', "org.apache.camel,${defaultOsgiImports}"
instruction 'Export-Package', "edu.amherst.acdc.exts.template;version=${projectOsgiVersion}"
}
}
......
......@@ -7,13 +7,14 @@ rest.port=9103
rest.prefix=/template
# The fedora baseUrl
fcrepo.baseUrl=localhost:8080/fcrepo/rest
fcrepo.baseUrl=http://localhost:8080/fcrepo/rest
# The resulting content-type
mustache.contentType=text/html
# The mustache template
mustache.templateUri=edu/amherst/acdc/template/template.mustache
mustache.templateUri=edu/amherst/acdc/exts/template/template.mustache
# The json+ld context file
jsonld.context=https://acdc.amherst.edu/jsonld/models.json
ldpath.serviceUrl=http://localhost:9086/ldpath
......@@ -19,18 +19,26 @@ import static org.apache.camel.component.mustache.MustacheConstants.MUSTACHE_RES
import static org.apache.camel.Exchange.CONTENT_TYPE;
import static org.apache.camel.Exchange.HTTP_METHOD;
import static org.apache.camel.Exchange.HTTP_PATH;
import static org.apache.camel.Exchange.HTTP_QUERY;
import static org.apache.camel.Exchange.HTTP_URI;
import static org.apache.camel.Exchange.HTTP_RESPONSE_CODE;
import static org.apache.camel.LoggingLevel.INFO;
import static org.apache.camel.model.dataformat.JsonLibrary.Jackson;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_IDENTIFIER;
import java.util.Map;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.List;
import org.apache.camel.model.dataformat.JsonLibrary;
import org.apache.camel.builder.RouteBuilder;
import org.slf4j.Logger;
/**
* @author Aaron Coburn
*/
public class EventRouter extends RouteBuilder {
private static final Logger LOGGER = getLogger(EventRouter.class);
/**
* Configure the message route workflow.
*/
......@@ -51,7 +59,7 @@ public class EventRouter extends RouteBuilder {
.process(e -> e.getIn().setHeader(FCREPO_IDENTIFIER,
e.getIn().getHeader("Apix-Ldp-Resource-Path",
e.getIn().getHeader(HTTP_PATH))))
.log("PATH: ${headers[CamelFcrepoIdentifier]}")
.log(INFO, LOGGER, "PATH: ${headers[CamelFcrepoIdentifier]}")
.removeHeader("breadcrumbId")
.removeHeader("Accept")
.removeHeader("User-Agent")
......@@ -63,16 +71,20 @@ public class EventRouter extends RouteBuilder {
from("direct:getFromFedora")
.routeId("FetchFromRepository")
.to("fcrepo:{{fcrepo.baseUrl}}?accept=application/ld+json&throwExceptionOnFailure=false")
.removeHeaders("CamelHttp*")
.setHeader(HTTP_URI).simple("{{ldpath.serviceUrl}}")
.setHeader(HTTP_QUERY).simple("context={{fcrepo.baseUrl}}${headers[CamelFcrepoIdentifier]}")
.setHeader(HTTP_METHOD).constant("GET")
.to("http4://localhost")
.filter(header(HTTP_RESPONSE_CODE).isEqualTo(200))
.to("direct:compact")
.to("direct:template");
from("direct:template")
.routeId("TemplateRoute")
.setHeader(CONTENT_TYPE).simple("{{mustache.contentType}}")
.unmarshal().json(JsonLibrary.Jackson, Map.class)
.unmarshal().json(Jackson, List.class)
.setBody(simple("${body[0]}"))
.choice()
.when(header("templateUri").isNull())
.to("direct:defaultTemplate")
......
......@@ -14,31 +14,19 @@
<cm:property name="rest.host" value="localhost"/>
<cm:property name="rest.port" value="9103"/>
<cm:property name="rest.prefix" value="/template"/>
<cm:property name="fcrepo.baseUrl" value="localhost:8080/fcrepo/rest"/>
<cm:property name="fcrepo.baseUrl" value="http://localhost:8080/fcrepo/rest"/>
<cm:property name="mustache.templateUri" value="edu/amherst/acdc/exts/template/template.mustache"/>
<cm:property name="mustache.contentType" value="text/html"/>
<cm:property name="jsonld.context" value="https://acdc.amherst.edu/jsonld/models.json"/>
<cm:property name="ldpath.serviceUrl" value="http://localhost:9086/ldpath"/>
<cm:property name="extension.load" value="true" />
<cm:property name="extension.load.uri" value="http://apix/services//apix:load" />
<cm:property name="extension.load.maximumRediveries" value="60" />
</cm:default-properties>
</cm:property-placeholder>
<reference id="jsonldService" interface="edu.amherst.acdc.services.jsonld.JsonLdService" filter="(osgi.jndi.service.name=acrepo/JsonLD)" />
<camelContext id="AcrepoTemplateService" xmlns="http://camel.apache.org/schema/blueprint" streamCache="false">
<package>edu.amherst.acdc.exts.template</package>
<route id="JsonLdCompaction">
<from uri="direct:compact"/>
<setHeader headerName="JsonLdContext">
<simple>{{jsonld.context}}</simple>
</setHeader>
<setBody>
<method ref="jsonldService" method="compact(${body}, ${header[JsonLdContext]})"/>
</setBody>
</route>
<!-- Self-register the loader service as an extension -->
<route id="load-extension">
<from uri="timer:register?repeatCount=1" />
......
<!DOCTYPE html>
<html lang="en" prefix="og: http://ogp.me/ns#">
<head>
<title>{{body.title}}</title>
{{#body.title}}
<title>{{.}}</title>
{{/body.title}}
</head>
<body>
<h1>Fedora Template Service: {{body.title}}</h1>
<p>{{body.description}}</p>
{{#body.title}}
<h1>Fedora Template Service: {{.}}</h1>
{{/body.title}}
{{#body.description}}
<p>{{.}}</p>
{{/body.description}}
</body>
</html>
......@@ -15,19 +15,17 @@
*/
package edu.amherst.acdc.exts.template;
import java.util.Dictionary;
import java.util.Map;
import edu.amherst.acdc.services.jsonld.JsonLdService;
import edu.amherst.acdc.services.jsonld.JsonLdServiceImpl;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.Properties;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.apache.camel.util.KeyValueHolder;
import org.junit.Test;
......@@ -58,9 +56,15 @@ public class RouteTest extends CamelBlueprintTestSupport {
}
@Override
protected void addServicesOnStartup(final Map<String, KeyValueHolder<Object, Dictionary>> services) {
services.put(JsonLdService.class.getName(), asService(new JsonLdServiceImpl(),
"osgi.jndi.service.name", "acrepo/JsonLD"));
protected Properties useOverridePropertiesWithPropertiesComponent() {
final Properties props = new Properties();
try {
final ServerSocket s = new ServerSocket(0);
props.put("rest.port", Integer.toString(s.getLocalPort()));
} catch (final IOException ex) {
throw new RuntimeCamelException(ex);
}
return props;
}
@Test
......@@ -80,7 +84,7 @@ public class RouteTest extends CamelBlueprintTestSupport {
resultEndpoint.allMessages().body().contains("Fedora Template Service: Foo");
resultEndpoint.allMessages().body().contains("<p>sample description</p>");
template.sendBody("{\"title\" : \"Foo\", \"description\" : \"sample description\"}");
template.sendBody("[{\"title\" : [\"Foo\"], \"description\" : [\"sample description\"]}]");
// assert expectations
assertMockEndpointsSatisfied();
......@@ -105,7 +109,7 @@ public class RouteTest extends CamelBlueprintTestSupport {
resultEndpoint.allMessages().body().contains("<p>sample description</p>");
template.sendBodyAndHeader(
"{\"title\" : \"Foo\", \"description\" : \"sample description\", \"date\" : \"Sometime 2016\"}",
"[{\"title\" : [\"Foo\"], \"description\" : [\"sample description\"], \"date\" : [\"Sometime 2016\"]}]",
"templateUri", "/edu/amherst/acdc/exts/template/template2.mustache");
// assert expectations
......
<!DOCTYPE html>
<html lang="en" prefix="og: http://ogp.me/ns#">
<head>
<title>{{body.title}}</title>
{{#body.title}}
<title>{{.}}</title>
{{/body.title}}
</head>
<body>
<h1>Fedora Template Service: {{body.title}}</h1>
<h2>Custom Template: {{body.date}}</h2>
<p>{{body.description}}</p>
{{#body.title}}
<h1>Fedora Template Service: {{.}}</h1>
{{/body.title}}
{{#body.date}}
<h2>Custom Template: {{.}}</h2>
{{/body.date}}
{{#body.description}}
<p>{{.}}</p>
{{/body.description}}
</body>
</html>
......@@ -59,7 +59,8 @@ public class AcrepoTemplateIT extends AbstractOSGiIT {
final String templateServicePort = cm.getProperty("karaf.template.port");
final String rmiRegistryPort = cm.getProperty("karaf.rmiRegistry.port");
final String rmiServerPort = cm.getProperty("karaf.rmiServer.port");
final String fcrepoBaseUrl = "localhost:" + fcrepoPort + "/fcrepo/rest";
final String fcrepoBaseUrl = "http://localhost:" + fcrepoPort + "/fcrepo/rest";
final String ldpathPort = cm.getProperty("karaf.ldpath.port");
final String sshPort = cm.getProperty("karaf.ssh.port");
return new Option[] {
......@@ -77,9 +78,11 @@ public class AcrepoTemplateIT extends AbstractOSGiIT {
.type("xml").classifier("features").versionAsInProject()),
features(maven().groupId("org.fcrepo.camel").artifactId("fcrepo-camel")
.type("xml").classifier("features").versionAsInProject()),
features(maven().groupId("org.fcrepo.camel").artifactId("toolbox-features")
.type("xml").classifier("features").versionAsInProject()),
features(maven().groupId("edu.amherst.acdc").artifactId("acrepo-karaf")
.type("xml").classifier("features").versionAsInProject(),
"acrepo-exts-template", "acrepo-services-jsonld"),
"acrepo-exts-template", "acrepo-exts-ldpath"),
systemProperty("karaf.template.port").value(templateServicePort),
systemProperty("fcrepo.port").value(fcrepoPort),
......@@ -87,8 +90,11 @@ public class AcrepoTemplateIT extends AbstractOSGiIT {
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", rmiRegistryPort),
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", rmiServerPort),
editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", "sshPort", sshPort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.ldpath.cfg", "rest.port", ldpathPort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.template.cfg", "fcrepo.baseUrl", fcrepoBaseUrl),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.template.cfg", "rest.port", templateServicePort)
editConfigurationFilePut("etc/edu.amherst.acdc.exts.template.cfg", "rest.port", templateServicePort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.template.cfg", "ldpath.serviceUrl",
"http://localhost:" + ldpathPort + "/ldpath")
};
}
......@@ -97,15 +103,14 @@ public class AcrepoTemplateIT extends AbstractOSGiIT {
assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-core")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-camel")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-exts-template")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-services-jsonld")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-exts-ldpath")));
}
@Test
public void testJsonLdService() throws Exception {
public void testTemplateService() throws Exception {
// make sure that the camel context has started up.
final CamelContext ctx = getOsgiService(CamelContext.class, "(camel.context.name=AcrepoTemplateService)",
10000);
assertNotNull(ctx);
assertNotNull(getOsgiService(CamelContext.class, "(camel.context.name=AcrepoTemplateService)", 10000));
assertNotNull(getOsgiService(CamelContext.class, "(camel.context.name=AcrepoLDPathContext)", 10000));
final String baseUrl = "http://localhost:" + System.getProperty("fcrepo.port") + "/fcrepo/rest";
final String baseSvcUrl = "http://localhost:" + System.getProperty("karaf.template.port") + "/template";
......
......@@ -149,7 +149,7 @@
</feature>
<feature name="acrepo-exts-template" version="${project.version}">
<details>Installs a sample JSON-LD-based template rendering service</details>
<details>Installs a sample JSON-based template rendering service</details>
<feature version="${camelVersionRange}">camel</feature>
<feature version="${camelVersionRange}">camel-blueprint</feature>
......@@ -158,7 +158,6 @@
<feature version="${camelVersionRange}">camel-jackson</feature>
<feature version="${camelVersionRange}">camel-http4</feature>
<feature version="${fcrepoCamelVersionRange}">fcrepo-camel</feature>
<feature version="${project.version}">acrepo-services-jsonld</feature>
<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