Navigation Menu

Skip to content

Commit

Permalink
moved http-api to resteasy
Browse files Browse the repository at this point in the history
  • Loading branch information
fasseg committed Mar 20, 2013
1 parent 16eb6ad commit 1227758
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 102 deletions.
72 changes: 43 additions & 29 deletions fcrepo-http-api/pom.xml
Expand Up @@ -26,18 +26,6 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>enunciate-cxf-rt</artifactId>
<version>${enunciate.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- RESTEasy -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
Expand All @@ -61,6 +49,18 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-spring</artifactId>
<version>2.3.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>2.3.5.Final</version>
</dependency>


<!-- Apache Velocity -->
<dependency>
Expand Down Expand Up @@ -93,19 +93,6 @@
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down Expand Up @@ -139,14 +126,41 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>maven-enunciate-cxf-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<contextPath>/</contextPath>
<stopPort>8005</stopPort>
<stopKey>STOP</stopKey>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<daemon>true</daemon>
<webAppSourceDirectory>${basedir}/src/test/resources</webAppSourceDirectory>
<useTestClasspath>true</useTestClasspath>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
53 changes: 26 additions & 27 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraDatastreams.java
Expand Up @@ -25,10 +25,11 @@
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;

import javax.inject.Inject;
import javax.inject.Named;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
Expand All @@ -52,8 +53,7 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
import org.apache.commons.io.IOUtils;
import org.fcrepo.AbstractResource;
import org.fcrepo.Datastream;
import org.fcrepo.exception.InvalidChecksumException;
Expand All @@ -65,13 +65,17 @@
import org.fcrepo.services.DatastreamService;
import org.fcrepo.services.LowLevelStorageService;
import org.fcrepo.utils.FixityResult;
import org.jboss.resteasy.plugins.providers.multipart.InputPart;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.modeshape.jcr.api.Binary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.ImmutableSet.Builder;

@Path("/objects/{pid}/datastreams")
@Named
@Path("/rest/objects/{pid}/datastreams")
public class FedoraDatastreams extends AbstractResource {

final private Logger logger = LoggerFactory
Expand Down Expand Up @@ -113,30 +117,26 @@ public ObjectDatastreams getDatastreams(@PathParam("pid")

@POST
@Path("/")
public Response modifyDatastreams(@PathParam("pid")
final String pid, @QueryParam("delete")
final List<String> dsidList, final List<Attachment> attachmentList)
throws RepositoryException, IOException, InvalidChecksumException {
public Response modifyDatastreams(@PathParam("pid") final String pid, @QueryParam("delete") final List<String> dsidList, final MultipartFormDataInput multipart)
throws RepositoryException, IOException, InvalidChecksumException {

final Session session = repo.login();
InputStream src = null;
try {
Long oldObjectSize =
getObjectSize(session.getNode(getObjectJcrNodePath(pid)));
long oldObjectSize = getObjectSize(session.getNode(getObjectJcrNodePath(pid)));

for (String dsid : dsidList) {
logger.debug("purging datastream " + dsid);
purgeDatastream(session, pid, dsid);
}

for (final Attachment a : attachmentList) {
final String dsid =
a.getContentDisposition().getParameter("name");
logger.debug("adding datastream " + dsid);
final String dsPath = getDatastreamJcrNodePath(pid, dsid);
createDatastreamNode(session, dsPath, a.getDataHandler()
.getContentType(), a.getDataHandler().getInputStream());
for (Entry<String,List<InputPart>> parts : multipart.getFormDataMap().entrySet()){
final String dsid = parts.getKey();
final String dsPath = getDatastreamJcrNodePath(pid, dsid);
src = parts.getValue().get(0).getBody(InputStream.class,null);
createDatastreamNode(session, dsPath, parts.getValue().get(0).getMediaType().toString(), src);
}

}
session.save();

/*
Expand All @@ -150,9 +150,9 @@ public Response modifyDatastreams(@PathParam("pid")
// now we save again to persist the repo size
session.save();
} finally {
session.logout();
IOUtils.closeQuietly(src);
session.logout();
}

return created(uriInfo.getAbsolutePath()).build();
}

Expand All @@ -178,7 +178,7 @@ public Response deleteDatastreams(@PathParam("pid")
@GET
@Path("/__content__")
@Produces("multipart/mixed")
public MultipartBody getDatastreamsContents(@PathParam("pid")
public MultipartOutput getDatastreamsContents(@PathParam("pid")
final String pid, @QueryParam("dsid")
List<String> dsids) throws RepositoryException, IOException {

Expand All @@ -191,17 +191,16 @@ public MultipartBody getDatastreamsContents(@PathParam("pid")
}
}

List<Attachment> atts = new LinkedList<Attachment>();
MultipartOutput multipart = new MultipartOutput();

try {
Iterator<String> i = dsids.iterator();
while (i.hasNext()) {
final String dsid = i.next();

try {
final Datastream ds =
DatastreamService.getDatastream(pid, dsid);
atts.add(new Attachment(ds.getNode().getName(), ds
.getMimeType(), ds.getContent()));
final Datastream ds = DatastreamService.getDatastream(pid, dsid);
multipart.addPart(ds.getContent(), MediaType.valueOf(ds.getMimeType()));
} catch (PathNotFoundException e) {

}
Expand All @@ -210,7 +209,7 @@ public MultipartBody getDatastreamsContents(@PathParam("pid")
session.logout();
}

return new MultipartBody(atts, true);
return multipart;
}

/**
Expand Down
Expand Up @@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.inject.Named;
import javax.jcr.LoginException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
Expand All @@ -31,8 +32,8 @@
/**
* @author Vincent Nguyen
*/

@Path("/search")
@Named
@Path("/rest/search")
public class FedoraFieldSearch extends AbstractResource {
private static final Logger logger = LoggerFactory
.getLogger(FedoraFieldSearch.class);
Expand Down
Expand Up @@ -8,6 +8,7 @@
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.TEXT_XML;

import javax.inject.Named;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand All @@ -25,7 +26,8 @@
* @author ajs6f
*
*/
@Path("nextPID")
@Named
@Path("/rest/nextPID")
public class FedoraIdentifiers extends AbstractResource {

/**
Expand Down
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.net.URI;

import javax.inject.Named;
import javax.jcr.NamespaceRegistry;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
Expand Down Expand Up @@ -37,7 +38,8 @@
* @author ajs6f
*
*/
@Path("/namespaces")
@Named
@Path("/rest/namespaces")
public class FedoraNamespaces extends AbstractResource {

/**
Expand Down
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;

import javax.inject.Named;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
Expand All @@ -41,7 +42,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Path("/objects")
@Named
@Path("/rest/objects")
public class FedoraObjects extends AbstractResource {

private static final Logger logger = LoggerFactory
Expand Down
Expand Up @@ -11,6 +11,7 @@

import java.io.IOException;

import javax.inject.Named;
import javax.jcr.LoginException;
import javax.jcr.NamespaceRegistry;
import javax.jcr.Repository;
Expand Down Expand Up @@ -40,7 +41,8 @@
* @author ajs6f
*/

@Path("/describe")
@Named
@Path("/rest/describe")
public class FedoraRepository extends AbstractResource {

private static final Logger logger = LoggerFactory
Expand Down
Expand Up @@ -21,8 +21,6 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/spring-test/master.xml")
public abstract class AbstractResourceIT {

protected Logger logger;
Expand Down
5 changes: 5 additions & 0 deletions fcrepo-http-api/src/test/resources/WEB-INF/web.xml
Expand Up @@ -2,6 +2,11 @@
<web-app>
<display-name>Archetype Created Web Application</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-test/master.xml</param-value>
</context-param>

<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
Expand Down

0 comments on commit 1227758

Please sign in to comment.