Skip to content

Commit

Permalink
Removed explicit JSON mapper bean that was supporting JAX-RS resource…
Browse files Browse the repository at this point in the history
…s. We are fully JAX-RS/JAXB.
  • Loading branch information
ajs6f committed Feb 12, 2013
1 parent 798627c commit ede56f0
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 89 deletions.
3 changes: 0 additions & 3 deletions fcrepo-dc/src/main/resources/META-INF/spring/generator.xml
Expand Up @@ -8,11 +8,8 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">


<context:annotation-config/>



<util:list value-type="org.fcrepo.generator.dublincore.AbstractIndexer">
<bean class="org.fcrepo.generator.dublincore.IndexFromWellKnownPath">
<property name="wellKnownPath" value="DC"/>
Expand Down
4 changes: 0 additions & 4 deletions fcrepo-dc/src/test/resources/spring-test/generator.xml
Expand Up @@ -31,10 +31,6 @@
<bean class="org.fcrepo.generator.dublincore.IndexFromJcrProperties"/>
</util:list>

<!-- Supports JSON output for API methods. Should be replaced with a properly-
configured JAX-RS Provider-->
<bean class="org.codehaus.jackson.map.ObjectMapper"/>

<!-- Mints PIDs-->
<bean class="org.fcrepo.identifiers.UUIDPidMinter"/>

