Commit 3ea021a4 authored by acoburn's avatar acoburn
Browse files

change interface for serialization service

parent e8506ef8
......@@ -6,13 +6,13 @@ to either a DC/XML or MODS/XML serialization. This translation relies on
pluggable XSLT 2.0 documents.
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`:
in order to retrieve a MODS version of the resource `http://localhost:8080/fcrepo/rest/a/b/c`:
curl localhost:9104/mods/a/b/c
curl localhost:9104/xml?format=mods&context=http://localhost:8080/fcrepo/rest/a/b/c
And the DC version:
curl localhost:9104/dc/a/b/c
curl localhost:9104/xml?format=dc&context=http://localhost:8080/fcrepo/rest/a/b/c
Building
--------
......@@ -50,6 +50,10 @@ be loaded from the classpath.
dc.xslt=edu/amherst/acdc/xml/metadata/rdf2dc.xsl
The prefix of the service
rest.prefix=/xml
The port on which the service is available
rest.port=9104
......
......@@ -23,7 +23,7 @@ jar {
vendor project.vendor
license project.license
instruction 'Import-Package', "org.apache.camel,${defaultOsgiImports}"
instruction 'Import-Package', "org.apache.camel,org.fcrepo.camel,${defaultOsgiImports}"
instruction 'Export-Package', "edu.amherst.acdc.exts.serialize.xml;version=${projectOsgiVersion}"
}
}
......
# The port on which the service is made available
rest.port=9104
rest.host=localhost
rest.prefix=/xml
# The fedora baseUrl
fcrepo.baseUrl=http://localhost:8080/fcrepo/rest
fcrepo.authUsername=
fcrepo.authPassword=
# The location of the XSLT to convert RDF/XML to MODS/XML and DC/XML
mods.xslt=edu/amherst/acdc/exts/serialize/xml/rdf2mods.xsl
......
......@@ -15,12 +15,12 @@
*/
package edu.amherst.acdc.exts.serialize.xml;
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_RESPONSE_CODE;
import static org.apache.camel.Exchange.CONTENT_TYPE;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_IDENTIFIER;
import static org.apache.camel.builder.PredicateBuilder.and;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_BASE_URL;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_URI;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
......@@ -30,20 +30,27 @@ import org.apache.camel.builder.RouteBuilder;
*/
public class EventRouter extends RouteBuilder {
private static final String HTTP_QUERY_CONTEXT = "context";
private static final String FORMAT = "format";
/**
* Configure the message route workflow.
*/
public void configure() throws Exception {
from("jetty:http://{{rest.host}}:{{rest.port}}{{rest.prefix}}?" +
"matchOnUriPrefix=true&httpMethodRestrict=GET,OPTIONS&sendServerVersion=false")
"httpMethodRestrict=GET,OPTIONS&sendServerVersion=false")
.routeId("XmlAccept")
.process(e -> e.getIn().setHeader(FCREPO_URI,
e.getIn().getHeader(HTTP_QUERY_CONTEXT,
e.getIn().getHeader("Apix-Ldp-Resource"))))
.setHeader(FCREPO_BASE_URL).simple("{{fcrepo.baseUrl}}")
.choice()
.when(header(HTTP_METHOD).isEqualTo("OPTIONS"))
.to("direct:options")
.when(header(HTTP_PATH).contains("dc"))
.when(and(header(FORMAT).isEqualTo("dc"), header(FCREPO_URI).startsWith(header(FCREPO_BASE_URL))))
.to("direct:dc")
.when(header(HTTP_PATH).contains("mods"))
.when(header(FORMAT).isEqualTo("mods"))
.to("direct:mods")
.otherwise()
.to("direct:choice");
......@@ -54,7 +61,7 @@ public class EventRouter extends RouteBuilder {
.filter(header(HTTP_RESPONSE_CODE).isEqualTo(200))
.setHeader(CONTENT_TYPE).constant("application/xml")
.convertBodyTo(org.w3c.dom.Document.class)
.log(LoggingLevel.INFO, "Converting resource to DC/XML: ${headers[CamelFcrepoIdentifier]}")
.log(LoggingLevel.INFO, "Converting resource to DC/XML: ${headers[CamelFcrepoUri]}")
.to("xslt:{{dc.xslt}}?saxon=true");
from("direct:mods")
......@@ -63,7 +70,7 @@ public class EventRouter extends RouteBuilder {
.filter(header(HTTP_RESPONSE_CODE).isEqualTo(200))
.setHeader(CONTENT_TYPE).constant("application/xml")
.convertBodyTo(org.w3c.dom.Document.class)
.log(LoggingLevel.INFO, "Converting resource to MODS/XML: ${headers[CamelFcrepoIdentifier]}")
.log(LoggingLevel.INFO, "Converting resource to MODS/XML: ${headers[CamelFcrepoUri]}")
.to("xslt:{{mods.xslt}}?saxon=true");
from("direct:options")
......@@ -83,12 +90,6 @@ public class EventRouter extends RouteBuilder {
.removeHeader("breadcrumbId")
.removeHeader("Accept")
.removeHeader("User-Agent")
.process(e -> e.getIn().setHeader(FCREPO_IDENTIFIER,
e.getIn().getHeader("Apix-Ldp-Resource-Path",
e.getIn().getHeader(HTTP_PATH, "", String.class).replaceFirst("^/.+?/", "/"))))
.setHeader(FCREPO_BASE_URL).simple("{{fcrepo.baseUrl}}")
.to("fcrepo:{{fcrepo.baseUrl}}?throwExceptionOnFailure=false");
.to("fcrepo:localhost?throwExceptionOnFailure=false");
}
}
......@@ -16,15 +16,23 @@
<cm:property name="mods.xslt" value="edu/amherst/acdc/exts/serialize/xml/rdf2mods.xsl"/>
<cm:property name="dc.xslt" value="edu/amherst/acdc/exts/serialize/xml/rdf2dc.xsl"/>
<cm:property name="fcrepo.baseUrl" value="http://localhost:8080/fcrepo/rest"/>
<cm:property name="fcrepo.authUsername" value=""/>
<cm:property name="fcrepo.authPassword" value=""/>
<cm:property name="extension.load" value="true" />
<cm:property name="extension.load.uri" value="http://apix/services//apix:load" />
<cm:property name="extension.load.maximumRedeliveries" value="60" />
</cm:default-properties>
</cm:property-placeholder>
<bean id="fcrepo" class="org.fcrepo.camel.FcrepoComponent">
<property name="authUsername" value="${fcrepo.authUsername}"/>
<property name="authPassword" value="${fcrepo.authPassword}"/>
<property name="baseUrl" value="${fcrepo.baseUrl}"/>
</bean>
<camelContext id="AcrepoExtsSerializeXml" xmlns="http://camel.apache.org/schema/blueprint">
<package>edu.amherst.acdc.exts.serialize.xml</package>
<!-- Self-register the loader service as an extension -->
<route id="load-extension">
<from uri="timer:register?repeatCount=1" />
......
......@@ -12,8 +12,7 @@
version="2.0">
<xsl:output indent="yes" method="xml"/>
<xsl:strip-space elements="dc:*"/>
<xsl:param name="CamelFcrepoIdentifier"/>
<xsl:param name="CamelFcrepoBaseUrl"/>
<xsl:param name="CamelFcrepoUri"/>
<xsl:template name="getValue">
<xsl:choose>
......@@ -102,7 +101,7 @@
</xsl:template>
<xsl:template match="rdf:Description">
<xsl:if test="ends-with(@rdf:about, concat($CamelFcrepoBaseUrl, $CamelFcrepoIdentifier))">
<xsl:if test="ends-with(@rdf:about, $CamelFcrepoUri)">
<xsl:apply-templates select="node()|@*"/>
</xsl:if>
</xsl:template>
......
......@@ -9,11 +9,10 @@
exclude-result-prefixes="xs rdf rdfs dc dcterms"
version="2.0">
<xsl:output indent="yes" method="xml"></xsl:output>
<xsl:param name="CamelFcrepoIdentifier"/>
<xsl:param name="CamelFcrepoBaseUrl"/>
<xsl:param name="CamelFcrepoUri"/>
<xsl:template match="/rdf:RDF/rdf:Description">
<xsl:if test="ends-with(@rdf:about, concat($CamelFcrepoBaseUrl, $CamelFcrepoIdentifier))">
<xsl:if test="ends-with(@rdf:about, $CamelFcrepoUri)">
<mods:mods>
<xsl:for-each select="dc:title">
<mods:titleInfo>
......
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#> .
@prefix fedora: <http://fedora.info/definitions/v4/repository#> .
@prefix registry: <http://acdc.amherst.edu/extensions#> .
@prefix apix:<http://fedora.info/definitions/v4/api-extension#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ldp: <http://www.w3.org/ns/ldp#> .
@prefix registry: <http://acdc.amherst.edu/ns/extensions#> .
@prefix apix: <http://fedora.info/definitions/v4/api-extension#> .
<> a apix:Extension ;
rdfs:label "XML Metadata Service" ;
rdfs:comment "A service that transforms RDFSource documents to plain XML (not RDF/XML)" ;
apix:exposesService registry:XmlMetadataService ;
apix:exposesServiceAt "svc:xmlmetadata/" ;
apix:bindsTo fedora:Resource .
apix:bindsTo ldp:Resource .
......@@ -129,7 +129,7 @@ public class RouteTest extends CamelBlueprintTestSupport {
final Map<String, Object> headers = new HashMap<>();
headers.put(HTTP_RESPONSE_CODE, 200);
headers.put("Apix-Ldp-Resource-Path", "/acdc/manuscript");
headers.put("Apix-Ldp-Resource", "http://localhost:8080/fcrepo/rest/acdc/manuscript");
template.sendBodyAndHeaders("direct:start", loadResourceAsStream("resource.rdf"), headers);
assertMockEndpointsSatisfied();
......
......@@ -118,12 +118,12 @@ public class AcrepoExtsSerializeXmlIT extends AbstractOSGiIT {
final String baseUrl = "http://localhost:" + System.getProperty("fcrepo.port") + "/fcrepo/rest";
final String baseSvcUrl = "http://localhost:" + System.getProperty("karaf.metadata.port") + "/xml";
assertTrue(options(baseSvcUrl).contains("apix:bindsTo fedora:Resource"));
assertTrue(options(baseSvcUrl).contains("apix:bindsTo ldp:Resource"));
final String id = post(baseUrl, getClass().getResourceAsStream("/resource.ttl"), "text/turtle")
.replace(baseUrl, "");
final String id = post(baseUrl, getClass().getResourceAsStream("/resource.ttl"), "text/turtle");
final InputStream input = new ByteArrayInputStream(get(baseSvcUrl + "/dc" + id).getBytes("UTF-8"));
final InputStream input = new ByteArrayInputStream(get(baseSvcUrl + "?format=dc&context=" + id)
.getBytes("UTF-8"));
final Document doc = newInstance().newDocumentBuilder().parse(input);
final NodeList root = doc.getChildNodes();
......
......@@ -87,7 +87,8 @@ public class AcrepoFitsIT extends AbstractOSGiIT {
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", rmiServerPort),
editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", "sshPort", sshPort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.fits.cfg", "fcrepo.baseUrl", fcrepoBaseUrl),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.fits.cfg", "rest.port", fitsServicePort)
editConfigurationFilePut("etc/edu.amherst.acdc.exts.fits.cfg", "rest.port", fitsServicePort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.fits.cfg", "extension.load", "false")
};
}
......
......@@ -94,7 +94,8 @@ public class AcrepoPcdmIT extends AbstractOSGiIT {
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", rmiServerPort),
editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", "sshPort", sshPort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.pcdm.cfg", "fcrepo.baseUrl", fcrepoBaseUrl),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.pcdm.cfg", "rest.port", pcdmExtPort)
editConfigurationFilePut("etc/edu.amherst.acdc.exts.pcdm.cfg", "rest.port", pcdmExtPort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.pcdm.cfg", "extension.load", "false")
};
}
......
......@@ -104,11 +104,17 @@ public class AcrepoServicesIT extends AbstractOSGiIT {
"acrepo-services-pcdm"),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.fits.cfg", "rest.port", fitsPort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.fits.cfg", "extension.load", "false"),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.image.cfg", "rest.port", imagePort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.image.cfg", "extension.load", "false"),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.ldpath.cfg", "rest.port", ldpathPort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.ldpath.cfg", "extension.load", "false"),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.pcdm.cfg", "rest.port", pcdmPort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.pcdm.cfg", "extension.load", "false"),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.serialize.xml.cfg", "rest.port", metadataPort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.serialize.cfg", "extension.load", "false"),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.template.cfg", "rest.port", templatePort),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.template.cfg", "extension.load", "false"),
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)
......
......@@ -90,6 +90,8 @@ public class AcrepoTemplateIT extends AbstractOSGiIT {
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.ldpath.cfg", "extension.load", "false"),
editConfigurationFilePut("etc/edu.amherst.acdc.exts.template.cfg", "extension.load", "false"),
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", "ldpath.serviceUrl",
......
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