<dependency> <groupId>org.modeshape</groupId> <artifactId>modeshape-web-jcr-rest-war</artifactId> <version>${modeshape.version}</version> <scope>runtime</scope> <type>war</type> </dependency>
ModeShape's RESTful API was intended to be used by HTTP clients, so it's quite easy to write a simple client application to read and write repository content using the RESTful API. However, since our trusty web browser is indeed a simple HTTP client, we can use it to directly interact with the RESTful API. It might not be pretty, but it works beautifully.
Depending on whether you want to use the REST endpoint in the JBoss Application Server or another web server, there are 2 different options:
To embed the REST endpoint in your own application, you need to use the modeshape-web-jcr-rest-war artifact which comes pre-packaged with all the default dependencies (including ModeShape). The easiest way to use & customize this is to first add the artifact as a dependency in your project:
<dependency> <groupId>org.modeshape</groupId> <artifactId>modeshape-web-jcr-rest-war</artifactId> <version>${modeshape.version}</version> <scope>runtime</scope> <type>war</type> </dependency>
after which you need to overwrite (overlay) your own web.xml, repository configuration and optional additional dependencies. The former is the most important as it contains a reference towards your own custom repository configuration:
<?xml version="1.0"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>ModeShape JCR RESTful Interface Custom Configuration</display-name> <!-- This parameter defines the location of the configuration file, or can specify the JNDI location of the Repository or Repositories implementation. (If the object in JNDI is a ModeShape Repositories instance, then this web application will support multiple repositories.) If a file is specified, ModeShape will first check for a file at this path in the filesystem. If not file exists at this path, ModeShape will attempt to load this as a resource from the classpath. The JNDI location can be specified in the form jndi:<jndi_name> --> <context-param> <param-name>org.modeshape.jcr.URL</param-name> <param-value>file:/my-repository-config.json</param-value> </context-param> <!-- This parameter defines the JAX-RS application class, which is really just a metadata class that lets the JAX-RS engine (RESTEasy in this case) know which classes implement pieces of the JAX-RS specification like exception handling and resource serving. This should not be modified. --> <context-param> <param-name>javax.ws.rs.Application</param-name> <param-value>org.modeshape.web.jcr.rest.JcrApplication</param-value> </context-param> <!-- Required parameter for RESTEasy - should not be modified --> <listener> <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class> </listener> <!-- Required parameter for ModeShape REST - should not be modified --> <listener> <listener-class>org.modeshape.web.jcr.ModeShapeJcrDeployer</listener-class> </listener> <!-- Required parameter for RESTEasy - should not be modified --> <servlet> <servlet-name>Resteasy</servlet-name> <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class> </servlet> <!-- Required parameter for ModeShape REST - should not be modified --> <servlet-mapping> <servlet-name>Resteasy</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
Maven automatically overlays dependencies of type war, so all you need to do is make sure your project structure contains the correct paths: src/main/resource and src/main/webapp/WEB-INF/web.xml.
See also our examples for such a configuration.
Once installed into Wildfly, the ModeShape Wildfly kit provides the RESTful API out-of-the-box, via a web application named modeshape-rest.war. This application is configured by default via the standalone-modeshape.xml server configuration file and allows access to all the repositories configured & deployed via Wildfly.
<subsystem xmlns="urn:jboss:domain:modeshape:2.0"> <!--The list of web applications that is packaged inside the kit and should be deployed when the subsystem starts up--> <webapp name="modeshape-rest.war"/> </subsystem>
See also Using Repositories with REST in Wildfly
By default, both web applications use Basic HTTP Authentication and require a role named connect to be present in the authenticated user's set of roles.