Skip to content

Commit

Permalink
Added JSON returns to every method I could find for which they make s…
Browse files Browse the repository at this point in the history
…ense
  • Loading branch information
ajs6f committed Feb 5, 2013
1 parent 8578b27 commit b15fdf0
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 15 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -150,6 +150,11 @@
<artifactId>enunciate-cxf-rt</artifactId>
<version>${enunciate.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/fcrepo/modeshape/FedoraDatastreams.java
Expand Up @@ -252,7 +252,7 @@ private URI addDatastreamNode(final String dsPath,
*/
@GET
@Path("/{dsid}")
@Produces(TEXT_XML)
@Produces({ TEXT_XML, APPLICATION_JSON })
public Response getDatastream(@PathParam("pid") final String pid,
@PathParam("dsid") final String dsid) throws RepositoryException,
IOException {
Expand All @@ -267,7 +267,7 @@ public Response getDatastream(@PathParam("pid") final String pid,

if (obj.hasNode(dsid)) {
final Node ds = obj.getNode(dsid);
DatastreamProfile dsProfile = getDSProfile(ds);
final DatastreamProfile dsProfile = getDSProfile(ds);
session.logout();
return ok(dsProfile).build();
} else {
Expand Down Expand Up @@ -323,7 +323,7 @@ public Response getDatastreamContent(@PathParam("pid") final String pid,
*/
@GET
@Path("/{dsid}/versions")
@Produces(TEXT_XML)
@Produces({ TEXT_XML, APPLICATION_JSON })
// TODO implement this after deciding on a versioning model
public Response getDatastreamHistory(@PathParam("pid") final String pid,
@PathParam("dsid") final String dsid) throws RepositoryException,
Expand Down Expand Up @@ -390,7 +390,7 @@ public Response deleteDatastream(@PathParam("pid") String pid,

private DatastreamProfile getDSProfile(Node ds) throws RepositoryException,
IOException {
DatastreamProfile dsProfile = new DatastreamProfile();
final DatastreamProfile dsProfile = new DatastreamProfile();
dsProfile.dsID = ds.getName();
dsProfile.pid = ds.getParent().getName();
dsProfile.dsLabel = ds.getName();
Expand All @@ -402,7 +402,7 @@ private DatastreamProfile getDSProfile(Node ds) throws RepositoryException,

private String getDSMimeType(Node ds) throws ValueFormatException,
PathNotFoundException, RepositoryException, IOException {
Binary b = (Binary) ds.getNode(JCR_CONTENT).getProperty(JCR_DATA)
final Binary b = (Binary) ds.getNode(JCR_CONTENT).getProperty(JCR_DATA)
.getBinary();
return b.getMimeType();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/fcrepo/modeshape/FedoraIdentifiers.java
Expand Up @@ -4,6 +4,7 @@
import static com.google.common.collect.DiscreteDomains.integers;
import static com.google.common.collect.ImmutableSet.copyOf;
import static com.google.common.collect.Ranges.closed;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.TEXT_XML;

import java.io.IOException;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class FedoraIdentifiers extends AbstractResource {
* @throws TemplateException
*/
@POST
@Produces(TEXT_XML)
@Produces({ TEXT_XML, APPLICATION_JSON })
public NextPid getNextPid(
@QueryParam("numPids") @DefaultValue("1") Integer numPids)
throws RepositoryException, IOException {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/fcrepo/modeshape/FedoraNamespaces.java
Expand Up @@ -117,9 +117,9 @@ public Response getObjectNamespaces() throws RepositoryException {

@GET
@Path("")
@Produces(TEXT_XML)
public Response getObjectNamespacesInXML() throws RepositoryException,
IOException {
@Produces({ TEXT_XML, APPLICATION_JSON })
public NamespaceListing getObjectNamespacesInXML()
throws RepositoryException, IOException {

final Session session = repo.login();
final NamespaceRegistry r = session.getWorkspace()
Expand All @@ -129,7 +129,7 @@ public Response getObjectNamespacesInXML() throws RepositoryException,
b.add(new Namespace(prefix, URI.create(r.getURI(prefix))));
}
session.logout();
return ok(new NamespaceListing(b.build())).build();
return new NamespaceListing(b.build());
}

}
5 changes: 3 additions & 2 deletions src/main/java/org/fcrepo/modeshape/FedoraObjects.java
@@ -1,5 +1,6 @@
package org.fcrepo.modeshape;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.TEXT_XML;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.ok;
Expand Down Expand Up @@ -80,8 +81,8 @@ public Response ingest(@PathParam("pid") final String pid)

@GET
@Path("/{pid}")
@Produces(TEXT_XML)
public Response getObjectInXML(@PathParam("pid") final String pid)
@Produces({TEXT_XML, APPLICATION_JSON})
public Response getObject(@PathParam("pid") final String pid)
throws RepositoryException, IOException {

final Session session = repo.login();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/fcrepo/modeshape/FedoraRepository.java
@@ -1,5 +1,6 @@
package org.fcrepo.modeshape;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.TEXT_XML;
import static javax.ws.rs.core.Response.ok;

Expand Down Expand Up @@ -77,7 +78,7 @@ public Response describeModeshape() throws JsonGenerationException,

@GET
@Path("/describe")
@Produces(TEXT_XML)
@Produces({ TEXT_XML, APPLICATION_JSON })
public DescribeRepository describe() {
return new DescribeRepository();
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/logback.xml
Expand Up @@ -9,7 +9,10 @@
<logger name="org.fcrepo" additivity="false" level="DEBUG">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.modeshape" additivity="false" level="DEBUG">
<logger name="org.apache.cxf" additivity="false" level="INFO">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.modeshape" additivity="false" level="INFO">
<appender-ref ref="STDOUT"/>
</logger>
<root additivity="false" level="INFO">
Expand Down
22 changes: 21 additions & 1 deletion src/main/resources/spring/rest.xml
Expand Up @@ -3,10 +3,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml"/>
Expand All @@ -32,6 +34,24 @@
<bean class="org.fcrepo.modeshape.FedoraObjects"/>
<bean class="org.fcrepo.modeshape.foxml.FedoraOXML"/>
</jaxrs:serviceBeans>
<jaxrs:extensionMappings>
<entry key="json" value="application/json"/>
<entry key="xml" value="application/xml"/>
</jaxrs:extensionMappings>
<jaxrs:providers>
<bean class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="marshallerProperties">
<util:map>
<entry key="jaxb.formatted.output">
<value type="java.lang.Boolean">true</value>
</entry>
</util:map>
</property>
</bean>
<bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="ignoreNamespaces" value="true"/>
</bean>
</jaxrs:providers>
</jaxrs:server>

<jaxrs:server address="/rest/modeshape">
Expand Down

0 comments on commit b15fdf0

Please sign in to comment.