Expand Down
Expand Up @@ -19,7 +19,6 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import org.codehaus.jackson.map.ObjectMapper;
import org.fcrepo.identifiers.PidMinter;
import org.modeshape.jcr.api.JcrTools;
import org.modeshape.jcr.api.Repository;
Expand All @@ -44,13 +43,6 @@ public abstract class AbstractResource extends Constants {
@Context
protected UriInfo uriInfo;

/**
* Jackson JSON mapper. Should eventually be replaced by the use of proper
* JAX-RS Providers.
*/
@Inject
protected ObjectMapper mapper;

/**
* The JCR repository at the heart of Fedora.
*/
Expand Down
Expand Up @@ -41,6 +41,14 @@
@Path("/namespaces")
public class FedoraNamespaces extends AbstractResource {

/**
* Creates a new namespace in the JCR for use in identifing objects.
*
* @param prefix Prefix to use
* @param uri Uri to use
* @return 201
* @throws RepositoryException
*/
@POST
@Path("/{prefix}")
public Response registerObjectNamespace(@PathParam("prefix")
Expand All @@ -54,6 +62,13 @@ public Response registerObjectNamespace(@PathParam("prefix")
return created(uriInfo.getAbsolutePath()).build();
}

/**
* Register multiple object namespaces.
*
* @param nses A set of namespaces in JAXB-specified format.
* @return 201
* @throws RepositoryException
*/
@POST
@Consumes({TEXT_XML, APPLICATION_JSON})
public Response registerObjectNamespaces(final NamespaceListing nses)
Expand All @@ -68,6 +83,13 @@ public Response registerObjectNamespaces(final NamespaceListing nses)
return created(uriInfo.getAbsolutePath()).build();
}

/**
* Retrieve a namespace URI from a prefix.
*
* @param prefix The prefix to search.
* @return A JAXB-specified format Namespace.
* @throws RepositoryException
*/
@GET
@Path("/{prefix}")
@Produces(APPLICATION_JSON)
Expand All @@ -89,6 +111,11 @@ public Response retrieveObjectNamespace(@PathParam("ns")
}
}

/**
* @return
* @throws RepositoryException
* @throws IOException
*/
@GET
@Produces({TEXT_XML, APPLICATION_JSON})
public NamespaceListing getNamespaces() throws RepositoryException,
Expand Down
@@ -1,3 +1,4 @@

package org.fcrepo.api.legacy;

import static com.google.common.collect.ImmutableMap.builder;
Expand All @@ -6,7 +7,6 @@
import static javax.ws.rs.core.Response.ok;

import java.io.IOException;
import java.util.Map;

import javax.jcr.LoginException;
import javax.jcr.NamespaceRegistry;
Expand Down Expand Up @@ -39,60 +39,58 @@
@Path("")
public class FedoraRepository extends AbstractResource {

private static final Logger logger = LoggerFactory
.getLogger(FedoraRepository.class);
private static final Logger logger = LoggerFactory
.getLogger(FedoraRepository.class);

@GET
@Path("/describe/modeshape")
public Response describeModeshape() throws JsonGenerationException,
JsonMappingException, IOException, RepositoryException {
final Session session = repo.login();
logger.debug("Repository name: "
+ repo.getDescriptor(Repository.REP_NAME_DESC));
final Builder<String, Object> repoproperties = builder();
for (final String key : repo.getDescriptorKeys()) {
if (repo.getDescriptor(key) != null)
repoproperties.put(key, repo.getDescriptor(key));
}
@GET
@Path("/describe/modeshape")
public Response describeModeshape() throws JsonGenerationException,
JsonMappingException, IOException, RepositoryException {
final Session session = repo.login();
logger.debug("Repository name: " +
repo.getDescriptor(Repository.REP_NAME_DESC));
final Builder<String, Object> repoproperties = builder();
for (final String key : repo.getDescriptorKeys()) {
if (repo.getDescriptor(key) != null)
repoproperties.put(key, repo.getDescriptor(key));
}

// add in node namespaces
final NamespaceRegistry reg = session.getWorkspace()
.getNamespaceRegistry();
final Builder<String, String> namespaces = builder();
for (final String prefix : reg.getPrefixes()) {
namespaces.put(prefix, reg.getURI(prefix));
}
repoproperties.put("node.namespaces", namespaces.build());
// add in node namespaces
final NamespaceRegistry reg =
session.getWorkspace().getNamespaceRegistry();
final Builder<String, String> namespaces = builder();
for (final String prefix : reg.getPrefixes()) {
namespaces.put(prefix, reg.getURI(prefix));
}
repoproperties.put("node.namespaces", namespaces.build());

// add in node types
final NodeTypeManager ntmanager = (NodeTypeManager) session
.getWorkspace().getNodeTypeManager();
final Builder<String, String> nodetypes = builder();
NodeTypeIterator i = ntmanager.getAllNodeTypes();
while (i.hasNext()) {
NodeType nt = i.nextNodeType();
nodetypes.put(nt.getName(), nt.toString());
}
repoproperties.put("node.types", nodetypes.build());
Map<String, Object> props = repoproperties.build();
session.logout();
return ok(mapper.writerWithType(Map.class).writeValueAsString(props))
.build();
}
// add in node types
final NodeTypeManager ntmanager =
(NodeTypeManager) session.getWorkspace().getNodeTypeManager();
final Builder<String, String> nodetypes = builder();
NodeTypeIterator i = ntmanager.getAllNodeTypes();
while (i.hasNext()) {
NodeType nt = i.nextNodeType();
nodetypes.put(nt.getName(), nt.toString());
}
repoproperties.put("node.types", nodetypes.build());
session.logout();
return ok(repoproperties.build().toString()).build();
}

@GET
@Path("/describe")
@Produces({ TEXT_XML, APPLICATION_JSON })
public DescribeRepository describe() throws LoginException,
RepositoryException {
@GET
@Path("/describe")
@Produces({TEXT_XML, APPLICATION_JSON})
public DescribeRepository describe() throws LoginException,
RepositoryException {

Session session = repo.login();
DescribeRepository description = new DescribeRepository();
description.repositorySize = getRepositorySize(session);
description.numberOfObjects = session.getNode("/objects").getNodes()
.getSize();
session.logout();
return description;
}
Session session = repo.login();
DescribeRepository description = new DescribeRepository();
description.repositorySize = getRepositorySize(session);
description.numberOfObjects =
session.getNode("/objects").getNodes().getSize();
session.logout();
return description;
}

}
@@ -1,9 +1,9 @@

package org.fcrepo.api.legacy.foxml;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
Expand All @@ -30,8 +30,9 @@ public class FedoraOXML extends AbstractResource {
@PUT
@Path("/{filename}")
@Consumes("text/xml")
public Response addFOXML(@PathParam("filename") final String filename,
InputStream foxml) throws RepositoryException, IOException {
public Response addFOXML(@PathParam("filename")
final String filename, InputStream foxml) throws RepositoryException,
IOException {

final Session session = repo.login();
if (session.hasPermission("/foxml", "add_node")) {
Expand All @@ -48,17 +49,18 @@ public Response addFOXML(@PathParam("filename") final String filename,

@GET
@Path("/{filename}")
public Response getFOXML(@PathParam("filename") final String filename)
throws RepositoryException {
public Response getFOXML(@PathParam("filename")
final String filename) throws RepositoryException {

final String foxmlpath = "/foxml" + filename;

final Session session = repo.login();

if (session.nodeExists(foxmlpath)) {
final Node foxmlfile = session.getNode(foxmlpath);
InputStream contentStream = foxmlfile.getNode("jcr:content")
.getProperty("jcr:data").getBinary().getStream();
InputStream contentStream =
foxmlfile.getNode("jcr:content").getProperty("jcr:data")
.getBinary().getStream();
session.logout();
return Response.ok(contentStream, "text/xml").build();
} else {
Expand All @@ -81,10 +83,8 @@ public Response getFOXMLs() throws RepositoryException,
Node n = i.nextNode();
b.put(n.getName(), n.getPath());
}
String foxmls = mapper.writerWithType(Map.class).writeValueAsString(
b.build());
session.logout();
return Response.ok().entity(foxmls).build();
return Response.ok().entity(b.build().toString()).build();

}
}
4 changes: 0 additions & 4 deletions fcrepo-legacy-api/src/main/resources/META-INF/spring/rest.xml
Expand Up @@ -56,10 +56,6 @@
<bean class="org.modeshape.web.jcr.rest.output.TextBodyWriter"/>
</jaxrs:providers>
</jaxrs:server>

<!-- Supports JSON output for API methods. Should be replaced with a properly-
configured JAX-RS Provider -->
<bean class="org.codehaus.jackson.map.ObjectMapper"/>

<!-- Mints PIDs-->
<bean class="org.fcrepo.identifiers.UUIDPidMinter"/>
Expand Down
4 changes: 0 additions & 4 deletions fcrepo-legacy-api/src/test/resources/spring-test/rest.xml
Expand Up @@ -48,10 +48,6 @@
</jaxrs:providers>
</jaxrs:server>

<!-- Supports JSON output for API methods. Should be replaced with a properly-
configured JAX-RS Provider-->
<bean class="org.codehaus.jackson.map.ObjectMapper"/>

<!-- Mints PIDs-->
<bean class="org.fcrepo.identifiers.UUIDPidMinter"/>

Expand Down
2 changes: 1 addition & 1 deletion fcrepo-webapp/src/main/resources/logback.xml
Expand Up @@ -9,7 +9,7 @@
<logger name="org.fcrepo" additivity="false" level="DEBUG">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.apache.cxf" additivity="false" level="DEBUG">
<logger name="org.apache.cxf" additivity="false" level="WARN">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.modeshape" additivity="false" level="WARN">
Expand Down
4 changes: 0 additions & 4 deletions fcrepo-webapp/src/main/resources/spring/rest.xml
Expand Up @@ -17,10 +17,6 @@

<context:annotation-config/>

<!-- Supports JSON output for API methods. Should be replaced with a properly-
configured JAX-RS Provider-->
<bean class="org.codehaus.jackson.map.ObjectMapper"/>

<!-- Mints PIDs-->
<bean class="org.fcrepo.identifiers.UUIDPidMinter"/>

Expand Down

0 comments on commit ede56f0

Please sign in to comment.