Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
manually adding RdfProvider until we figure out classpath scanning
  • Loading branch information
barmintor committed Nov 11, 2013
1 parent 6e883c8 commit 3d133a6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
Expand Up @@ -91,7 +91,6 @@
import org.fcrepo.http.commons.domain.MOVE;
import org.fcrepo.http.commons.domain.PATCH;
import org.fcrepo.http.commons.domain.COPY;
import org.fcrepo.http.commons.domain.RDFMediaType;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.rdf.GraphSubjects;
Expand Down Expand Up @@ -142,7 +141,6 @@ public Dataset describe(@PathParam("path") final List<PathSegment> pathList,
@Context final UriInfo uriInfo) throws RepositoryException, IOException {
final String path = toPath(pathList);
logger.trace("Getting profile for {}", path);
logger.debug("Getting profile for {} of type {}", path, request.selectVariant(RDFMediaType.POSSIBLE_RDF_VARIANTS));

try {
final FedoraResource resource =
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.fcrepo.http.commons.domain.RDFMediaType;
import org.fcrepo.integration.http.api.AbstractResourceIT;
import org.junit.Test;

Expand All @@ -60,6 +61,7 @@ public void testGeneralHttpVersion() throws IOException {
@Test
public void testProvidesRDFRepresentation() throws IOException {
final HttpGet testMethod = new HttpGet(serverAddress + "");
testMethod.setHeader(HttpHeaders.ACCEPT, RDFMediaType.TURTLE);
final HttpResponse response = client.execute(testMethod);
assertEquals("text/turtle", response.getFirstHeader("Content-Type")
.getValue());
Expand All @@ -79,6 +81,7 @@ public void testProvidesRDFRepresentation() throws IOException {
@Test
public void testShouldHaveAtLeastOneRdfType() throws IOException {
final HttpGet testMethod = new HttpGet(serverAddress + "");
testMethod.setHeader(HttpHeaders.ACCEPT, RDFMediaType.TURTLE);
final HttpResponse response = client.execute(testMethod);
assertEquals("text/turtle", response.getFirstHeader("Content-Type")
.getValue());
Expand Down
Expand Up @@ -17,6 +17,7 @@

import javax.jcr.Session;

import org.fcrepo.http.commons.responses.RdfProvider;
import org.fcrepo.http.commons.session.AuthenticatedSessionProvider;
import org.fcrepo.kernel.services.TransactionService;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
Expand All @@ -36,6 +37,9 @@ public FedoraApplication() {
register(new FactoryBinder());
register(JacksonFeature.class);
register(MultiPartFeature.class);
//TODO this is a temporary hack to get tests to run
// until we know why classpath scanning from mvn isn't working
register(RdfProvider.class);
registerInstances(singletonTx);
}

Expand Down
Expand Up @@ -19,13 +19,25 @@
import static java.util.Collections.singletonList;
import static org.apache.jena.riot.WebContent.contentTypeToLang;
import static org.fcrepo.http.commons.responses.RdfSerializationUtils.setCachingHeaders;
/**
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.NTRIPLES;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_JSON;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_TEXT_RDF;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_APPLICATION;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_TEXT;
import static org.fcrepo.http.commons.domain.RDFMediaType.TRI_G;
import static org.fcrepo.http.commons.domain.RDFMediaType.NQUADS;
*/
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
Expand All @@ -42,6 +54,9 @@
* with cache headers.
*/
@Provider
@Produces(MediaType.WILDCARD)
//@Produces(value = {TURTLE, RDF_XML, NTRIPLES, RDF_JSON, N3_TEXT_RDF,
// N3_APPLICATION, N3_TEXT, TRI_G, NQUADS})
public class RdfProvider implements MessageBodyWriter<Dataset> {

private static final Logger logger = getLogger(RdfProvider.class);
Expand Down Expand Up @@ -72,12 +87,16 @@ public void writeTo(final Dataset rdf, final Class<?> type,
public boolean isWriteable(final Class<?> type, final Type genericType,
final Annotation[] annotations, final MediaType mediaType) {

logger.info("{} with mediaType {}", type.getName(), mediaType.toString());
// we can return a result for any MIME type that Jena can serialize
final Boolean appropriateMimeType =
mediaType == null ||
mediaType.equals(MediaType.WILDCARD_TYPE) ||
mediaType.equals(RDFMediaType.RDF_XML_TYPE) ||
contentTypeToLang(mediaType.toString()) != null;
if (!appropriateMimeType) {
logger.info("rejecting {} on grounds of appropriateness", mediaType);
}
return appropriateMimeType &&
(Dataset.class.isAssignableFrom(type) || Dataset.class
.isAssignableFrom(genericType.getClass()));
Expand Down
Expand Up @@ -24,11 +24,9 @@

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ws.rs.core.Application;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import org.fcrepo.http.FedoraApplication;
import org.fcrepo.http.commons.webxml.WebAppConfig;
import org.fcrepo.http.commons.webxml.bind.ContextParam;
import org.fcrepo.http.commons.webxml.bind.Filter;
Expand All @@ -41,9 +39,6 @@
import org.glassfish.grizzly.servlet.FilterRegistration;
import org.glassfish.grizzly.servlet.ServletRegistration;
import org.glassfish.grizzly.servlet.WebappContext;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ApplicationHandler;
import org.glassfish.jersey.server.ResourceConfig;
import org.slf4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -80,12 +75,10 @@ public void start() throws Exception {

final URI uri = URI.create("http://localhost:" + port);
// create a "root" web application
FedoraApplication application = new FedoraApplication();
appContext = new WebappContext(o.displayName(), "/");

for (final ContextParam p : o.contextParams()) {
appContext.addContextInitParameter(p.name(), p.value());
application.property(p.name(), p.value());
}

for (final Listener l : o.listeners()) {
Expand Down Expand Up @@ -127,8 +120,7 @@ public void start() throws Exception {
}
}

application.packages("org.fcrepo.kernel.services;org.fcrepo.http;org.fcrepo.http.commons.responses;org.fcrepo.http.api");
server = createHttpServer(uri, application);
server = createHttpServer(uri);

appContext.deploy(server);

Expand Down

0 comments on commit 3d133a6

Please sign in to comment.