Commit 63fecef4 authored by acoburn's avatar acoburn
Browse files

update interface to the FITS service

parent 9f640725
Repository FITS Service
===================================
This service will return the FITS information associated with a Fedora Binary, in
This service will return the FITS information associated with an LDP NonRDFSource, in
XML format. The service can be used with any Camel route in an OSGi container.
The service is invoked like so:
curl http://localhost:9601/fits?context=http://localhost:8080/fcrepo/rest/image
The appropriate Fedora resource is identified with either the `context` query option
or the `Apix-Ldp-Resource-Path` header.
Building
--------
......@@ -25,12 +32,12 @@ command from its shell:
Configuration
-------------
The application can be configured by creating the following configuration
file `KARAF_HOME/etc/edu.amherst.acdc.exts.fits.cfg`. The following values
file `KARAF_HOME/etc/edu.amherst.acdc.exts.fits.cfg`. The following values
are available for configuration:
The base URL of the Fedora repository and any authentication parameters
fcrepo.baseUrl=localhost:8080/fcrepo/rest
fcrepo.baseUrl=http://localhost:8080/fcrepo/rest
fcrepo.authHost=
fcrepo.authUsername=
fcrepo.password=
......@@ -49,7 +56,7 @@ The hostname on which the service is available
The endpoint on which the FITS server is located
fits.endpoint=localhost:8080/fits
fits.endpoint=http://localhost:8080/fits
By editing this file, any currently running routes will be immediately redeployed
with the new values.
......
# Fedora Repository location
fcrepo.baseUrl=localhost:8080/fcrepo/rest
fcrepo.baseUrl=http://localhost:8080/fcrepo/rest
fcrepo.authHost=
fcrepo.authUsername=
......@@ -10,7 +10,7 @@ rest.port=9106
rest.host=localhost
# The endpoint for the FITS server
fits.endpoint=localhost:8080/fits/examine
fits.endpoint=http://localhost:8080/fits/examine
# API-X configuration
extension.load=true
......
......@@ -19,8 +19,8 @@ import static org.apache.camel.Exchange.CONTENT_TYPE;
import static org.apache.camel.Exchange.HTTP_METHOD;
import static org.apache.camel.Exchange.HTTP_RESPONSE_CODE;
import static org.apache.camel.Exchange.HTTP_URI;
import static org.apache.camel.Exchange.HTTP_PATH;
import static org.apache.camel.LoggingLevel.INFO;
import static org.apache.camel.builder.PredicateBuilder.and;
import static org.apache.http.entity.mime.MultipartEntityBuilder.create;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -37,7 +37,9 @@ import org.slf4j.Logger;
*/
public class FitsRouter extends RouteBuilder {
private static final String FEDORA_PATH = "CamelFedoraPath";
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(FitsRouter.class);
......@@ -47,16 +49,17 @@ public class FitsRouter extends RouteBuilder {
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("AcrepoFitsRest")
.routeDescription(
"FITS service to gather technical information about a binary located in a Fedora repository.")
.process(e -> e.getIn().setHeader(FEDORA_PATH,
e.getIn().getHeader("Apix-Ldp-Resource-Path",
e.getIn().getHeader(HTTP_PATH))))
.log(INFO, LOGGER, "Received request for Fits data for: ${headers[CamelHttpPath]}")
.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}}")
.log(INFO, LOGGER, "Received request for Fits data for: ${headers[CamelFedoraUri]}")
.choice()
.when(header(HTTP_METHOD).isEqualTo("GET"))
.when(and(header(HTTP_METHOD).isEqualTo("GET"), header(FEDORA_URI).startsWith(header(FEDORA_BASE_URL))))
.to("direct:fitsService")
.when(header(HTTP_METHOD).isEqualTo("OPTIONS"))
.setHeader(CONTENT_TYPE).constant("text/turtle")
......@@ -65,11 +68,10 @@ public class FitsRouter extends RouteBuilder {
from("direct:fitsService")
.routeId("AcrepoFitsFedoraLookup")
.log(INFO, LOGGER, "FitsFedoraLookup - fetching ${headers[CamelHttpPath]}")
.log(INFO, LOGGER, "FitsFedoraLookup - fetching ${headers[CamelFedoraUri]}")
.setHeader(HTTP_METHOD).constant("HEAD")
.setHeader(HTTP_URI).simple("http://{{fcrepo.baseUrl}}")
.setHeader(HTTP_PATH, header(FEDORA_PATH))
.to("http4://{{fcrepo.baseUrl}}?authUsername={{fcrepo.authUsername}}" +
.setHeader(HTTP_URI).header(FEDORA_URI)
.to("http4://localhost?authUsername={{fcrepo.authUsername}}" +
"&authPassword={{fcrepo.authPassword}}&throwExceptionOnFailure=false")
.choice()
.when(header("Link").contains("<http://www.w3.org/ns/ldp#NonRDFSource>;rel=\"type\""))
......@@ -77,7 +79,7 @@ public class FitsRouter extends RouteBuilder {
.when(header(HTTP_RESPONSE_CODE).isEqualTo(200))
.removeHeaders("*")
.log(INFO, LOGGER, "Object is not a binary resource, sending 4xx")
.setBody(constant("Error: this resource is not a fedora:Binary"))
.setBody(constant("Error: this resource is not a ldp:NonRDFSource"))
.setHeader(CONTENT_TYPE).constant("text/plain")
.setHeader(HTTP_RESPONSE_CODE).constant(400);
......@@ -86,8 +88,8 @@ public class FitsRouter extends RouteBuilder {
.log(INFO, LOGGER, "Object is invoking Fits Service")
.removeHeaders("CamelHttp*")
.setHeader(HTTP_METHOD).constant("GET")
.setHeader(HTTP_PATH).header(FEDORA_PATH)
.to("http4://{{fcrepo.baseUrl}}?authUsername={{fcrepo.authUsername}}" +
.setHeader(HTTP_URI).header(FEDORA_URI)
.to("http4://localhost?authUsername={{fcrepo.authUsername}}" +
"&authPassword={{fcrepo.authPassword}}&throwExceptionOnFailure=false")
.removeHeaders("CamelHttp*")
.process(exchange -> {
......@@ -97,6 +99,7 @@ public class FitsRouter extends RouteBuilder {
})
.setHeader(CONTENT_TYPE).constant("multipart/form-data")
.setHeader(HTTP_METHOD).constant("POST")
.to("http4://{{fits.endpoint}}");
.setHeader(HTTP_URI).simple("{{fits.endpoint}}")
.to("http4://localhost");
}
}
......@@ -9,14 +9,14 @@
<!-- OSGi blueprint property placeholder -->
<cm:property-placeholder id="properties" persistent-id="edu.amherst.acdc.exts.fits" update-strategy="reload">
<cm:default-properties>
<cm:property name="fcrepo.baseUrl" value="localhost:8080/fcrepo/rest"/>
<cm:property name="fcrepo.baseUrl" value="http://localhost:8080/fcrepo/rest"/>
<cm:property name="fcrepo.authHost" value=""/>
<cm:property name="fcrepo.authUsername" value=""/>
<cm:property name="fcrepo.authPassword" value=""/>
<cm:property name="rest.prefix" value="/fits"/>
<cm:property name="rest.host" value="localhost"/>
<cm:property name="rest.port" value="9106"/>
<cm:property name="fits.endpoint" value="localhost:8080/fits/examine"/>
<cm:property name="fits.endpoint" value="http://localhost:8080/fits/examine"/>
<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" />
......
@prefix apix:<http://fedora.info/definitions/v4/api-extension#> .
@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 ldp: <http://www.w3.org/ns/ldp#> .
@prefix registry: <http://acdc.amherst.edu/ns/extensions#> .
<> a apix:Extension;
apix:exposesService registry:fits;
apix:exposesServiceAt "svc:fits";
apix:bindsTo fedora:Binary .
\ No newline at end of file
apix:bindsTo ldp:NonRDFSource .
......@@ -60,7 +60,7 @@ public class AcrepoFitsIT extends AbstractOSGiIT {
final String fitsServicePort = cm.getProperty("karaf.fits.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 sshPort = cm.getProperty("karaf.ssh.port");
return new Option[] {
......@@ -111,7 +111,7 @@ public class AcrepoFitsIT extends AbstractOSGiIT {
final String baseUrl = "http://localhost:" + System.getProperty("fcrepo.port") + "/fcrepo/rest";
final String baseSvcUrl = "http://localhost:" + System.getProperty("karaf.fits.port") + "/fits";
assertTrue(options(baseSvcUrl).contains("owl:equivalentClass fedora:Binary"));
assertTrue(options(baseSvcUrl).contains("apix:bindsTo ldp:NonRDFSource"));
range(1, 2).mapToObj(x -> post(baseUrl, getClass().getResourceAsStream("/fitsfile" + x + ".jpg"), "image/jpeg"))
.forEach(url -> {
......
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