From 14df515eca6440633456c84ac267fa86694cf190 Mon Sep 17 00:00:00 2001 From: Horia Chiorean Date: Tue, 23 Apr 2013 16:54:20 +0300 Subject: [PATCH 01/11] MODE-1695 - Migrated the web application servlet example from the examples repository and transformed it into an EAP-style quickstart. --- .gitignore | 28 ++ modeshape-servlet-example/README.md | 116 ++++++++ modeshape-servlet-example/pom.xml | 248 ++++++++++++++++++ modeshape-servlet-example/settings.xml | 48 ++++ .../example/web/RepositoryServlet.java | 179 +++++++++++++ .../src/main/resources/log4j.properties | 9 + .../WEB-INF/jboss-deployment-structure.xml | 9 + .../src/main/webapp/WEB-INF/jboss-web.xml | 6 + .../src/main/webapp/WEB-INF/web.xml | 20 ++ .../src/main/webapp/dblue106.gif | Bin 0 -> 8543 bytes .../src/main/webapp/lgrey029.jpg | Bin 0 -> 1969 bytes .../src/main/webapp/main.jsp | 113 ++++++++ .../main/webapp/modeshape_icon_64px_med.png | Bin 0 -> 5372 bytes .../example/web/RepositoryServletTest.java | 48 ++++ .../src/test/resources/arquillian.xml | 32 +++ .../src/test/resources/log4j.properties | 23 ++ pom.xml | 20 ++ 17 files changed, 899 insertions(+) create mode 100644 .gitignore create mode 100644 modeshape-servlet-example/README.md create mode 100644 modeshape-servlet-example/pom.xml create mode 100644 modeshape-servlet-example/settings.xml create mode 100644 modeshape-servlet-example/src/main/java/org/modeshape/example/web/RepositoryServlet.java create mode 100644 modeshape-servlet-example/src/main/resources/log4j.properties create mode 100644 modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml create mode 100644 modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-web.xml create mode 100644 modeshape-servlet-example/src/main/webapp/WEB-INF/web.xml create mode 100644 modeshape-servlet-example/src/main/webapp/dblue106.gif create mode 100644 modeshape-servlet-example/src/main/webapp/lgrey029.jpg create mode 100644 modeshape-servlet-example/src/main/webapp/main.jsp create mode 100644 modeshape-servlet-example/src/main/webapp/modeshape_icon_64px_med.png create mode 100644 modeshape-servlet-example/src/test/java/org/modeshape/example/web/RepositoryServletTest.java create mode 100644 modeshape-servlet-example/src/test/resources/arquillian.xml create mode 100644 modeshape-servlet-example/src/test/resources/log4j.properties create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e85fc99 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# ignore Maven generated target folders +target + +# ignore eclipse files and folders +.project +.classpath +.settings +.metadata +.scala_dependencies +.externalToolBuilders +/.metadata +/RemoteSystemsTempFiles + +# ignore IDEA files +*.iml +*.ipr +*.iws +.idea +atlassian-ide-plugin.xml + +# Compiled python files +*.pyc + +# REST client module bin folder +/tools/org.modeshape.eclipse.jcr.rest.client/bin + +# Presentation Keynote files +/docs/presentations/*.key diff --git a/modeshape-servlet-example/README.md b/modeshape-servlet-example/README.md new file mode 100644 index 0000000..f0f4000 --- /dev/null +++ b/modeshape-servlet-example/README.md @@ -0,0 +1,116 @@ +Example Using ModeShape from a Web Application's Servlet +========================================================= + + +What is it? +----------- + +This is a self-contained and deployable Maven 3 project that shows how to get access repository bound in JNDI either via native JCR API or using +JNDI API. + +System requirements +------------------- + +All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better. +The application this project produces is designed to be run on JBoss Enterprise Application Platform 6. + +Install ModeShape's EAP kit into an existing JBoss EAP 6 server +----------------------------------------------------- +Before running this demo make sure that you have installed the ModeShape EAP kit into an existing JBoss EAP server. +The simplest way to do this is to follow the instructions provided [here](https://docs.jboss.org/author/display/MODE/Installing+ModeShape+into+AS7) + +Start JBoss EAP with the ModeShape configuration +-------------------------------------------------------------------------------- + +1. Open a command line and navigate to the root of the JBoss server directory. +2. The following shows the command line to start the server with the web profile: + + For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-modeshape.xml + For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-modeshape.xml + +Build and Deploy the Quickstart +------------------------- +_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must use the `settings.xml` +file from the root of this project. See [this ModeShape community article](http://community.jboss.org/wiki/ModeShapeandMaven) +for help on how to install and configure Maven 3._ + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. Type this command to build and deploy the archive: + + mvn clean package jboss-as:deploy + +4. This will deploy `target/modeshape-servlet-example.war` to the running instance of the server. + +Accessing the application +--------------------- + +The application will be running at the following URL: . + +Installing the ModeShape kit will add two pre-configured demo repositories: `sample` and `artifacts` (see the `JBOSS_HOME/conf/standalone-modeshape.xml` file for more details). +Both repositories are bound by default in JNDI under names: `java:/jcr/sample` and `java:/jcr/artifacts`. + +The user is presented with a form where he can input data in two fields: + +1. Repository Location - a *mandatory* string, which can have one of the following formats that will dictate the way the repository +is looked up: + `repository_name` - the simple name of a repository which can be located in JNDI at the pre-configured location: java:/jcr/ + `full_repository_jndi_path` - the full JNDI path to a repository + `repository_url` - a url starting with either `jndi:`, `http:`, `file:` and `classpath:` which represents the full path to a repository JSON configuration file +2. Node Path - an *optional* string which represents the full path to a node in a repository. The default value is the root path: _/_ + +Once the above information is submitted, the form will display the children of the node located at the above path. + +Undeploy the Archive +-------------------- + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. When you are finished testing, type this command to undeploy the archive: + + mvn jboss-as:undeploy + +Run the Arquillian Tests +------------------------- + +This quickstart provides Arquillian tests. By default, these tests are configured to be skipped as Arquillian tests require the use of a container. + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. Type the following command to run the test goal with the following profile activated: + + mvn clean test -Parq-jbossas-remote + +The ModeShape project +--------------------- +ModeShape is an open source implementation of the JCR 2.0 +([JSR-283](http://www.jcp.org/en/jsr/detail?id=283])) specification and +standard API. To your applications, ModeShape looks and behaves like a +regular JCR repository. Applications can search, query, navigate, change, +version, listen for changes, etc. But ModeShape can store that content +in a variety of back-end stores (including relational databases, Infinispan +data grids, JBoss Cache, etc.), or it can access and update existing content +from *other* kinds of systems (including file systems, SVN repositories, +JDBC database metadata, and other JCR repositories). ModeShape's connector +architecture means that you can write custom connectors to access any +kind of system. And ModeShape can even federate multiple back-end systems +into a single, unified virtual repository. + +For more information on ModeShape, including getting started guides, +reference guides, and downloadable binaries, visit the project's website +at [http://www.modeshape.org]() or follow us on our [blog](http://modeshape.wordpress.org) +or on [Twitter](http://twitter.com/modeshape). Or hop into our +[IRC chat room](http://www.jboss.org/modeshape/chat) and talk our community +of contributors and users. + +The official Git repository for the project is also on GitHub at +[http://github.com/ModeShape/modeshape](). + +Need help ? +----------- + +ModeShape is open source software with a dedicated community. If you have +any questions or problems, post a question in our +[user forum](http://community.jboss.org/en/modeshape) or hop into our +[IRC chat room](http://www.jboss.org/modeshape/chat) and talk our +community of contributors and users. diff --git a/modeshape-servlet-example/pom.xml b/modeshape-servlet-example/pom.xml new file mode 100644 index 0000000..6aeff00 --- /dev/null +++ b/modeshape-servlet-example/pom.xml @@ -0,0 +1,248 @@ + + + 4.0.0 + org.modeshape.quickstarts + modeshape-servlet-example + 1.0-SNAPSHOT + war + Example of web application that uses ModeShape + + A simple self-contained example web application that uses a servlet to retrieve a repository managed within EAP. + + + + UTF-8 + 1.6 + 1.6 + + + 2.4 + 2.5 + 3.0 + 2.6 + 2.4 + 2.4 + 2.6 + 2.12.3 + 2.3 + 7.3.Final + + + 1.0.4.Final + 3.2.0.Final + + + + + + + org.jboss.bom + jboss-javaee-6.0-with-tools + ${version.org.jboss.bom} + pom + import + + + + + org.modeshape.bom + modeshape-bom-jbosseap + ${version.modeshape} + pom + import + + + + + + + javax.jcr + jcr + + + org.slf4j + slf4j-api + + + javax.servlet + servlet-api + + + + + javax.enterprise + cdi-api + provided + + + + + org.jboss.spec.javax.annotation + jboss-annotations-api_1.1_spec + provided + + + + + org.jboss.spec.javax.servlet + jboss-servlet-api_3.0_spec + provided + + + + + junit + junit + test + + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.jboss.arquillian.protocol + arquillian-protocol-servlet + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-depchain + pom + test + + + + + ${project.artifactId} + + + + + org.apache.maven.plugins + maven-assembly-plugin + ${version.assembly.plugin} + + + org.apache.maven.plugins + maven-clean-plugin + ${version.clean.plugin} + + + org.apache.maven.plugins + maven-compiler-plugin + ${version.compiler.plugin} + + false + false + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + org.apache.maven.plugins + maven-dependency-plugin + ${version.dependency.plugin} + + + org.apache.maven.plugins + maven-install-plugin + ${version.install.plugin} + + + org.apache.maven.plugins + maven-jar-plugin + ${version.jar.plugin} + + + org.apache.maven.plugins + maven-resources-plugin + ${version.resources.plugin} + + + org.apache.maven.plugins + maven-surefire-plugin + ${version.surefire.plugin} + + + org.apache.maven.plugins + maven-war-plugin + ${version.war.plugin} + + + + + org.jboss.as.plugins + jboss-as-maven-plugin + ${version.org.jboss.as.plugins.maven.plugin} + + + + + + + + + + default + + true + + + + + maven-surefire-plugin + ${version.surefire.plugin} + + true + + + + + + + + + + arq-jbossas-managed + + + org.jboss.as + jboss-as-arquillian-container-managed + test + + + + + + + arq-jbossas-remote + + + org.jboss.as + jboss-as-arquillian-container-remote + test + + + + + diff --git a/modeshape-servlet-example/settings.xml b/modeshape-servlet-example/settings.xml new file mode 100644 index 0000000..fc2ab66 --- /dev/null +++ b/modeshape-servlet-example/settings.xml @@ -0,0 +1,48 @@ + + + + + jboss-public-repository + + + jboss-public-repository-group + JBoss Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + default + + true + never + + + true + never + + + + + + jboss-public-repository-group + JBoss Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + default + + true + never + + + true + never + + + + + + + + jboss-public-repository + + + diff --git a/modeshape-servlet-example/src/main/java/org/modeshape/example/web/RepositoryServlet.java b/modeshape-servlet-example/src/main/java/org/modeshape/example/web/RepositoryServlet.java new file mode 100644 index 0000000..9337f07 --- /dev/null +++ b/modeshape-servlet-example/src/main/java/org/modeshape/example/web/RepositoryServlet.java @@ -0,0 +1,179 @@ +/* + * ModeShape (http://www.modeshape.org) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * ModeShape is free software. Unless otherwise indicated, all code in ModeShape + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * ModeShape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.modeshape.example.web; + +import java.io.IOException; +import java.util.Map; +import javax.jcr.Node; +import javax.jcr.PathNotFoundException; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.RepositoryFactory; +import javax.jcr.Session; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Demo for using JCR from web application. This example application accepts a "repository" parameter and a "path" parameter, + * while most practical applications will know where to find the repository URL (e.g. via configuration, perhaps via the web.xml), + * and will determine the path from the requests' URL. + * + * @author kulikov + * @author Horia Chiorean + */ +public class RepositoryServlet extends HttpServlet { + public static final String CHILDREN_ATTRIBUTE = "children"; + public static final String REPOSITORY_PARAM = "repository"; + public static final String NODE_PATH_PARAM = "path"; + public static final String ERROR_MESSAGE = "errorMessage"; + + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = LoggerFactory.getLogger(RepositoryServlet.class); + + protected void doGet( HttpServletRequest request, + HttpServletResponse response ) throws IOException { + cleanSession(request); + String repositoryLocation = storeRequestParameterIntoSession(request, REPOSITORY_PARAM, null); + + if (repositoryLocation != null && repositoryLocation.trim().length() > 0) { + Session jcrSession = null; + try { + // Lookup repository ... + Repository repository = getRepository(repositoryLocation); + + // establish jcr session ... + jcrSession = repository.login(); + LOGGER.info("Session established successfully to repository at: {0}", repositoryLocation); + + // get the path of the node + String path = storeRequestParameterIntoSession(request, NODE_PATH_PARAM, "/"); + // display children + try { + Node node = jcrSession.getNode(path); + request.getSession().setAttribute(CHILDREN_ATTRIBUTE, node.getNodes()); + } catch (PathNotFoundException e) { + displayError(request, "No node can be located at: " + path); + } + } catch (Exception e) { + LOGGER.error("Could not complete request", e); + displayError(request, e.getMessage()); + } finally { + // Always log out of the jcrSession ... + if (jcrSession != null) { + jcrSession.logout(); + LOGGER.info("Logged out from jcrSession"); + } + } + } else { + displayError(request, "The repository location is required"); + } + + response.sendRedirect("main.jsp"); + } + + private Repository getRepository( String location ) throws Exception { + Repository repository = searchJNDI(location); + if (repository == null) { + repository = searchURL(location); + } + + if (repository == null) { + throw new RuntimeException("Unable to lookup repository at '" + location + "'. Please check the format."); + } + + return repository; + } + + private Repository searchURL( String location ) throws RepositoryException { + if (location.startsWith("jndi:") || + location.startsWith("file:") || + location.startsWith("classpath:") || + location.startsWith("http:")) { + // Look up the repository using JCR's RepositoryFactory. This seems like a lot more work, but it actually + // is far more capable and can handle a much wider range of "location" formats. This code even works in + // a Java SE application, so this approach is great for libraries that can be used in any kind of application. + // The "parameters" map could actually be obtained by reading in the entries from a properties file or via + // properties in the web.xml; this way, the code contains no specific settings for ModeShape. + Map parameters = java.util.Collections.singletonMap("org.modeshape.jcr.URL", location); + for (RepositoryFactory factory : java.util.ServiceLoader.load(RepositoryFactory.class)) { + Repository repository = factory.getRepository(parameters); + if (repository != null) { + return repository; + } + } + } + return null; + } + + private Repository searchJNDI( String location ) { + Repository repository = null; + try { + LOGGER.debug("Searching in JNDI directly at: {0}", location); + InitialContext ic = new InitialContext(); + repository = (Repository)ic.lookup(location); + } catch (NamingException e) { + LOGGER.debug("Naming exception", e); + } + + if (repository == null) { + location = "java:/jcr/" + location; + try { + LOGGER.debug("Searching in JNDI directly at: {0}", location); + InitialContext ic = new InitialContext(); + repository = (Repository)ic.lookup(location); + } catch (NamingException e) { + LOGGER.debug("Naming exception", e); + } + } + + return repository; + } + + private void cleanSession( HttpServletRequest request ) { + request.getSession(true).removeAttribute(ERROR_MESSAGE); + request.getSession().removeAttribute(CHILDREN_ATTRIBUTE); + } + + private void displayError( HttpServletRequest request, + String message ) { + request.getSession().setAttribute(ERROR_MESSAGE, message); + } + + private String storeRequestParameterIntoSession( HttpServletRequest request, + String name, + String defaultValue ) { + String paramValue = request.getParameter(name); + if (paramValue == null || paramValue.trim().length() == 0) { + paramValue = defaultValue; + } + request.getSession(true).setAttribute(name, paramValue); + return paramValue; + } +} diff --git a/modeshape-servlet-example/src/main/resources/log4j.properties b/modeshape-servlet-example/src/main/resources/log4j.properties new file mode 100644 index 0000000..764338a --- /dev/null +++ b/modeshape-servlet-example/src/main/resources/log4j.properties @@ -0,0 +1,9 @@ +log4j.rootLogger = INFO, stdout + +log4j.category.org.apache=INFO +log4j.category.org.slf4j.impl.JCLLoggerAdapter=INFO + +log4j.appender.stdout = org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target = System.out +log4j.appender.stdout.layout = org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern = [%-5p] [%C] : %m%n [%F:%L] diff --git a/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000..4d773af --- /dev/null +++ b/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-web.xml b/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000..e4902c3 --- /dev/null +++ b/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,6 @@ + + + + /modeshape + + diff --git a/modeshape-servlet-example/src/main/webapp/WEB-INF/web.xml b/modeshape-servlet-example/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..66979f1 --- /dev/null +++ b/modeshape-servlet-example/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,20 @@ + + + Repository descriptor + + JCR-RepositoryServlet + org.modeshape.example.web.RepositoryServlet + 1 + + + JCR-RepositoryServlet + *.do + + + BASIC + + + main.jsp + + diff --git a/modeshape-servlet-example/src/main/webapp/dblue106.gif b/modeshape-servlet-example/src/main/webapp/dblue106.gif new file mode 100644 index 0000000000000000000000000000000000000000..1cc7688b6c659e34ae90cc48415490c19c1dd2d4 GIT binary patch literal 8543 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 WNGAWp`bqBDURMVjBoqn&*!(~GzFP1A literal 0 HcmV?d00001 diff --git a/modeshape-servlet-example/src/main/webapp/lgrey029.jpg b/modeshape-servlet-example/src/main/webapp/lgrey029.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5ef185c73eae8745b57b00a04800a5c1af5e0198 GIT binary patch literal 1969 zcmbV}c{JPE9>9M;2@-pdRP17DM-`FUWlBvWmLiC)%m}3|r4vi5Qni~_drU-w8fC^( zYL5~r##F18)(EvcrKkpJEwxjotrzdTGw+=D*UbBzbMLw5e!t&)@8^5>$M)XE-R? z8+0}}m#@TLjY~;QOaI}<%?w8N9cE5$-rfA-lG3vKc-`L#R-ubw@ci;sAkbi6aY4$%} z2!WRnRM1k<120hMieNwxP+<+Mh^!4sltPum7$w2vPiFnX>VRwF+*Xl+k%M9=t>ZJ= zYX@roGW%;{$^VzxpJM;@8V4jGpy2Z$2;c8Qk1{!<~JUHKO_TP>|%0y z`3NP)@0^)xVPWG(=QP>QTP+7gjhwLwS4$2(I?Y+6w*AiH==ZFCu3ti?HZdLVoSdgRH0cg(DX`q z+1Pb$?0Sn;zu=A4%6uwHmrihCpl3}H6He7E?$N`!&zY`=nc@DMr2fU&Rs#Jy5k}aAF7nPh==hvVZ6HN<~XC}d>vFeM7*g$M={|Pb0 z_G0I8l>RZ^$Zed@EM3a(blc_${{ z0?Q#A+)gx?*lPcAFDFsyd*=Dw0oE+lc4TC3;qxu|Ii29 z)Wm2SY)L28>ta%}7mFO&(4nQ)m%#+rcE2q9A9GdKzQnmRwCypS+fU%CUsk*42s6be zAMq7F;i*15UIxbp+gz)Nynemuj;!6wNUQh8yA0URImXOUJN;eqBKPM#ntNRYkF8*M zla%*>u2TAj7Q_El+@`%m`GMysAqeI7^w|S7W`P@FySKu$1`9vfg^JOA5>7 zIWcHwl0IiiMX1izZy*w}{nnexYhQGj8Idf4q{;blzb-905}UmP`?AVaWtOP49Yco< zBlL4~zOQPG8ldC$M#h%fa=m+}tXQ%+;pLg7QlAoZf2W2AM=yc|CQ%!gMrm!Q@%Dk5 OQ@d>0jEsT(SN{a@GFsaJ literal 0 HcmV?d00001 diff --git a/modeshape-servlet-example/src/main/webapp/main.jsp b/modeshape-servlet-example/src/main/webapp/main.jsp new file mode 100644 index 0000000..2d784f2 --- /dev/null +++ b/modeshape-servlet-example/src/main/webapp/main.jsp @@ -0,0 +1,113 @@ +<%@ page import="javax.jcr.*" %> +<%@ page import="org.modeshape.example.web.RepositoryServlet" %> + + + ModeShape Servlet QuickStart + + +
+
+
+ + + + + +

ModeShape Demo Servlet Web Application

+
+

+ This is a demo which demonstrates two approaches of how to access a ModeShape repository from + web application's servlet. + The first approach uses standard way to get a reference to the repository via JNDI, the second + demonstrates how to utilize the native JCR API to access the same repository. +

+ +

+ Before running this quickstart make sure that you have installed Modeshape repository and the repository is bound to some + JNDI name. The simplest way to do it is use JBoss AS7 and install + Modeshape following to intructions provided by the wiki page + which explains how to start ModeShape engine as AS7 subsystem with two preconfigured sample repositories: sample + and artifacts (see conf/standalone-modeshape.xml). + Both repositories are bound by default in JNDI under name jcr/sample and jcr/artifacts in the java + namespace. +

+ +

+ Via the form bellow it is possible to specify a repository name/full JNDI name and an absolute path to a node. + The response will contain the children of the node at the given path in the repository. + The format of the Repository location parameter defines which approach will be used + to get the access to the repository. + If Repository location contains a simple name (like sample or artifacts) or a JNDI name like java:/jcr/sample + the repository will be located directly in JNDI. + If Repository location is a URI which starts with one of the following prefixes: 'jndi:' (i.e. jndi:/jcr/artifacts) or + 'http:', 'file:', 'classpath:' + the path to the a JSON file representing a valid repository configuration. + the native JCR API will be used +

+ +
+

Repository parameters +


+

+
+ + + + + + + + + + + + +
+

Repository location:
+ (simple repository name/jndi-path/URL) +

+
+ " + size="50"/> +
+

+ Node path: +
Absolute path to node. If you don't enter anything, the root node path "/" will be used

+
+ " + size="50"/>
+ +
+
+
+ <% if (session.getAttribute(RepositoryServlet.ERROR_MESSAGE) != null) { %> +
+ <%= session.getAttribute(RepositoryServlet.ERROR_MESSAGE) %> +
+ <%} else if (session.getAttribute(RepositoryServlet.CHILDREN_ATTRIBUTE) != null) {%> +

+ Selected node: <%= session.getAttribute(RepositoryServlet.NODE_PATH_PARAM) %> +

+

Children:

+
    + <% + NodeIterator it = (NodeIterator)session.getAttribute(RepositoryServlet.CHILDREN_ATTRIBUTE); + while (it.hasNext()) { + Node n = it.nextNode(); %> +
  • + <%= + n.getName() + %> +
  • + <% } %> +
+ <% } %> +
+
+
+ + diff --git a/modeshape-servlet-example/src/main/webapp/modeshape_icon_64px_med.png b/modeshape-servlet-example/src/main/webapp/modeshape_icon_64px_med.png new file mode 100644 index 0000000000000000000000000000000000000000..ac27b3f4bf89052c73019a6d84530173279c84a2 GIT binary patch literal 5372 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 + + + + + + + + + + + + + + + + + + + diff --git a/modeshape-servlet-example/src/test/resources/log4j.properties b/modeshape-servlet-example/src/test/resources/log4j.properties new file mode 100644 index 0000000..8bc3a0c --- /dev/null +++ b/modeshape-servlet-example/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n + +# Root logger option +log4j.rootLogger=WARN, stdout + +# Set up the default logging to be INFO level, then override specific units +log4j.logger.org.modeshape=INFO +log4j.logger.org.junit=DEBUG +log4j.logger.org.hibernate=WARN +log4j.logger.org.hibernate.pretty.Printer=WARN +log4j.logger.org.hibernate.engine.Collections=WARN +log4j.logger.org.hibernate.cfg=WARN +log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=WARN +log4j.logger.org.hibernate.persister.entity.AbstractEntityPersister=WARN +log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=WARN +log4j.logger.org.hibernate.engine.TwoPhaseLoad=WARN +log4j.logger.org.hibernate.jdbc.AbstractBatcher=WARN +log4j.logger.org.hibernate.hql.ast=WARN +log4j.logger.org.hibernate.engine.loading.CollectionLoadContext=WARN \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d0d7060 --- /dev/null +++ b/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + org.modeshape.quickstarts + modeshape-quickstarts-aggregator + 1.0-SNAPSHOT + ModeShape EAP Quickstarts + Top-Level POM for building all of the quickstarts. + http://www.modeshape.org + pom + + scm:git:git://github.com/ModeShape/quickstart.git + scm:git:git@github.com:ModeShape/quickstart.git + http://github.com/ModeShape/quickstart + + + modeshape-servlet-example + + From 8bcd9791454c575423d72069cfec888c35e55561 Mon Sep 17 00:00:00 2001 From: Horia Chiorean Date: Wed, 24 Apr 2013 11:58:21 +0300 Subject: [PATCH 02/11] MODE-1695 - Updated servlet quickstart to use correct package names and a dedicated web app context --- modeshape-servlet-example/README.md | 2 +- modeshape-servlet-example/pom.xml | 9 +++++- .../servlet}/RepositoryServlet.java | 2 +- .../src/main/webapp/WEB-INF/jboss-web.xml | 2 +- .../src/main/webapp/WEB-INF/web.xml | 2 +- .../src/main/webapp/main.jsp | 24 ++++++++-------- .../servlet}/RepositoryServletTest.java | 28 ++++++++----------- 7 files changed, 35 insertions(+), 34 deletions(-) rename modeshape-servlet-example/src/main/java/org/modeshape/{example/web => quickstart/servlet}/RepositoryServlet.java (99%) rename modeshape-servlet-example/src/test/java/org/modeshape/{example/web => quickstart/servlet}/RepositoryServletTest.java (64%) diff --git a/modeshape-servlet-example/README.md b/modeshape-servlet-example/README.md index f0f4000..d4edf51 100644 --- a/modeshape-servlet-example/README.md +++ b/modeshape-servlet-example/README.md @@ -45,7 +45,7 @@ for help on how to install and configure Maven 3._ Accessing the application --------------------- -The application will be running at the following URL: . +The application will be running at the following URL: . Installing the ModeShape kit will add two pre-configured demo repositories: `sample` and `artifacts` (see the `JBOSS_HOME/conf/standalone-modeshape.xml` file for more details). Both repositories are bound by default in JNDI under names: `java:/jcr/sample` and `java:/jcr/artifacts`. diff --git a/modeshape-servlet-example/pom.xml b/modeshape-servlet-example/pom.xml index 6aeff00..7f27bf8 100644 --- a/modeshape-servlet-example/pom.xml +++ b/modeshape-servlet-example/pom.xml @@ -31,6 +31,7 @@ 1.0.4.Final 3.2.0.Final + 1.14.1-beta @@ -100,13 +101,19 @@ provided - + junit junit test + + com.google.http-client + google-http-client + ${version.google.http-client} + + org.jboss.arquillian.junit arquillian-junit-container diff --git a/modeshape-servlet-example/src/main/java/org/modeshape/example/web/RepositoryServlet.java b/modeshape-servlet-example/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java similarity index 99% rename from modeshape-servlet-example/src/main/java/org/modeshape/example/web/RepositoryServlet.java rename to modeshape-servlet-example/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java index 9337f07..cec0252 100644 --- a/modeshape-servlet-example/src/main/java/org/modeshape/example/web/RepositoryServlet.java +++ b/modeshape-servlet-example/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java @@ -21,7 +21,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.modeshape.example.web; +package org.modeshape.quickstart.servlet; import java.io.IOException; import java.util.Map; diff --git a/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-web.xml b/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-web.xml index e4902c3..cab233d 100644 --- a/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-web.xml +++ b/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-web.xml @@ -1,6 +1,6 @@ - /modeshape + /modeshape-servlet diff --git a/modeshape-servlet-example/src/main/webapp/WEB-INF/web.xml b/modeshape-servlet-example/src/main/webapp/WEB-INF/web.xml index 66979f1..e8b0a40 100644 --- a/modeshape-servlet-example/src/main/webapp/WEB-INF/web.xml +++ b/modeshape-servlet-example/src/main/webapp/WEB-INF/web.xml @@ -4,7 +4,7 @@ Repository descriptor JCR-RepositoryServlet - org.modeshape.example.web.RepositoryServlet + org.modeshape.quickstart.servlet.RepositoryServlet 1 diff --git a/modeshape-servlet-example/src/main/webapp/main.jsp b/modeshape-servlet-example/src/main/webapp/main.jsp index 2d784f2..985461e 100644 --- a/modeshape-servlet-example/src/main/webapp/main.jsp +++ b/modeshape-servlet-example/src/main/webapp/main.jsp @@ -1,5 +1,5 @@ -<%@ page import="javax.jcr.*" %> -<%@ page import="org.modeshape.example.web.RepositoryServlet" %> +<%@ page import="javax.jcr.Node" %> +<%@ page import="javax.jcr.NodeIterator" %> ModeShape Servlet QuickStart @@ -58,9 +58,9 @@

- " + " size="50"/> @@ -72,8 +72,8 @@ " + value="<%= session.getAttribute(org.modeshape.quickstart.servlet.RepositoryServlet.NODE_PATH_PARAM) == null ? "" : + session.getAttribute(org.modeshape.quickstart.servlet.RepositoryServlet.NODE_PATH_PARAM) %>" size="50"/> @@ -84,18 +84,18 @@ - <% if (session.getAttribute(RepositoryServlet.ERROR_MESSAGE) != null) { %> + <% if (session.getAttribute(org.modeshape.quickstart.servlet.RepositoryServlet.ERROR_MESSAGE) != null) { %>
- <%= session.getAttribute(RepositoryServlet.ERROR_MESSAGE) %> + <%= session.getAttribute(org.modeshape.quickstart.servlet.RepositoryServlet.ERROR_MESSAGE) %>
- <%} else if (session.getAttribute(RepositoryServlet.CHILDREN_ATTRIBUTE) != null) {%> + <%} else if (session.getAttribute(org.modeshape.quickstart.servlet.RepositoryServlet.CHILDREN_ATTRIBUTE) != null) {%>

- Selected node: <%= session.getAttribute(RepositoryServlet.NODE_PATH_PARAM) %> + Selected node: <%= session.getAttribute(org.modeshape.quickstart.servlet.RepositoryServlet.NODE_PATH_PARAM) %>

Children:

    <% - NodeIterator it = (NodeIterator)session.getAttribute(RepositoryServlet.CHILDREN_ATTRIBUTE); + NodeIterator it = (NodeIterator)session.getAttribute(org.modeshape.quickstart.servlet.RepositoryServlet.CHILDREN_ATTRIBUTE); while (it.hasNext()) { Node n = it.nextNode(); %>
  • diff --git a/modeshape-servlet-example/src/test/java/org/modeshape/example/web/RepositoryServletTest.java b/modeshape-servlet-example/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java similarity index 64% rename from modeshape-servlet-example/src/test/java/org/modeshape/example/web/RepositoryServletTest.java rename to modeshape-servlet-example/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java index 48e1942..133ed37 100644 --- a/modeshape-servlet-example/src/test/java/org/modeshape/example/web/RepositoryServletTest.java +++ b/modeshape-servlet-example/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java @@ -1,18 +1,19 @@ -package org.modeshape.example.web; +package org.modeshape.quickstart.servlet; import java.io.File; -import java.net.URL; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; import org.junit.Test; -import org.junit.*; import org.junit.runner.RunWith; -import sun.net.www.protocol.http.HttpURLConnection; +import com.google.api.client.http.GenericUrl; +import com.google.api.client.http.HttpRequestFactory; +import com.google.api.client.http.javanet.NetHttpTransport; -@RunWith( Arquillian.class ) +@RunWith(Arquillian.class) @RunAsClient public class RepositoryServletTest { @@ -31,18 +32,11 @@ public static WebArchive createDeployment() { @Test public void shouldExecuteQuery() throws Exception { - URL url = new URL("http://localhost:8080/modeshape/session.do?repository=sample&path=/"); - HttpURLConnection connection = (HttpURLConnection)url.openConnection(); - connection.setRequestMethod("GET"); - connection.setRequestProperty("User-Agent", "Mozilla/5.0 ( compatible )"); - connection.setRequestProperty("Accept", "*/*"); - connection.setDoOutput(true); - connection.setDoInput(true); - - connection.connect(); - - int responseCode = connection.getResponseCode(); - Assert.assertEquals(200, responseCode); + HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory(); + Assert.assertEquals(200, + requestFactory.buildGetRequest(new GenericUrl( + "http://localhost:8080/modeshape-servlet/session.do?repository=sample&path=/")) + .execute().getStatusCode()); } } From f77ef031ddea04c6a06bc1f6b04cade72b95adb3 Mon Sep 17 00:00:00 2001 From: Horia Chiorean Date: Wed, 24 Apr 2013 12:20:38 +0300 Subject: [PATCH 03/11] MODE-1695 - Renamed modeshape-servlet-example to modeshape-servlet --- .../README.md | 2 +- .../pom.xml | 2 +- .../settings.xml | 0 .../quickstart/servlet/RepositoryServlet.java | 0 .../src/main/resources/log4j.properties | 0 .../webapp/WEB-INF/jboss-deployment-structure.xml | 0 .../src/main/webapp/WEB-INF/jboss-web.xml | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/main/webapp/dblue106.gif | Bin .../src/main/webapp/lgrey029.jpg | Bin .../src/main/webapp/main.jsp | 0 .../src/main/webapp/modeshape_icon_64px_med.png | Bin .../quickstart/servlet/RepositoryServletTest.java | 2 +- .../src/test/resources/arquillian.xml | 0 .../src/test/resources/log4j.properties | 0 pom.xml | 2 +- 16 files changed, 4 insertions(+), 4 deletions(-) rename {modeshape-servlet-example => modeshape-servlet}/README.md (98%) rename {modeshape-servlet-example => modeshape-servlet}/pom.xml (99%) rename {modeshape-servlet-example => modeshape-servlet}/settings.xml (100%) rename {modeshape-servlet-example => modeshape-servlet}/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java (100%) rename {modeshape-servlet-example => modeshape-servlet}/src/main/resources/log4j.properties (100%) rename {modeshape-servlet-example => modeshape-servlet}/src/main/webapp/WEB-INF/jboss-deployment-structure.xml (100%) rename {modeshape-servlet-example => modeshape-servlet}/src/main/webapp/WEB-INF/jboss-web.xml (100%) rename {modeshape-servlet-example => modeshape-servlet}/src/main/webapp/WEB-INF/web.xml (100%) rename {modeshape-servlet-example => modeshape-servlet}/src/main/webapp/dblue106.gif (100%) rename {modeshape-servlet-example => modeshape-servlet}/src/main/webapp/lgrey029.jpg (100%) rename {modeshape-servlet-example => modeshape-servlet}/src/main/webapp/main.jsp (100%) rename {modeshape-servlet-example => modeshape-servlet}/src/main/webapp/modeshape_icon_64px_med.png (100%) rename {modeshape-servlet-example => modeshape-servlet}/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java (96%) rename {modeshape-servlet-example => modeshape-servlet}/src/test/resources/arquillian.xml (100%) rename {modeshape-servlet-example => modeshape-servlet}/src/test/resources/log4j.properties (100%) diff --git a/modeshape-servlet-example/README.md b/modeshape-servlet/README.md similarity index 98% rename from modeshape-servlet-example/README.md rename to modeshape-servlet/README.md index d4edf51..5e4d181 100644 --- a/modeshape-servlet-example/README.md +++ b/modeshape-servlet/README.md @@ -40,7 +40,7 @@ for help on how to install and configure Maven 3._ mvn clean package jboss-as:deploy -4. This will deploy `target/modeshape-servlet-example.war` to the running instance of the server. +4. This will deploy `target/modeshape-servlet.war` to the running instance of the server. Accessing the application --------------------- diff --git a/modeshape-servlet-example/pom.xml b/modeshape-servlet/pom.xml similarity index 99% rename from modeshape-servlet-example/pom.xml rename to modeshape-servlet/pom.xml index 7f27bf8..4f07059 100644 --- a/modeshape-servlet-example/pom.xml +++ b/modeshape-servlet/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 org.modeshape.quickstarts - modeshape-servlet-example + modeshape-servlet 1.0-SNAPSHOT war Example of web application that uses ModeShape diff --git a/modeshape-servlet-example/settings.xml b/modeshape-servlet/settings.xml similarity index 100% rename from modeshape-servlet-example/settings.xml rename to modeshape-servlet/settings.xml diff --git a/modeshape-servlet-example/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java b/modeshape-servlet/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java similarity index 100% rename from modeshape-servlet-example/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java rename to modeshape-servlet/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java diff --git a/modeshape-servlet-example/src/main/resources/log4j.properties b/modeshape-servlet/src/main/resources/log4j.properties similarity index 100% rename from modeshape-servlet-example/src/main/resources/log4j.properties rename to modeshape-servlet/src/main/resources/log4j.properties diff --git a/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/modeshape-servlet/src/main/webapp/WEB-INF/jboss-deployment-structure.xml similarity index 100% rename from modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml rename to modeshape-servlet/src/main/webapp/WEB-INF/jboss-deployment-structure.xml diff --git a/modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-web.xml b/modeshape-servlet/src/main/webapp/WEB-INF/jboss-web.xml similarity index 100% rename from modeshape-servlet-example/src/main/webapp/WEB-INF/jboss-web.xml rename to modeshape-servlet/src/main/webapp/WEB-INF/jboss-web.xml diff --git a/modeshape-servlet-example/src/main/webapp/WEB-INF/web.xml b/modeshape-servlet/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from modeshape-servlet-example/src/main/webapp/WEB-INF/web.xml rename to modeshape-servlet/src/main/webapp/WEB-INF/web.xml diff --git a/modeshape-servlet-example/src/main/webapp/dblue106.gif b/modeshape-servlet/src/main/webapp/dblue106.gif similarity index 100% rename from modeshape-servlet-example/src/main/webapp/dblue106.gif rename to modeshape-servlet/src/main/webapp/dblue106.gif diff --git a/modeshape-servlet-example/src/main/webapp/lgrey029.jpg b/modeshape-servlet/src/main/webapp/lgrey029.jpg similarity index 100% rename from modeshape-servlet-example/src/main/webapp/lgrey029.jpg rename to modeshape-servlet/src/main/webapp/lgrey029.jpg diff --git a/modeshape-servlet-example/src/main/webapp/main.jsp b/modeshape-servlet/src/main/webapp/main.jsp similarity index 100% rename from modeshape-servlet-example/src/main/webapp/main.jsp rename to modeshape-servlet/src/main/webapp/main.jsp diff --git a/modeshape-servlet-example/src/main/webapp/modeshape_icon_64px_med.png b/modeshape-servlet/src/main/webapp/modeshape_icon_64px_med.png similarity index 100% rename from modeshape-servlet-example/src/main/webapp/modeshape_icon_64px_med.png rename to modeshape-servlet/src/main/webapp/modeshape_icon_64px_med.png diff --git a/modeshape-servlet-example/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java b/modeshape-servlet/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java similarity index 96% rename from modeshape-servlet-example/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java rename to modeshape-servlet/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java index 133ed37..b8eccfa 100644 --- a/modeshape-servlet-example/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java +++ b/modeshape-servlet/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java @@ -19,7 +19,7 @@ public class RepositoryServletTest { @Deployment public static WebArchive createDeployment() { - return ShrinkWrap.create(WebArchive.class, "modeshape-servlet-example-test.war").addClass(RepositoryServlet.class) + return ShrinkWrap.create(WebArchive.class, "modeshape-servlet-test.war").addClass(RepositoryServlet.class) .addAsWebInfResource(new File("src/main/resources/log4j.properties")) .addAsWebInfResource(new File("src/main/webapp/WEB-INF/jboss-web.xml")) .addAsWebInfResource(new File("src/main/webapp/WEB-INF/jboss-deployment-structure.xml")) diff --git a/modeshape-servlet-example/src/test/resources/arquillian.xml b/modeshape-servlet/src/test/resources/arquillian.xml similarity index 100% rename from modeshape-servlet-example/src/test/resources/arquillian.xml rename to modeshape-servlet/src/test/resources/arquillian.xml diff --git a/modeshape-servlet-example/src/test/resources/log4j.properties b/modeshape-servlet/src/test/resources/log4j.properties similarity index 100% rename from modeshape-servlet-example/src/test/resources/log4j.properties rename to modeshape-servlet/src/test/resources/log4j.properties diff --git a/pom.xml b/pom.xml index d0d7060..abb911f 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,6 @@ http://github.com/ModeShape/quickstart - modeshape-servlet-example + modeshape-servlet From cbbcc776f8748c667f3e08a81a2bad8b62a33f07 Mon Sep 17 00:00:00 2001 From: Horia Chiorean Date: Wed, 24 Apr 2013 17:44:58 +0300 Subject: [PATCH 04/11] MODE-1695 - Added a modeshape-ejb quickstart which uses 3 different types of EJBs to perform repository operations. --- modeshape-ejb/README.md | 116 +++++++ modeshape-ejb/pom.xml | 284 ++++++++++++++++++ modeshape-ejb/settings.xml | 48 +++ .../ejb/beans/RepositoryDescriptor.java | 95 ++++++ .../beans/SingletonRepositoryDescriptor.java | 34 +++ .../StatelessBMTRepositoryDescriptor.java | 81 +++++ .../StatelessCMTRepositoryDescriptor.java | 34 +++ .../ejb/controller/EJBController.java | 183 +++++++++++ .../src/main/resources/log4j.properties | 9 + .../src/main/webapp/WEB-INF/beans.xml | 18 ++ .../src/main/webapp/WEB-INF/faces-config.xml | 20 ++ .../WEB-INF/jboss-deployment-structure.xml | 9 + .../src/main/webapp/WEB-INF/jboss-web.xml | 6 + modeshape-ejb/src/main/webapp/index.html | 23 ++ modeshape-ejb/src/main/webapp/main.xhtml | 68 +++++ .../src/test/resources/arquillian.xml | 32 ++ .../src/test/resources/log4j.properties | 23 ++ modeshape-servlet/pom.xml | 1 + .../servlet/RepositoryServletTest.java | 4 + pom.xml | 1 + 20 files changed, 1089 insertions(+) create mode 100644 modeshape-ejb/README.md create mode 100644 modeshape-ejb/pom.xml create mode 100644 modeshape-ejb/settings.xml create mode 100644 modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptor.java create mode 100644 modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/SingletonRepositoryDescriptor.java create mode 100644 modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/StatelessBMTRepositoryDescriptor.java create mode 100644 modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/StatelessCMTRepositoryDescriptor.java create mode 100644 modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/controller/EJBController.java create mode 100644 modeshape-ejb/src/main/resources/log4j.properties create mode 100644 modeshape-ejb/src/main/webapp/WEB-INF/beans.xml create mode 100644 modeshape-ejb/src/main/webapp/WEB-INF/faces-config.xml create mode 100644 modeshape-ejb/src/main/webapp/WEB-INF/jboss-deployment-structure.xml create mode 100644 modeshape-ejb/src/main/webapp/WEB-INF/jboss-web.xml create mode 100644 modeshape-ejb/src/main/webapp/index.html create mode 100644 modeshape-ejb/src/main/webapp/main.xhtml create mode 100644 modeshape-ejb/src/test/resources/arquillian.xml create mode 100644 modeshape-ejb/src/test/resources/log4j.properties diff --git a/modeshape-ejb/README.md b/modeshape-ejb/README.md new file mode 100644 index 0000000..5e4d181 --- /dev/null +++ b/modeshape-ejb/README.md @@ -0,0 +1,116 @@ +Example Using ModeShape from a Web Application's Servlet +========================================================= + + +What is it? +----------- + +This is a self-contained and deployable Maven 3 project that shows how to get access repository bound in JNDI either via native JCR API or using +JNDI API. + +System requirements +------------------- + +All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better. +The application this project produces is designed to be run on JBoss Enterprise Application Platform 6. + +Install ModeShape's EAP kit into an existing JBoss EAP 6 server +----------------------------------------------------- +Before running this demo make sure that you have installed the ModeShape EAP kit into an existing JBoss EAP server. +The simplest way to do this is to follow the instructions provided [here](https://docs.jboss.org/author/display/MODE/Installing+ModeShape+into+AS7) + +Start JBoss EAP with the ModeShape configuration +-------------------------------------------------------------------------------- + +1. Open a command line and navigate to the root of the JBoss server directory. +2. The following shows the command line to start the server with the web profile: + + For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-modeshape.xml + For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-modeshape.xml + +Build and Deploy the Quickstart +------------------------- +_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must use the `settings.xml` +file from the root of this project. See [this ModeShape community article](http://community.jboss.org/wiki/ModeShapeandMaven) +for help on how to install and configure Maven 3._ + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. Type this command to build and deploy the archive: + + mvn clean package jboss-as:deploy + +4. This will deploy `target/modeshape-servlet.war` to the running instance of the server. + +Accessing the application +--------------------- + +The application will be running at the following URL: . + +Installing the ModeShape kit will add two pre-configured demo repositories: `sample` and `artifacts` (see the `JBOSS_HOME/conf/standalone-modeshape.xml` file for more details). +Both repositories are bound by default in JNDI under names: `java:/jcr/sample` and `java:/jcr/artifacts`. + +The user is presented with a form where he can input data in two fields: + +1. Repository Location - a *mandatory* string, which can have one of the following formats that will dictate the way the repository +is looked up: + `repository_name` - the simple name of a repository which can be located in JNDI at the pre-configured location: java:/jcr/ + `full_repository_jndi_path` - the full JNDI path to a repository + `repository_url` - a url starting with either `jndi:`, `http:`, `file:` and `classpath:` which represents the full path to a repository JSON configuration file +2. Node Path - an *optional* string which represents the full path to a node in a repository. The default value is the root path: _/_ + +Once the above information is submitted, the form will display the children of the node located at the above path. + +Undeploy the Archive +-------------------- + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. When you are finished testing, type this command to undeploy the archive: + + mvn jboss-as:undeploy + +Run the Arquillian Tests +------------------------- + +This quickstart provides Arquillian tests. By default, these tests are configured to be skipped as Arquillian tests require the use of a container. + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. Type the following command to run the test goal with the following profile activated: + + mvn clean test -Parq-jbossas-remote + +The ModeShape project +--------------------- +ModeShape is an open source implementation of the JCR 2.0 +([JSR-283](http://www.jcp.org/en/jsr/detail?id=283])) specification and +standard API. To your applications, ModeShape looks and behaves like a +regular JCR repository. Applications can search, query, navigate, change, +version, listen for changes, etc. But ModeShape can store that content +in a variety of back-end stores (including relational databases, Infinispan +data grids, JBoss Cache, etc.), or it can access and update existing content +from *other* kinds of systems (including file systems, SVN repositories, +JDBC database metadata, and other JCR repositories). ModeShape's connector +architecture means that you can write custom connectors to access any +kind of system. And ModeShape can even federate multiple back-end systems +into a single, unified virtual repository. + +For more information on ModeShape, including getting started guides, +reference guides, and downloadable binaries, visit the project's website +at [http://www.modeshape.org]() or follow us on our [blog](http://modeshape.wordpress.org) +or on [Twitter](http://twitter.com/modeshape). Or hop into our +[IRC chat room](http://www.jboss.org/modeshape/chat) and talk our community +of contributors and users. + +The official Git repository for the project is also on GitHub at +[http://github.com/ModeShape/modeshape](). + +Need help ? +----------- + +ModeShape is open source software with a dedicated community. If you have +any questions or problems, post a question in our +[user forum](http://community.jboss.org/en/modeshape) or hop into our +[IRC chat room](http://www.jboss.org/modeshape/chat) and talk our +community of contributors and users. diff --git a/modeshape-ejb/pom.xml b/modeshape-ejb/pom.xml new file mode 100644 index 0000000..0e70e6f --- /dev/null +++ b/modeshape-ejb/pom.xml @@ -0,0 +1,284 @@ + + + 4.0.0 + org.modeshape.quickstarts + modeshape-ejb + 1.0-SNAPSHOT + war + Example of web application that uses ModeShape via EJBs + + A simple self-contained example web application that uses different EJBs to retrieve repositories managed within EAP. + + + + UTF-8 + 1.6 + 1.6 + + + 2.4 + 2.5 + 3.0 + 2.6 + 2.4 + 2.4 + 2.6 + 2.12.3 + 2.3 + 7.3.Final + + + 1.0.4.Final + 3.2.0.Final + 1.14.1-beta + + + + + + + org.jboss.bom + jboss-javaee-6.0-with-tools + ${version.org.jboss.bom} + pom + import + + + + + org.modeshape.bom + modeshape-bom-jbosseap + ${version.modeshape} + pom + import + + + + + + + javax.jcr + jcr + + + org.modeshape + modeshape-jcr-api + + + org.slf4j + slf4j-api + + + javax.servlet + servlet-api + + + + + javax.enterprise + cdi-api + provided + + + + + org.jboss.spec.javax.annotation + jboss-annotations-api_1.1_spec + provided + + + + + org.jboss.spec.javax.servlet + jboss-servlet-api_3.0_spec + provided + + + + + org.jboss.spec.javax.faces + jboss-jsf-api_2.1_spec + provided + + + + + org.jboss.spec.javax.ejb + jboss-ejb-api_3.1_spec + provided + + + + + org.jboss.spec.javax.transaction + jboss-transaction-api_1.1_spec + provided + + + + + junit + junit + test + + + + com.google.http-client + google-http-client + ${version.google.http-client} + test + + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.jboss.arquillian.protocol + arquillian-protocol-servlet + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-depchain + pom + test + + + + + ${project.artifactId}.war + + + + + org.apache.maven.plugins + maven-assembly-plugin + ${version.assembly.plugin} + + + org.apache.maven.plugins + maven-clean-plugin + ${version.clean.plugin} + + + org.apache.maven.plugins + maven-compiler-plugin + ${version.compiler.plugin} + + false + false + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + org.apache.maven.plugins + maven-dependency-plugin + ${version.dependency.plugin} + + + org.apache.maven.plugins + maven-install-plugin + ${version.install.plugin} + + + org.apache.maven.plugins + maven-jar-plugin + ${version.jar.plugin} + + + org.apache.maven.plugins + maven-resources-plugin + ${version.resources.plugin} + + + org.apache.maven.plugins + maven-surefire-plugin + ${version.surefire.plugin} + + + org.apache.maven.plugins + maven-war-plugin + ${version.war.plugin} + + false + + + + + + org.jboss.as.plugins + jboss-as-maven-plugin + ${version.org.jboss.as.plugins.maven.plugin} + + + + + + + + + + default + + true + + + + + maven-surefire-plugin + ${version.surefire.plugin} + + true + + + + + + + + + + arq-jbossas-managed + + + org.jboss.as + jboss-as-arquillian-container-managed + test + + + + + + + arq-jbossas-remote + + + org.jboss.as + jboss-as-arquillian-container-remote + test + + + + + diff --git a/modeshape-ejb/settings.xml b/modeshape-ejb/settings.xml new file mode 100644 index 0000000..fc2ab66 --- /dev/null +++ b/modeshape-ejb/settings.xml @@ -0,0 +1,48 @@ + + + + + jboss-public-repository + + + jboss-public-repository-group + JBoss Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + default + + true + never + + + true + never + + + + + + jboss-public-repository-group + JBoss Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + default + + true + never + + + true + never + + + + + + + + jboss-public-repository + + + diff --git a/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptor.java b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptor.java new file mode 100644 index 0000000..e80516c --- /dev/null +++ b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptor.java @@ -0,0 +1,95 @@ +/* + * ModeShape (http://www.modeshape.org) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * ModeShape is free software. Unless otherwise indicated, all code in ModeShape + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * ModeShape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.modeshape.quickstart.ejb.beans; + +import java.util.Map; +import java.util.TreeMap; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.modeshape.jcr.api.JcrTools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A utility class that describes a repository after looking it up in JNDI. + */ +public abstract class RepositoryDescriptor { + + protected Logger log = LoggerFactory.getLogger(getClass()); + protected JcrTools jcrTools = new JcrTools(); + + /** + * Returns a map which contains the repository descriptors for a given repository. + * + * @param repositoryName a {@code non-null} {@link String} representing the simple name of a repository + * @return a {@link Map} of {@code descriptor key, descriptor value} pairs. + */ + public Map describeRepository( String repositoryName ) { + log.info("Retrieving description for repository: " + repositoryName); + Repository repository = getRepositoryFromJndi(repositoryName); + Map descriptors = new TreeMap(); + for (String descriptorKey : repository.getDescriptorKeys()) { + descriptors.put(descriptorKey, repository.getDescriptor(descriptorKey)); + } + return descriptors; + } + + /** + * Counts the number of nodes in a respository, by using a default session. + * + * @param repositoryName a {@code non-null} {@link String} representing the simple name of a repository + * @return the number of nodes in the given repository. + * @throws RepositoryException if anything unexpected fails. + */ + public long countNodes( String repositoryName ) throws RepositoryException { + log.info("Counting nodes for repository: " + repositoryName); + Repository repository = getRepositoryFromJndi(repositoryName); + Session session = repository.login(); + JcrTools.CountNodes countNodes = new JcrTools.CountNodes(jcrTools); + countNodes.run(session); + return countNodes.numNonSystemNodes; + } + + protected Repository getRepositoryFromJndi( String jndiName ) throws IllegalArgumentException { + if (!jndiName.startsWith("java:")) { + jndiName = "java:/jcr/" + jndiName; + } + + try { + InitialContext context = new InitialContext(); + Object object = context.lookup(jndiName); + if (!(object instanceof Repository)) { + throw new IllegalArgumentException("Expected to find a javax.jcr.Repository instance, but found a " + + object.getClass().toString() + " instance in JNDI at: " + jndiName); + } + log.info("Successfully retrieved repository at: " + jndiName); + return (Repository)object; + } catch (NamingException e) { + throw new IllegalArgumentException(jndiName + " cannot be located in JNDI"); + } + } +} diff --git a/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/SingletonRepositoryDescriptor.java b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/SingletonRepositoryDescriptor.java new file mode 100644 index 0000000..8139fb5 --- /dev/null +++ b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/SingletonRepositoryDescriptor.java @@ -0,0 +1,34 @@ +/* + * ModeShape (http://www.modeshape.org) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * ModeShape is free software. Unless otherwise indicated, all code in ModeShape + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * ModeShape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.modeshape.quickstart.ejb.beans; + +import javax.ejb.Singleton; + +/** + * A singleton EJB that extends {@link RepositoryDescriptor} + */ +@Singleton +public class SingletonRepositoryDescriptor extends RepositoryDescriptor { +} diff --git a/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/StatelessBMTRepositoryDescriptor.java b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/StatelessBMTRepositoryDescriptor.java new file mode 100644 index 0000000..c007a1b --- /dev/null +++ b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/StatelessBMTRepositoryDescriptor.java @@ -0,0 +1,81 @@ +/* + * ModeShape (http://www.modeshape.org) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * ModeShape is free software. Unless otherwise indicated, all code in ModeShape + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * ModeShape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.modeshape.quickstart.ejb.beans; + +import java.util.Map; +import java.util.TreeMap; +import javax.annotation.Resource; +import javax.ejb.Stateless; +import javax.ejb.TransactionManagement; +import javax.ejb.TransactionManagementType; +import javax.jcr.RepositoryException; +import javax.transaction.SystemException; +import javax.transaction.UserTransaction; + +/** + * A stateless EJB that extends {@link RepositoryDescriptor}. + */ +@Stateless +@TransactionManagement( TransactionManagementType.BEAN ) +public class StatelessBMTRepositoryDescriptor extends RepositoryDescriptor { + + @Resource + private UserTransaction utxn; + + @Override + public Map describeRepository( String repositoryName ) { + Map descriptors = new TreeMap(); + try { + utxn.begin(); + descriptors = super.describeRepository(repositoryName); + utxn.commit(); + } catch (Exception e) { + log.error(e.getMessage(), e); + try { + utxn.rollback(); + } catch (SystemException e1) { + log.error(e1.getMessage(), e1); + } + } + return descriptors; + } + + @Override + public long countNodes( String repositoryName ) throws RepositoryException { + try { + utxn.begin(); + long count = super.countNodes(repositoryName); + utxn.commit(); + return count; + } catch (Exception e) { + try { + utxn.rollback(); + } catch (SystemException e1) { + log.error(e1.getMessage(), e1); + } + throw new RuntimeException(e); + } + } +} diff --git a/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/StatelessCMTRepositoryDescriptor.java b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/StatelessCMTRepositoryDescriptor.java new file mode 100644 index 0000000..20907a2 --- /dev/null +++ b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/StatelessCMTRepositoryDescriptor.java @@ -0,0 +1,34 @@ +/* + * ModeShape (http://www.modeshape.org) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * ModeShape is free software. Unless otherwise indicated, all code in ModeShape + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * ModeShape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.modeshape.quickstart.ejb.beans; + +import javax.ejb.Stateless; + +/** + * A stateless, CMT EJB that extends {@link RepositoryDescriptor} + */ +@Stateless +public class StatelessCMTRepositoryDescriptor extends RepositoryDescriptor { +} diff --git a/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/controller/EJBController.java b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/controller/EJBController.java new file mode 100644 index 0000000..97468c8 --- /dev/null +++ b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/controller/EJBController.java @@ -0,0 +1,183 @@ +/* + * ModeShape (http://www.modeshape.org) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * ModeShape is free software. Unless otherwise indicated, all code in ModeShape + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * ModeShape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.modeshape.quickstart.ejb.controller; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; +import javax.faces.model.SelectItem; +import javax.inject.Named; +import org.modeshape.quickstart.ejb.beans.RepositoryDescriptor; +import org.modeshape.quickstart.ejb.beans.SingletonRepositoryDescriptor; +import org.modeshape.quickstart.ejb.beans.StatelessBMTRepositoryDescriptor; +import org.modeshape.quickstart.ejb.beans.StatelessCMTRepositoryDescriptor; + +/** + * A simple request scoped bean that handles invocations towards different EJBs. + * + * @author Horia Chiorean + */ +@Named("ejbController") +@RequestScoped +public class EJBController implements Serializable { + @EJB + private SingletonRepositoryDescriptor singletonEJB; + + @EJB + private StatelessBMTRepositoryDescriptor statelessBMTEJB; + + @EJB + private StatelessCMTRepositoryDescriptor statelessCMTEJB; + + private String repositoryName; + private String selectedEJB = RepoProvider.SINGLETON.name(); + + private Long nodesCount; + private Map repositoryDescription; + + /** + * Returns the objects used for the html select element that will allow users to select an EJB. + * + * @return a SelectItem[] + */ + public SelectItem[] getAvailableEJBs() { + RepoProvider[] ejbs = RepoProvider.values(); + List items = new ArrayList(ejbs.length); + for (RepoProvider ejb : ejbs) { + items.add(new SelectItem(ejb.name(), ejb.description)); + } + return items.toArray(new SelectItem[items.size()]); + } + + /** + * Returns the EJB that was chosen by the user. + * + * @return a {@link RepositoryDescriptor} instance + */ + public String getSelectedEJB() { + return selectedEJB; + } + + /** + * Sets the active EJB to which calls will be delegated + * + * @param selectedEJB a {@link RepositoryDescriptor} instance + */ + public void setSelectedEJB( String selectedEJB ) { + this.selectedEJB = selectedEJB; + } + + /** + * Counts all the nodes in a repository using the user selected EJB and the inputted repository name. + * + * @return the nodes count or null, if there was an error. + */ + public Long getNodesCount() { + return nodesCount; + } + + /** + * Counts all the nodes in a repository, using the user selected EJB and the inputted repository name. + */ + public void countNodes() { + try { + nodesCount = selectedEJB().countNodes(repositoryName); + } catch (Exception e) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + } + } + + /** + * Gets the description of a repository, using the user selected EJB and the inputted repository name. + */ + public void retrieveDescription() { + try { + repositoryDescription = selectedEJB().describeRepository(repositoryName); + } catch (Exception e) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + } + } + + /** + * Returns a repository description map. + * + * @return a Map or null, if there was an error. + */ + public Map getRepositoryDescription() { + return repositoryDescription; + } + + /** + * Returns the name of the inputted repository. + * + * @return the name of a repository. + */ + public String getRepositoryName() { + return repositoryName; + } + + /** + * Sets the name of a repository. + * + * @param repositoryName a string. + */ + public void setRepositoryName( String repositoryName ) { + this.repositoryName = repositoryName; + } + + private RepositoryDescriptor selectedEJB() { + RepoProvider ejb = RepoProvider.valueOf(selectedEJB); + switch (ejb) { + case SINGLETON: { + return singletonEJB; + } + case STATELESS_CMT: { + return statelessCMTEJB; + } + case STATELESS_BMT: { + return statelessBMTEJB; + } + default: { + throw new IllegalArgumentException("Unknown EJB name: " + selectedEJB); + } + } + } + + private enum RepoProvider { + SINGLETON("Stateful Singleton EJB"), + STATELESS_CMT("Stateless CMT EJB"), + STATELESS_BMT("Stateless BMT EJB"); + + String description; + + private RepoProvider( String description ) { + this.description = description; + } + } +} diff --git a/modeshape-ejb/src/main/resources/log4j.properties b/modeshape-ejb/src/main/resources/log4j.properties new file mode 100644 index 0000000..764338a --- /dev/null +++ b/modeshape-ejb/src/main/resources/log4j.properties @@ -0,0 +1,9 @@ +log4j.rootLogger = INFO, stdout + +log4j.category.org.apache=INFO +log4j.category.org.slf4j.impl.JCLLoggerAdapter=INFO + +log4j.appender.stdout = org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target = System.out +log4j.appender.stdout.layout = org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern = [%-5p] [%C] : %m%n [%F:%L] diff --git a/modeshape-ejb/src/main/webapp/WEB-INF/beans.xml b/modeshape-ejb/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..3f9d20e --- /dev/null +++ b/modeshape-ejb/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,18 @@ + + + + + diff --git a/modeshape-ejb/src/main/webapp/WEB-INF/faces-config.xml b/modeshape-ejb/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000..fbe54e5 --- /dev/null +++ b/modeshape-ejb/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/modeshape-ejb/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/modeshape-ejb/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000..4d773af --- /dev/null +++ b/modeshape-ejb/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/modeshape-ejb/src/main/webapp/WEB-INF/jboss-web.xml b/modeshape-ejb/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000..e8c4309 --- /dev/null +++ b/modeshape-ejb/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,6 @@ + + + + /modeshape-ejb + + diff --git a/modeshape-ejb/src/main/webapp/index.html b/modeshape-ejb/src/main/webapp/index.html new file mode 100644 index 0000000..961c88d --- /dev/null +++ b/modeshape-ejb/src/main/webapp/index.html @@ -0,0 +1,23 @@ + + + + + + + + diff --git a/modeshape-ejb/src/main/webapp/main.xhtml b/modeshape-ejb/src/main/webapp/main.xhtml new file mode 100644 index 0000000..c6cefa7 --- /dev/null +++ b/modeshape-ejb/src/main/webapp/main.xhtml @@ -0,0 +1,68 @@ + + + + + + + ModeShape EJB Example + + + + +

    ModeShape EJB Example

    + +
    + + + + + + + EJB: + + + + + Repository Name: + + + + + + + + + + + + + + + + + + + + Count: + + + +
    + + + \ No newline at end of file diff --git a/modeshape-ejb/src/test/resources/arquillian.xml b/modeshape-ejb/src/test/resources/arquillian.xml new file mode 100644 index 0000000..01c6040 --- /dev/null +++ b/modeshape-ejb/src/test/resources/arquillian.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/modeshape-ejb/src/test/resources/log4j.properties b/modeshape-ejb/src/test/resources/log4j.properties new file mode 100644 index 0000000..8bc3a0c --- /dev/null +++ b/modeshape-ejb/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n + +# Root logger option +log4j.rootLogger=WARN, stdout + +# Set up the default logging to be INFO level, then override specific units +log4j.logger.org.modeshape=INFO +log4j.logger.org.junit=DEBUG +log4j.logger.org.hibernate=WARN +log4j.logger.org.hibernate.pretty.Printer=WARN +log4j.logger.org.hibernate.engine.Collections=WARN +log4j.logger.org.hibernate.cfg=WARN +log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=WARN +log4j.logger.org.hibernate.persister.entity.AbstractEntityPersister=WARN +log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=WARN +log4j.logger.org.hibernate.engine.TwoPhaseLoad=WARN +log4j.logger.org.hibernate.jdbc.AbstractBatcher=WARN +log4j.logger.org.hibernate.hql.ast=WARN +log4j.logger.org.hibernate.engine.loading.CollectionLoadContext=WARN \ No newline at end of file diff --git a/modeshape-servlet/pom.xml b/modeshape-servlet/pom.xml index 4f07059..067b34a 100644 --- a/modeshape-servlet/pom.xml +++ b/modeshape-servlet/pom.xml @@ -112,6 +112,7 @@ com.google.http-client google-http-client ${version.google.http-client} + test diff --git a/modeshape-servlet/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java b/modeshape-servlet/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java index b8eccfa..8997a62 100644 --- a/modeshape-servlet/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java +++ b/modeshape-servlet/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java @@ -13,6 +13,10 @@ import com.google.api.client.http.HttpRequestFactory; import com.google.api.client.http.javanet.NetHttpTransport; +/** + * Arquillian test for {@link RepositoryServlet}. For this to pass, make sure that the active server has a repository + * named "sample". + */ @RunWith(Arquillian.class) @RunAsClient public class RepositoryServletTest { diff --git a/pom.xml b/pom.xml index abb911f..b7d9e89 100644 --- a/pom.xml +++ b/pom.xml @@ -16,5 +16,6 @@ modeshape-servlet + modeshape-ejb From 5ef9f9110b768f34fbf97426e8fe79010bd9ff7d Mon Sep 17 00:00:00 2001 From: Horia Chiorean Date: Thu, 25 Apr 2013 16:10:17 +0300 Subject: [PATCH 05/11] MODE-1695 - Added Arquillian tests for the EJB quickstart, together with CLI scripts which setup and tear down the repository. --- modeshape-ejb/README.md | 27 ++--- modeshape-ejb/pom.xml | 111 ++++++++++++------ .../ejb/controller/EJBController.java | 2 +- modeshape-ejb/src/main/webapp/index.html | 41 ++++--- modeshape-ejb/src/main/webapp/main.xhtml | 35 ++++-- .../beans/RepositoryDescriptorEJBTest.java | 67 +++++++++++ .../ejb/controller/EJBControllerTest.java | 76 ++++++++++++ .../src/test/resources/create-repository.cli | 14 +++ .../src/test/resources/remove-repository.cli | 11 ++ modeshape-servlet/pom.xml | 35 +++--- 10 files changed, 319 insertions(+), 100 deletions(-) create mode 100644 modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptorEJBTest.java create mode 100644 modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/controller/EJBControllerTest.java create mode 100644 modeshape-ejb/src/test/resources/create-repository.cli create mode 100644 modeshape-ejb/src/test/resources/remove-repository.cli diff --git a/modeshape-ejb/README.md b/modeshape-ejb/README.md index 5e4d181..fee4651 100644 --- a/modeshape-ejb/README.md +++ b/modeshape-ejb/README.md @@ -1,12 +1,12 @@ -Example Using ModeShape from a Web Application's Servlet +Example Using ModeShape from different types of EJBs ========================================================= What is it? ----------- -This is a self-contained and deployable Maven 3 project that shows how to get access repository bound in JNDI either via native JCR API or using -JNDI API. +This is a self-contained and deployable Maven 3 project that shows how to get access and use a repository bound in JNDI, from different +types of EJBs via a JSF application. System requirements ------------------- @@ -40,26 +40,23 @@ for help on how to install and configure Maven 3._ mvn clean package jboss-as:deploy -4. This will deploy `target/modeshape-servlet.war` to the running instance of the server. +4. This will deploy `target/modeshape-ejb.war` to the running instance of the server. Accessing the application --------------------- -The application will be running at the following URL: . +The application will be running at the following URL: . Installing the ModeShape kit will add two pre-configured demo repositories: `sample` and `artifacts` (see the `JBOSS_HOME/conf/standalone-modeshape.xml` file for more details). Both repositories are bound by default in JNDI under names: `java:/jcr/sample` and `java:/jcr/artifacts`. -The user is presented with a form where he can input data in two fields: +The user is presented with a form where he can input the name of a repository and select on of the following EJBs: a Stateful Singleton, +a Stateless EJB which uses Container Managed Transactions and a Stateful EJB which uses Bean Managed Transactions. -1. Repository Location - a *mandatory* string, which can have one of the following formats that will dictate the way the repository -is looked up: - `repository_name` - the simple name of a repository which can be located in JNDI at the pre-configured location: java:/jcr/ - `full_repository_jndi_path` - the full JNDI path to a repository - `repository_url` - a url starting with either `jndi:`, `http:`, `file:` and `classpath:` which represents the full path to a repository JSON configuration file -2. Node Path - an *optional* string which represents the full path to a node in a repository. The default value is the root path: _/_ +Based on the user selection, one of the following two actions is delegated to the EJB: -Once the above information is submitted, the form will display the children of the node located at the above path. +1. Describe - displays some meta-information about the repository or shows an error in case the repository cannot be located in JNDI. +2. Count - displays the total number of non-system nodes in a repository or shows an error in case the repository cannot be located in JNDI. Undeploy the Archive -------------------- @@ -79,7 +76,9 @@ This quickstart provides Arquillian tests. By default, these tests are configure 2. Open a command line and navigate to the root directory of this quickstart. 3. Type the following command to run the test goal with the following profile activated: - mvn clean test -Parq-jbossas-remote + mvn clean package -Parq-jbossas-remote + +The above command will create & initialize a test repository, run the existing tests and then remove & clean up the test data. The ModeShape project --------------------- diff --git a/modeshape-ejb/pom.xml b/modeshape-ejb/pom.xml index 0e70e6f..7e344ff 100644 --- a/modeshape-ejb/pom.xml +++ b/modeshape-ejb/pom.xml @@ -26,7 +26,7 @@ 2.6 2.12.3 2.3 - 7.3.Final + 7.4.Final 1.0.4.Final @@ -78,10 +78,6 @@ org.slf4j slf4j-api - - javax.servlet - servlet-api - @@ -98,13 +94,6 @@ provided - - - org.jboss.spec.javax.servlet - jboss-servlet-api_3.0_spec - provided - - org.jboss.spec.javax.faces @@ -132,14 +121,6 @@ junit test - - - com.google.http-client - google-http-client - ${version.google.http-client} - test - - org.jboss.arquillian.junit arquillian-junit-container @@ -159,7 +140,7 @@ - ${project.artifactId}.war + ${project.artifactId} @@ -234,6 +215,7 @@ + default @@ -242,6 +224,24 @@ + + + org.jboss.as.plugins + jboss-as-maven-plugin + + + undeploy + clean + + undeploy + + + true + + + + + maven-surefire-plugin ${version.surefire.plugin} @@ -253,24 +253,10 @@ - - - - arq-jbossas-managed - - - org.jboss.as - jboss-as-arquillian-container-managed - test - - - - - - + arq-jbossas-remote @@ -279,6 +265,53 @@ test + + + + org.jboss.as.plugins + jboss-as-maven-plugin + + + + create-test-repository + + execute-commands + shutdown + + process-test-classes + + true + + + + + + + + + + + remove-test-repository + + execute-commands + + prepare-package + + + + + + + + + + + + diff --git a/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/controller/EJBController.java b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/controller/EJBController.java index 97468c8..e694b7d 100644 --- a/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/controller/EJBController.java +++ b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/controller/EJBController.java @@ -169,7 +169,7 @@ private RepositoryDescriptor selectedEJB() { } } - private enum RepoProvider { + protected enum RepoProvider { SINGLETON("Stateful Singleton EJB"), STATELESS_CMT("Stateless CMT EJB"), STATELESS_BMT("Stateless BMT EJB"); diff --git a/modeshape-ejb/src/main/webapp/index.html b/modeshape-ejb/src/main/webapp/index.html index 961c88d..10a2efd 100644 --- a/modeshape-ejb/src/main/webapp/index.html +++ b/modeshape-ejb/src/main/webapp/index.html @@ -1,23 +1,28 @@ - - + ~ ModeShape (http://www.modeshape.org) + ~ See the COPYRIGHT.txt file distributed with this work for information + ~ regarding copyright ownership. Some portions may be licensed + ~ to Red Hat, Inc. under one or more contributor license agreements. + ~ See the AUTHORS.txt file in the distribution for a full listing of + ~ individual contributors. + ~ + ~ ModeShape is free software. Unless otherwise indicated, all code in ModeShape + ~ is licensed to you under the terms of the GNU Lesser General Public License as + ~ published by the Free Software Foundation; either version 2.1 of + ~ the License, or (at your option) any later version. + ~ + ~ ModeShape is distributed in the hope that it will be useful, + ~ but WITHOUT ANY WARRANTY; without even the implied warranty of + ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + ~ Lesser General Public License for more details. + ~ + ~ You should have received a copy of the GNU Lesser General Public + ~ License along with this software; if not, write to the Free + ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org. + --> - + diff --git a/modeshape-ejb/src/main/webapp/main.xhtml b/modeshape-ejb/src/main/webapp/main.xhtml index c6cefa7..4937d26 100644 --- a/modeshape-ejb/src/main/webapp/main.xhtml +++ b/modeshape-ejb/src/main/webapp/main.xhtml @@ -1,15 +1,26 @@ - + 0); + assertTrue(statelessBMTRepositoryDescriptor.countNodes(TEST_REPOSITORY) > 0); + assertTrue(statelessCMTRepositoryDescriptor.countNodes(TEST_REPOSITORY) > 0); + } +} diff --git a/modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/controller/EJBControllerTest.java b/modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/controller/EJBControllerTest.java new file mode 100644 index 0000000..e3cb87d --- /dev/null +++ b/modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/controller/EJBControllerTest.java @@ -0,0 +1,76 @@ +package org.modeshape.quickstart.ejb.controller; + +import java.io.File; +import javax.inject.Inject; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.modeshape.quickstart.ejb.beans.RepositoryDescriptor; +import org.modeshape.quickstart.ejb.beans.SingletonRepositoryDescriptor; +import org.modeshape.quickstart.ejb.beans.StatelessBMTRepositoryDescriptor; +import org.modeshape.quickstart.ejb.beans.StatelessCMTRepositoryDescriptor; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * Arquillian test which validates the functionality provided by the {@link org.modeshape.quickstart.ejb.controller.EJBController} class + * + * @author Horia Chiorean (hchiorea@redhat.com) + */ +@RunWith(Arquillian.class) +public class EJBControllerTest { + private static final String TEST_REPOSITORY = "test-ejb"; + + @Inject + private EJBController ejbController; + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, "modeshape-ejb-controller-test.war") + .addClass(RepositoryDescriptor.class) + .addClass(SingletonRepositoryDescriptor.class) + .addClass(StatelessBMTRepositoryDescriptor.class) + .addClass(StatelessCMTRepositoryDescriptor.class) + .addClass(EJBController.class) + .addAsWebInfResource(new File("src/test/resources/log4j.properties")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/jboss-deployment-structure.xml")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/faces-config.xml")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/beans.xml")); + } + + @Before + public void beforeEach() { + assertNotNull("EJB Controller not injected", ejbController); + ejbController.setRepositoryName(TEST_REPOSITORY); + } + + @Test + public void shouldDescribeRepository() throws Exception { + retrieveAndAssertDescription(EJBController.RepoProvider.STATELESS_BMT); + retrieveAndAssertDescription(EJBController.RepoProvider.STATELESS_CMT); + retrieveAndAssertDescription(EJBController.RepoProvider.SINGLETON); + } + + private void retrieveAndAssertDescription( EJBController.RepoProvider repoProvider ) { + ejbController.setSelectedEJB(repoProvider.name()); + ejbController.retrieveDescription(); + assertTrue(!ejbController.getRepositoryDescription().isEmpty()); + } + + @Test + public void shouldCountNodesInRepository() throws Exception { + retrieveAndAssertNodesCount(EJBController.RepoProvider.SINGLETON); + retrieveAndAssertNodesCount(EJBController.RepoProvider.STATELESS_CMT); + retrieveAndAssertNodesCount(EJBController.RepoProvider.STATELESS_BMT); + } + + private void retrieveAndAssertNodesCount( EJBController.RepoProvider repoProvider ) { + ejbController.setSelectedEJB(repoProvider.name()); + ejbController.countNodes(); + assertTrue(ejbController.getNodesCount() > 0); + } +} diff --git a/modeshape-ejb/src/test/resources/create-repository.cli b/modeshape-ejb/src/test/resources/create-repository.cli new file mode 100644 index 0000000..afd1c25 --- /dev/null +++ b/modeshape-ejb/src/test/resources/create-repository.cli @@ -0,0 +1,14 @@ +batch +# !! Make sure the modeshape subsystem is installed into the active configuration before running this + +# Setup Infinispan +/subsystem=infinispan/cache-container=modeshape-test:add +/subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb:add +/subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb/transaction=TRANSACTION:add(mode=NON_XA) +/subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb/file-store=FILE_STORE:add(path="modeshape/store/test-ejb",relative-to="jboss.server.data.dir",passivation=false,purge=false) + +# Add the test repository +/subsystem=modeshape/repository=test-ejb:add(cache-container="modeshape-test") + +# Execute but don't reload from here, since we're using the jboss-as-plugin. We need to use that for reloading, so that it's part of the Maven build +run-batch \ No newline at end of file diff --git a/modeshape-ejb/src/test/resources/remove-repository.cli b/modeshape-ejb/src/test/resources/remove-repository.cli new file mode 100644 index 0000000..f39f923 --- /dev/null +++ b/modeshape-ejb/src/test/resources/remove-repository.cli @@ -0,0 +1,11 @@ +batch +# !! Make sure the modeshape subsystem is installed into the active configuration before running this + +# Remove the test repository +/subsystem=modeshape/repository=test-ejb:remove + +# Remove the cache container +/subsystem=infinispan/cache-container=modeshape-test:remove + +# Execute +run-batch \ No newline at end of file diff --git a/modeshape-servlet/pom.xml b/modeshape-servlet/pom.xml index 067b34a..b6945a3 100644 --- a/modeshape-servlet/pom.xml +++ b/modeshape-servlet/pom.xml @@ -26,7 +26,7 @@ 2.6 2.12.3 2.3 - 7.3.Final + 7.4.Final 1.0.4.Final @@ -214,6 +214,24 @@ + + + org.jboss.as.plugins + jboss-as-maven-plugin + + + undeploy + clean + + undeploy + + + true + + + + + maven-surefire-plugin ${version.surefire.plugin} @@ -224,21 +242,6 @@ - - - - - arq-jbossas-managed - - - org.jboss.as - jboss-as-arquillian-container-managed - test - - - From b8ed80e503260df7c1d6290bd31204525ff4cca2 Mon Sep 17 00:00:00 2001 From: Horia Chiorean Date: Fri, 26 Apr 2013 13:27:24 +0300 Subject: [PATCH 06/11] MODE-1695 - Updated CLI scripts and readmes. --- modeshape-ejb/README.md | 2 +- modeshape-ejb/pom.xml | 114 ++++++++---------- .../src/main/resources/create-repository.cli | 23 ++++ .../src/main/resources/remove-repository.cli | 10 ++ .../beans/RepositoryDescriptorEJBTest.java | 2 +- .../ejb/controller/EJBControllerTest.java | 2 +- .../src/test/resources/create-repository.cli | 14 --- .../src/test/resources/remove-repository.cli | 11 -- modeshape-servlet/README.md | 2 +- 9 files changed, 86 insertions(+), 94 deletions(-) create mode 100644 modeshape-ejb/src/main/resources/create-repository.cli create mode 100644 modeshape-ejb/src/main/resources/remove-repository.cli delete mode 100644 modeshape-ejb/src/test/resources/create-repository.cli delete mode 100644 modeshape-ejb/src/test/resources/remove-repository.cli diff --git a/modeshape-ejb/README.md b/modeshape-ejb/README.md index fee4651..225bf3a 100644 --- a/modeshape-ejb/README.md +++ b/modeshape-ejb/README.md @@ -23,7 +23,7 @@ Start JBoss EAP with the ModeShape configuration -------------------------------------------------------------------------------- 1. Open a command line and navigate to the root of the JBoss server directory. -2. The following shows the command line to start the server with the web profile: +2. The following shows the command line to start the server with the ModeShape profile: For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-modeshape.xml For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-modeshape.xml diff --git a/modeshape-ejb/pom.xml b/modeshape-ejb/pom.xml index 7e344ff..ec77e95 100644 --- a/modeshape-ejb/pom.xml +++ b/modeshape-ejb/pom.xml @@ -209,6 +209,55 @@ + + + + @@ -224,24 +273,6 @@ - - - org.jboss.as.plugins - jboss-as-maven-plugin - - - undeploy - clean - - undeploy - - - true - - - - - maven-surefire-plugin ${version.surefire.plugin} @@ -265,53 +296,6 @@ test - - - - org.jboss.as.plugins - jboss-as-maven-plugin - - - - create-test-repository - - execute-commands - shutdown - - process-test-classes - - true - - - - - - - - - - - remove-test-repository - - execute-commands - - prepare-package - - - - - - - - - - - - diff --git a/modeshape-ejb/src/main/resources/create-repository.cli b/modeshape-ejb/src/main/resources/create-repository.cli new file mode 100644 index 0000000..9f361cd --- /dev/null +++ b/modeshape-ejb/src/main/resources/create-repository.cli @@ -0,0 +1,23 @@ +# Check if the ModeShape extension is present and if not, add it +if (outcome != success) of /extension=org.modeshape:read-resource + /extension=org.modeshape:add() +end-if + +# Check if the ModeShape subsystem needs creating +if (outcome != success) of /subsystem=modeshape:read-resource + /subsystem=modeshape:add +end-if + +# Check if the test setup needs creating +if (outcome != success) of /subsystem=infinispan/cache-container=modeshape-test:read-resource + # Setup Infinispan + /subsystem=infinispan/cache-container=modeshape-test:add + /subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb:add + /subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb/transaction=TRANSACTION:add(mode=NON_XA) + /subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb/file-store=FILE_STORE:add(path="modeshape/store/test-ejb",relative-to="jboss.server.data.dir",passivation=false,purge=false) +end-if + +# Add the test repository +if (outcome != success) of /subsystem=modeshape/repository=test-ejb:read-resource + /subsystem=modeshape/repository=test-ejb:add(cache-container="modeshape-test") +end-if diff --git a/modeshape-ejb/src/main/resources/remove-repository.cli b/modeshape-ejb/src/main/resources/remove-repository.cli new file mode 100644 index 0000000..b9a5c0d --- /dev/null +++ b/modeshape-ejb/src/main/resources/remove-repository.cli @@ -0,0 +1,10 @@ +# Remove the test repository if it exists +if (outcome == success) of /subsystem=modeshape/repository=test-ejb:read-resource + /subsystem=modeshape/repository=test-ejb:remove +end-if + +# Remove the Infinispan cache container +if (outcome == success) of /subsystem=infinispan/cache-container=modeshape-test:read-resource + # Setup Infinispan + /subsystem=infinispan/cache-container=modeshape-test:remove +end-if \ No newline at end of file diff --git a/modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptorEJBTest.java b/modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptorEJBTest.java index ae33cfc..3440c3e 100644 --- a/modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptorEJBTest.java +++ b/modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptorEJBTest.java @@ -21,7 +21,7 @@ @RunWith(Arquillian.class) public class RepositoryDescriptorEJBTest { - private static final String TEST_REPOSITORY = "test-ejb"; + private static final String TEST_REPOSITORY = "sample"; @EJB private SingletonRepositoryDescriptor singletonRepositoryDescriptor; diff --git a/modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/controller/EJBControllerTest.java b/modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/controller/EJBControllerTest.java index e3cb87d..7056c21 100644 --- a/modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/controller/EJBControllerTest.java +++ b/modeshape-ejb/src/test/java/org/modeshape/quickstart/ejb/controller/EJBControllerTest.java @@ -23,7 +23,7 @@ */ @RunWith(Arquillian.class) public class EJBControllerTest { - private static final String TEST_REPOSITORY = "test-ejb"; + private static final String TEST_REPOSITORY = "sample"; @Inject private EJBController ejbController; diff --git a/modeshape-ejb/src/test/resources/create-repository.cli b/modeshape-ejb/src/test/resources/create-repository.cli deleted file mode 100644 index afd1c25..0000000 --- a/modeshape-ejb/src/test/resources/create-repository.cli +++ /dev/null @@ -1,14 +0,0 @@ -batch -# !! Make sure the modeshape subsystem is installed into the active configuration before running this - -# Setup Infinispan -/subsystem=infinispan/cache-container=modeshape-test:add -/subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb:add -/subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb/transaction=TRANSACTION:add(mode=NON_XA) -/subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb/file-store=FILE_STORE:add(path="modeshape/store/test-ejb",relative-to="jboss.server.data.dir",passivation=false,purge=false) - -# Add the test repository -/subsystem=modeshape/repository=test-ejb:add(cache-container="modeshape-test") - -# Execute but don't reload from here, since we're using the jboss-as-plugin. We need to use that for reloading, so that it's part of the Maven build -run-batch \ No newline at end of file diff --git a/modeshape-ejb/src/test/resources/remove-repository.cli b/modeshape-ejb/src/test/resources/remove-repository.cli deleted file mode 100644 index f39f923..0000000 --- a/modeshape-ejb/src/test/resources/remove-repository.cli +++ /dev/null @@ -1,11 +0,0 @@ -batch -# !! Make sure the modeshape subsystem is installed into the active configuration before running this - -# Remove the test repository -/subsystem=modeshape/repository=test-ejb:remove - -# Remove the cache container -/subsystem=infinispan/cache-container=modeshape-test:remove - -# Execute -run-batch \ No newline at end of file diff --git a/modeshape-servlet/README.md b/modeshape-servlet/README.md index 5e4d181..47ffc97 100644 --- a/modeshape-servlet/README.md +++ b/modeshape-servlet/README.md @@ -23,7 +23,7 @@ Start JBoss EAP with the ModeShape configuration -------------------------------------------------------------------------------- 1. Open a command line and navigate to the root of the JBoss server directory. -2. The following shows the command line to start the server with the web profile: +2. The following shows the command line to start the server with the ModeShape profile: For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-modeshape.xml For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-modeshape.xml From 179b80273562e666857716e4ff14f53dfc887ab9 Mon Sep 17 00:00:00 2001 From: Horia Chiorean Date: Fri, 26 Apr 2013 16:54:59 +0300 Subject: [PATCH 07/11] MODE-1695 - Added modeshape-cdi quickstart. Also, reverted all logging back to log4j. --- modeshape-cdi/README.md | 120 ++++++++ modeshape-cdi/pom.xml | 266 ++++++++++++++++++ modeshape-cdi/settings.xml | 48 ++++ .../quickstart/cdi/CDIController.java | 124 ++++++++ .../quickstart/cdi/SessionProducer.java | 46 +++ .../src/main/webapp/WEB-INF/beans.xml | 18 ++ .../src/main/webapp/WEB-INF/faces-config.xml | 20 ++ .../WEB-INF/jboss-deployment-structure.xml | 10 + .../src/main/webapp/WEB-INF/jboss-web.xml | 6 + modeshape-cdi/src/main/webapp/index.html | 28 ++ modeshape-cdi/src/main/webapp/main.xhtml | 73 +++++ .../src/test/resources/arquillian.xml | 32 +++ modeshape-ejb/README.md | 6 +- modeshape-ejb/pom.xml | 77 +++-- .../ejb/beans/RepositoryDescriptor.java | 5 +- .../src/main/resources/log4j.properties | 9 - .../WEB-INF/jboss-deployment-structure.xml | 1 + .../src/test/resources/log4j.properties | 23 -- modeshape-servlet/README.md | 2 + modeshape-servlet/pom.xml | 4 +- .../quickstart/servlet/RepositoryServlet.java | 11 +- .../src/main/resources/log4j.properties | 9 - .../WEB-INF/jboss-deployment-structure.xml | 1 + .../src/test/resources/log4j.properties | 23 -- pom.xml | 1 + 25 files changed, 861 insertions(+), 102 deletions(-) create mode 100644 modeshape-cdi/README.md create mode 100644 modeshape-cdi/pom.xml create mode 100644 modeshape-cdi/settings.xml create mode 100644 modeshape-cdi/src/main/java/org/modeshape/quickstart/cdi/CDIController.java create mode 100644 modeshape-cdi/src/main/java/org/modeshape/quickstart/cdi/SessionProducer.java create mode 100644 modeshape-cdi/src/main/webapp/WEB-INF/beans.xml create mode 100644 modeshape-cdi/src/main/webapp/WEB-INF/faces-config.xml create mode 100644 modeshape-cdi/src/main/webapp/WEB-INF/jboss-deployment-structure.xml create mode 100644 modeshape-cdi/src/main/webapp/WEB-INF/jboss-web.xml create mode 100644 modeshape-cdi/src/main/webapp/index.html create mode 100644 modeshape-cdi/src/main/webapp/main.xhtml create mode 100644 modeshape-cdi/src/test/resources/arquillian.xml delete mode 100644 modeshape-ejb/src/main/resources/log4j.properties delete mode 100644 modeshape-ejb/src/test/resources/log4j.properties delete mode 100644 modeshape-servlet/src/main/resources/log4j.properties delete mode 100644 modeshape-servlet/src/test/resources/log4j.properties diff --git a/modeshape-cdi/README.md b/modeshape-cdi/README.md new file mode 100644 index 0000000..6974ce2 --- /dev/null +++ b/modeshape-cdi/README.md @@ -0,0 +1,120 @@ +Example Using ModeShape from a JSF application via CDI +========================================================= + + +What is it? +----------- + +This is a self-contained and deployable Maven 3 project that shows how to get access and use a repository bound in JNDI, from +a JSF application, using only CDI. + +System requirements +------------------- + +All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better. +The application this project produces is designed to be run on JBoss Enterprise Application Platform 6. + +Install ModeShape's EAP kit into an existing JBoss EAP 6 server +----------------------------------------------------- +Before running this demo make sure that you have installed the ModeShape EAP kit into an existing JBoss EAP server. +The simplest way to do this is to follow the instructions provided [here](https://docs.jboss.org/author/display/MODE/Installing+ModeShape+into+AS7) + +Start JBoss EAP with the ModeShape configuration +-------------------------------------------------------------------------------- + +1. Open a command line and navigate to the root of the JBoss server directory. +2. The following shows the command line to start the server with the ModeShape profile: + + For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-modeshape.xml + For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-modeshape.xml + +Build and Deploy the Quickstart +------------------------- +_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must use the `settings.xml` +file from the root of this project. See [this ModeShape community article](http://community.jboss.org/wiki/ModeShapeandMaven) +for help on how to install and configure Maven 3._ + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. Type this command to build and deploy the archive: + + mvn clean package jboss-as:deploy + +4. This will deploy `target/modeshape-cdi.war` to the running instance of the server. + +Accessing the application +--------------------- + +The application will be running at the following URL: . + +Installing the ModeShape kit will add a preconfigured repository named `sample` which will be used by this example (see the `JBOSS_HOME/conf/standalone-modeshape.xml` file for more details). + +The user is presented with a form where he can input one of the following: + +1. Parent Absolute Path - an absolute node path +2. New Node Name - a simple string which represents the name of new node that can be added + +based on which one of the following actions can be performed + +1. Show children - displays the children of node located at "Parent Absolute Path" +2. Add Node - add a new child with the given name under the node located at "Parent Absolute Path" + +Undeploy the Archive +-------------------- + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. When you are finished testing, type this command to undeploy the archive: + + mvn jboss-as:undeploy + +4. The archive is also undeployed each time the following command is issued: + + mvn clean + +Run the Arquillian Tests +------------------------- + +This quickstart provides Arquillian tests. By default, these tests are configured to be skipped as Arquillian tests require the use of a container. + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. Type the following command to run the test goal with the following profile activated: + + mvn clean package -Parq-jbossas-remote + +The above command will run the tests using the predefined repository named `sample` (see above). + +The ModeShape project +--------------------- +ModeShape is an open source implementation of the JCR 2.0 +([JSR-283](http://www.jcp.org/en/jsr/detail?id=283])) specification and +standard API. To your applications, ModeShape looks and behaves like a +regular JCR repository. Applications can search, query, navigate, change, +version, listen for changes, etc. But ModeShape can store that content +in a variety of back-end stores (including relational databases, Infinispan +data grids, JBoss Cache, etc.), or it can access and update existing content +from *other* kinds of systems (including file systems, SVN repositories, +JDBC database metadata, and other JCR repositories). ModeShape's connector +architecture means that you can write custom connectors to access any +kind of system. And ModeShape can even federate multiple back-end systems +into a single, unified virtual repository. + +For more information on ModeShape, including getting started guides, +reference guides, and downloadable binaries, visit the project's website +at [http://www.modeshape.org]() or follow us on our [blog](http://modeshape.wordpress.org) +or on [Twitter](http://twitter.com/modeshape). Or hop into our +[IRC chat room](http://www.jboss.org/modeshape/chat) and talk our community +of contributors and users. + +The official Git repository for the project is also on GitHub at +[http://github.com/ModeShape/modeshape](). + +Need help ? +----------- + +ModeShape is open source software with a dedicated community. If you have +any questions or problems, post a question in our +[user forum](http://community.jboss.org/en/modeshape) or hop into our +[IRC chat room](http://www.jboss.org/modeshape/chat) and talk our +community of contributors and users. diff --git a/modeshape-cdi/pom.xml b/modeshape-cdi/pom.xml new file mode 100644 index 0000000..486a0a2 --- /dev/null +++ b/modeshape-cdi/pom.xml @@ -0,0 +1,266 @@ + + + 4.0.0 + org.modeshape.quickstarts + modeshape-cdi + 1.0-SNAPSHOT + war + Example of a JSF web application that uses ModeShape via CDI + + A simple self-contained JSF web application that injects a ModeShape repository via CDI and performs various operations. + + + + UTF-8 + 1.6 + 1.6 + + + 2.4 + 2.5 + 3.0 + 2.6 + 2.4 + 2.4 + 2.6 + 2.12.3 + 2.3 + 7.4.Final + + + 1.0.4.Final + 3.2.0.Final + + + + + + + org.jboss.bom + jboss-javaee-6.0-with-tools + ${version.org.jboss.bom} + pom + import + + + + + org.modeshape.bom + modeshape-bom-jbosseap + ${version.modeshape} + pom + import + + + + + + + javax.jcr + jcr + + + + org.modeshape + modeshape-jcr-api + + + + log4j + log4j + + + + + javax.enterprise + cdi-api + provided + + + + + org.jboss.spec.javax.annotation + jboss-annotations-api_1.1_spec + provided + + + + + org.jboss.spec.javax.faces + jboss-jsf-api_2.1_spec + provided + + + + + junit + junit + test + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.jboss.arquillian.protocol + arquillian-protocol-servlet + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-depchain + pom + test + + + + + ${project.artifactId} + + + + + org.apache.maven.plugins + maven-assembly-plugin + ${version.assembly.plugin} + + + org.apache.maven.plugins + maven-clean-plugin + ${version.clean.plugin} + + + org.apache.maven.plugins + maven-compiler-plugin + ${version.compiler.plugin} + + false + false + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + org.apache.maven.plugins + maven-dependency-plugin + ${version.dependency.plugin} + + + org.apache.maven.plugins + maven-install-plugin + ${version.install.plugin} + + + org.apache.maven.plugins + maven-jar-plugin + ${version.jar.plugin} + + + org.apache.maven.plugins + maven-resources-plugin + ${version.resources.plugin} + + + org.apache.maven.plugins + maven-surefire-plugin + ${version.surefire.plugin} + + + org.apache.maven.plugins + maven-war-plugin + ${version.war.plugin} + + false + + + + + + org.jboss.as.plugins + jboss-as-maven-plugin + ${version.org.jboss.as.plugins.maven.plugin} + + + + + + + org.jboss.as.plugins + jboss-as-maven-plugin + + + + undeploy + clean + + undeploy + + + true + true + + false + + + + + + + + + + + + + + + + + default + + true + + + + + maven-surefire-plugin + ${version.surefire.plugin} + + true + + + + + + + + arq-jbossas-remote + + + org.jboss.as + jboss-as-arquillian-container-remote + test + + + + + diff --git a/modeshape-cdi/settings.xml b/modeshape-cdi/settings.xml new file mode 100644 index 0000000..fc2ab66 --- /dev/null +++ b/modeshape-cdi/settings.xml @@ -0,0 +1,48 @@ + + + + + jboss-public-repository + + + jboss-public-repository-group + JBoss Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + default + + true + never + + + true + never + + + + + + jboss-public-repository-group + JBoss Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + default + + true + never + + + true + never + + + + + + + + jboss-public-repository + + + diff --git a/modeshape-cdi/src/main/java/org/modeshape/quickstart/cdi/CDIController.java b/modeshape-cdi/src/main/java/org/modeshape/quickstart/cdi/CDIController.java new file mode 100644 index 0000000..39e313b --- /dev/null +++ b/modeshape-cdi/src/main/java/org/modeshape/quickstart/cdi/CDIController.java @@ -0,0 +1,124 @@ +package org.modeshape.quickstart.cdi; + +import java.util.Collections; +import java.util.Set; +import java.util.TreeSet; +import javax.enterprise.context.RequestScoped; +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; +import javax.inject.Inject; +import javax.inject.Named; +import javax.jcr.Node; +import javax.jcr.NodeIterator; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +/** + * A simple JSF controller, that uses CDI to obtain a {@link SessionProducer} instance with which it performs some operations. + * + * @author Horia Chiorean (hchiorea@redhat.com) + */ +@Named( "cdiController" ) +@RequestScoped +public class CDIController { + + @Inject + private Session repositorySession; + + private String parentPath = "/"; + private String newNodeName; + + private Set children = Collections.emptySet(); + + /** + * Sets a name for a new node to create. + * + * @param newNodeName a {@code non-null} string + */ + public void setNewNodeName( String newNodeName ) { + this.newNodeName = newNodeName; + } + + /** + * Returns the name of a new node which can be created. + * + * @return a {@code non-null} string + */ + public String getNewNodeName() { + return newNodeName; + } + + /** + * Returns the absolute path of a parent node + * + * @return a {@code non-null} string + */ + public String getParentPath() { + return parentPath; + } + + /** + * Sets the absolute path of a parent node. + * + * @param parentPath a {@code non-null} string + */ + public void setParentPath( String parentPath ) { + this.parentPath = parentPath; + } + + /** + * Returns the children nodes of the node located at {@link CDIController#parentPath} + * + * @return a Set containing the paths of the children. + */ + public Set getChildren() { + return children; + } + + /** + * Loads the children nodes of the node located at {@link CDIController#parentPath} + */ + public void loadChildren() { + children = new TreeSet(); + if (parentPath == null || parentPath.trim().length() == 0) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage( + "The absolute path of the parent node is required")); + } else { + try { + Node parentNode = repositorySession.getNode(parentPath); + for (NodeIterator nodeIterator = parentNode.getNodes(); nodeIterator.hasNext(); ) { + children.add(nodeIterator.nextNode().getPath()); + } + } catch (RepositoryException e) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + } + } + } + + /** + * Adds a child node at {@link CDIController#parentPath} which has the name {@link CDIController#newNodeName} + */ + public void addChildNode() { + if (newNodeName == null || newNodeName.trim().length() == 0) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("The name of the new node is required")); + } else { + try { + Node parentNode = repositorySession.getNode(parentPath); + parentNode.addNode(newNodeName); + repositorySession.save(); + } catch (RepositoryException e) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + } + } + loadChildren(); + } + + /** + * Returns the name of the repository to which the session is bound. + * + * @return a non-null string. + */ + public String getRepositoryName() { + return repositorySession.getRepository().getDescriptor(org.modeshape.jcr.api.Repository.REPOSITORY_NAME); + } +} diff --git a/modeshape-cdi/src/main/java/org/modeshape/quickstart/cdi/SessionProducer.java b/modeshape-cdi/src/main/java/org/modeshape/quickstart/cdi/SessionProducer.java new file mode 100644 index 0000000..e0607e8 --- /dev/null +++ b/modeshape-cdi/src/main/java/org/modeshape/quickstart/cdi/SessionProducer.java @@ -0,0 +1,46 @@ +package org.modeshape.quickstart.cdi; + +import javax.annotation.Resource; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Disposes; +import javax.enterprise.inject.Produces; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import org.apache.log4j.Logger; + +/** + * A simple managed bean, that provides clients with {@link javax.jcr.Session} instances. + * + * @author Horia Chiorean (hchiorea@redhat.com) + */ +public class SessionProducer { + + private static final Logger LOGGER = Logger.getLogger(SessionProducer.class); + + @Resource(mappedName = "java:/jcr/sample") + private Repository sampleRepository; + + /** + * Producer method which returns a default session to the preconfigured repository. + * + * @return a {@link Session} instance + * @throws RepositoryException if anything goes wrong + */ + @RequestScoped + @Produces + public Session getSession() throws RepositoryException { + LOGGER.info("Creating new session..."); + return sampleRepository.login(); + } + + /** + * Disposer method for {@link org.modeshape.quickstart.cdi.SessionProducer#getSession()} + * + * @param session the {@link Session} created by the producer method + */ + public void logoutSession( @Disposes final Session session ) { + LOGGER.info("Closing session..."); + session.logout(); + } +} diff --git a/modeshape-cdi/src/main/webapp/WEB-INF/beans.xml b/modeshape-cdi/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..3f9d20e --- /dev/null +++ b/modeshape-cdi/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,18 @@ + + + + + diff --git a/modeshape-cdi/src/main/webapp/WEB-INF/faces-config.xml b/modeshape-cdi/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000..fbe54e5 --- /dev/null +++ b/modeshape-cdi/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/modeshape-cdi/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/modeshape-cdi/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000..4b3b7d9 --- /dev/null +++ b/modeshape-cdi/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/modeshape-cdi/src/main/webapp/WEB-INF/jboss-web.xml b/modeshape-cdi/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000..521bb51 --- /dev/null +++ b/modeshape-cdi/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,6 @@ + + + + /modeshape-cdi + + diff --git a/modeshape-cdi/src/main/webapp/index.html b/modeshape-cdi/src/main/webapp/index.html new file mode 100644 index 0000000..10a2efd --- /dev/null +++ b/modeshape-cdi/src/main/webapp/index.html @@ -0,0 +1,28 @@ + + + + + + diff --git a/modeshape-cdi/src/main/webapp/main.xhtml b/modeshape-cdi/src/main/webapp/main.xhtml new file mode 100644 index 0000000..88214df --- /dev/null +++ b/modeshape-cdi/src/main/webapp/main.xhtml @@ -0,0 +1,73 @@ + + + + + + + ModeShape CDI Example + + + + +

    ModeShape CDI Example

    + +
    + + + + + + + Repository Name: + + + Parent Absolute Path: + + + New Node Name: + + + + + + + + + + + + + + + + +
    + + + \ No newline at end of file diff --git a/modeshape-cdi/src/test/resources/arquillian.xml b/modeshape-cdi/src/test/resources/arquillian.xml new file mode 100644 index 0000000..01c6040 --- /dev/null +++ b/modeshape-cdi/src/test/resources/arquillian.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/modeshape-ejb/README.md b/modeshape-ejb/README.md index 225bf3a..3316ab3 100644 --- a/modeshape-ejb/README.md +++ b/modeshape-ejb/README.md @@ -67,6 +67,10 @@ Undeploy the Archive mvn jboss-as:undeploy +4. The archive is also undeployed each time the following command is issued: + + mvn clean + Run the Arquillian Tests ------------------------- @@ -78,7 +82,7 @@ This quickstart provides Arquillian tests. By default, these tests are configure mvn clean package -Parq-jbossas-remote -The above command will create & initialize a test repository, run the existing tests and then remove & clean up the test data. +The above command will run the tests using the predefined repository named `sample` (see above). The ModeShape project --------------------- diff --git a/modeshape-ejb/pom.xml b/modeshape-ejb/pom.xml index ec77e95..461a423 100644 --- a/modeshape-ejb/pom.xml +++ b/modeshape-ejb/pom.xml @@ -75,8 +75,8 @@ modeshape-jcr-api - org.slf4j - slf4j-api + log4j + log4j @@ -211,19 +211,16 @@ - undeploy clean undeploy - execute-commands - shutdown true @@ -236,27 +233,55 @@ - - Create the test repository and ISPN caches, and reload the repository - - create-test-repository - - execute-commands - shutdown - - validate - - true - - - - - - - - --> + + diff --git a/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptor.java b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptor.java index e80516c..bc56910 100644 --- a/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptor.java +++ b/modeshape-ejb/src/main/java/org/modeshape/quickstart/ejb/beans/RepositoryDescriptor.java @@ -30,16 +30,15 @@ import javax.jcr.Session; import javax.naming.InitialContext; import javax.naming.NamingException; +import org.apache.log4j.Logger; import org.modeshape.jcr.api.JcrTools; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * A utility class that describes a repository after looking it up in JNDI. */ public abstract class RepositoryDescriptor { - protected Logger log = LoggerFactory.getLogger(getClass()); + protected Logger log = Logger.getLogger(getClass()); protected JcrTools jcrTools = new JcrTools(); /** diff --git a/modeshape-ejb/src/main/resources/log4j.properties b/modeshape-ejb/src/main/resources/log4j.properties deleted file mode 100644 index 764338a..0000000 --- a/modeshape-ejb/src/main/resources/log4j.properties +++ /dev/null @@ -1,9 +0,0 @@ -log4j.rootLogger = INFO, stdout - -log4j.category.org.apache=INFO -log4j.category.org.slf4j.impl.JCLLoggerAdapter=INFO - -log4j.appender.stdout = org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target = System.out -log4j.appender.stdout.layout = org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern = [%-5p] [%C] : %m%n [%F:%L] diff --git a/modeshape-ejb/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/modeshape-ejb/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 4d773af..4b3b7d9 100644 --- a/modeshape-ejb/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/modeshape-ejb/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -4,6 +4,7 @@ + diff --git a/modeshape-ejb/src/test/resources/log4j.properties b/modeshape-ejb/src/test/resources/log4j.properties deleted file mode 100644 index 8bc3a0c..0000000 --- a/modeshape-ejb/src/test/resources/log4j.properties +++ /dev/null @@ -1,23 +0,0 @@ -# Direct log messages to stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n - -# Root logger option -log4j.rootLogger=WARN, stdout - -# Set up the default logging to be INFO level, then override specific units -log4j.logger.org.modeshape=INFO -log4j.logger.org.junit=DEBUG -log4j.logger.org.hibernate=WARN -log4j.logger.org.hibernate.pretty.Printer=WARN -log4j.logger.org.hibernate.engine.Collections=WARN -log4j.logger.org.hibernate.cfg=WARN -log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=WARN -log4j.logger.org.hibernate.persister.entity.AbstractEntityPersister=WARN -log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=WARN -log4j.logger.org.hibernate.engine.TwoPhaseLoad=WARN -log4j.logger.org.hibernate.jdbc.AbstractBatcher=WARN -log4j.logger.org.hibernate.hql.ast=WARN -log4j.logger.org.hibernate.engine.loading.CollectionLoadContext=WARN \ No newline at end of file diff --git a/modeshape-servlet/README.md b/modeshape-servlet/README.md index 47ffc97..573678c 100644 --- a/modeshape-servlet/README.md +++ b/modeshape-servlet/README.md @@ -81,6 +81,8 @@ This quickstart provides Arquillian tests. By default, these tests are configure mvn clean test -Parq-jbossas-remote +The above command will run the tests using the predefined repository named `sample` (see above). + The ModeShape project --------------------- ModeShape is an open source implementation of the JCR 2.0 diff --git a/modeshape-servlet/pom.xml b/modeshape-servlet/pom.xml index b6945a3..a98dc0e 100644 --- a/modeshape-servlet/pom.xml +++ b/modeshape-servlet/pom.xml @@ -71,8 +71,8 @@ jcr - org.slf4j - slf4j-api + log4j + log4j javax.servlet diff --git a/modeshape-servlet/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java b/modeshape-servlet/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java index cec0252..857ad16 100644 --- a/modeshape-servlet/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java +++ b/modeshape-servlet/src/main/java/org/modeshape/quickstart/servlet/RepositoryServlet.java @@ -36,8 +36,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.log4j.Logger; /** * Demo for using JCR from web application. This example application accepts a "repository" parameter and a "path" parameter, @@ -55,7 +54,7 @@ public class RepositoryServlet extends HttpServlet { private static final long serialVersionUID = 1L; - private static final Logger LOGGER = LoggerFactory.getLogger(RepositoryServlet.class); + private static final Logger LOGGER = Logger.getLogger(RepositoryServlet.class); protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws IOException { @@ -70,7 +69,7 @@ protected void doGet( HttpServletRequest request, // establish jcr session ... jcrSession = repository.login(); - LOGGER.info("Session established successfully to repository at: {0}", repositoryLocation); + LOGGER.info("Session established successfully to repository at: " + repositoryLocation); // get the path of the node String path = storeRequestParameterIntoSession(request, NODE_PATH_PARAM, "/"); @@ -135,7 +134,7 @@ private Repository searchURL( String location ) throws RepositoryException { private Repository searchJNDI( String location ) { Repository repository = null; try { - LOGGER.debug("Searching in JNDI directly at: {0}", location); + LOGGER.debug("Searching in JNDI directly at: " + location); InitialContext ic = new InitialContext(); repository = (Repository)ic.lookup(location); } catch (NamingException e) { @@ -145,7 +144,7 @@ private Repository searchJNDI( String location ) { if (repository == null) { location = "java:/jcr/" + location; try { - LOGGER.debug("Searching in JNDI directly at: {0}", location); + LOGGER.debug("Searching in JNDI directly at: " + location); InitialContext ic = new InitialContext(); repository = (Repository)ic.lookup(location); } catch (NamingException e) { diff --git a/modeshape-servlet/src/main/resources/log4j.properties b/modeshape-servlet/src/main/resources/log4j.properties deleted file mode 100644 index 764338a..0000000 --- a/modeshape-servlet/src/main/resources/log4j.properties +++ /dev/null @@ -1,9 +0,0 @@ -log4j.rootLogger = INFO, stdout - -log4j.category.org.apache=INFO -log4j.category.org.slf4j.impl.JCLLoggerAdapter=INFO - -log4j.appender.stdout = org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target = System.out -log4j.appender.stdout.layout = org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern = [%-5p] [%C] : %m%n [%F:%L] diff --git a/modeshape-servlet/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/modeshape-servlet/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 4d773af..4b3b7d9 100644 --- a/modeshape-servlet/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/modeshape-servlet/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -4,6 +4,7 @@ + diff --git a/modeshape-servlet/src/test/resources/log4j.properties b/modeshape-servlet/src/test/resources/log4j.properties deleted file mode 100644 index 8bc3a0c..0000000 --- a/modeshape-servlet/src/test/resources/log4j.properties +++ /dev/null @@ -1,23 +0,0 @@ -# Direct log messages to stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n - -# Root logger option -log4j.rootLogger=WARN, stdout - -# Set up the default logging to be INFO level, then override specific units -log4j.logger.org.modeshape=INFO -log4j.logger.org.junit=DEBUG -log4j.logger.org.hibernate=WARN -log4j.logger.org.hibernate.pretty.Printer=WARN -log4j.logger.org.hibernate.engine.Collections=WARN -log4j.logger.org.hibernate.cfg=WARN -log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=WARN -log4j.logger.org.hibernate.persister.entity.AbstractEntityPersister=WARN -log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=WARN -log4j.logger.org.hibernate.engine.TwoPhaseLoad=WARN -log4j.logger.org.hibernate.jdbc.AbstractBatcher=WARN -log4j.logger.org.hibernate.hql.ast=WARN -log4j.logger.org.hibernate.engine.loading.CollectionLoadContext=WARN \ No newline at end of file diff --git a/pom.xml b/pom.xml index b7d9e89..dafae89 100644 --- a/pom.xml +++ b/pom.xml @@ -17,5 +17,6 @@ modeshape-servlet modeshape-ejb + modeshape-cdi From e107e87e665fea64cc3ef149a1422f8334f740d3 Mon Sep 17 00:00:00 2001 From: Horia Chiorean Date: Mon, 29 Apr 2013 16:37:20 +0300 Subject: [PATCH 08/11] MODE-1695 - Added modeshape-cli quickstart, together with Arquillian tests for the modeshape-cdi quickstart. --- .../quickstart/cdi/CDIControllerTest.java | 62 ++++ .../quickstart/cdi/SessionProducerTest.java | 39 +++ .../src/test/resources/log4j.properties | 23 ++ modeshape-cli/README.md | 123 +++++++ modeshape-cli/pom.xml | 308 ++++++++++++++++++ modeshape-cli/settings.xml | 48 +++ .../quickstart/cli/CLIController.java | 53 +++ .../src/main/resources/create-repository.cli | 12 +- .../src/main/resources/remove-repository.cli | 8 +- .../src/main/webapp/WEB-INF/beans.xml | 18 + .../src/main/webapp/WEB-INF/faces-config.xml | 20 ++ .../WEB-INF/jboss-deployment-structure.xml | 10 + .../src/main/webapp/WEB-INF/jboss-web.xml | 6 + modeshape-cli/src/main/webapp/index.html | 28 ++ modeshape-cli/src/main/webapp/main.xhtml | 59 ++++ .../quickstart/cli/CLIControllerTest.java | 40 +++ .../src/test/resources/arquillian.xml | 32 ++ .../src/test/resources/log4j.properties | 23 ++ modeshape-ejb/pom.xml | 54 --- .../src/test/resources/log4j.properties | 23 ++ .../servlet/RepositoryServletTest.java | 2 +- .../src/test/resources/log4j.properties | 23 ++ pom.xml | 3 +- 23 files changed, 953 insertions(+), 64 deletions(-) create mode 100644 modeshape-cdi/src/test/java/org/modeshape/quickstart/cdi/CDIControllerTest.java create mode 100644 modeshape-cdi/src/test/java/org/modeshape/quickstart/cdi/SessionProducerTest.java create mode 100644 modeshape-cdi/src/test/resources/log4j.properties create mode 100644 modeshape-cli/README.md create mode 100644 modeshape-cli/pom.xml create mode 100644 modeshape-cli/settings.xml create mode 100644 modeshape-cli/src/main/java/org/modeshape/quickstart/cli/CLIController.java rename {modeshape-ejb => modeshape-cli}/src/main/resources/create-repository.cli (74%) rename {modeshape-ejb => modeshape-cli}/src/main/resources/remove-repository.cli (79%) create mode 100644 modeshape-cli/src/main/webapp/WEB-INF/beans.xml create mode 100644 modeshape-cli/src/main/webapp/WEB-INF/faces-config.xml create mode 100644 modeshape-cli/src/main/webapp/WEB-INF/jboss-deployment-structure.xml create mode 100644 modeshape-cli/src/main/webapp/WEB-INF/jboss-web.xml create mode 100644 modeshape-cli/src/main/webapp/index.html create mode 100644 modeshape-cli/src/main/webapp/main.xhtml create mode 100644 modeshape-cli/src/test/java/org/modeshape/quickstart/cli/CLIControllerTest.java create mode 100644 modeshape-cli/src/test/resources/arquillian.xml create mode 100644 modeshape-cli/src/test/resources/log4j.properties create mode 100644 modeshape-ejb/src/test/resources/log4j.properties create mode 100644 modeshape-servlet/src/test/resources/log4j.properties diff --git a/modeshape-cdi/src/test/java/org/modeshape/quickstart/cdi/CDIControllerTest.java b/modeshape-cdi/src/test/java/org/modeshape/quickstart/cdi/CDIControllerTest.java new file mode 100644 index 0000000..df639e4 --- /dev/null +++ b/modeshape-cdi/src/test/java/org/modeshape/quickstart/cdi/CDIControllerTest.java @@ -0,0 +1,62 @@ +package org.modeshape.quickstart.cdi; + +import java.io.File; +import javax.inject.Inject; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * Arquillian test for {@link CDIController} + * + * @author Horia Chiorean (hchiorea@redhat.com) + */ +@RunWith(Arquillian.class) +public class CDIControllerTest { + + @Inject + private CDIController cdiController; + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, "modeshape-cdi-controller-test.war") + .addClass(CDIController.class) + .addClass(SessionProducer.class) + .addAsWebInfResource(new File("src/test/resources/log4j.properties")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/jboss-deployment-structure.xml")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/faces-config.xml")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/beans.xml")); + } + + @Before + public void before() { + assertNotNull("CDI controller not injected", cdiController); + } + + @Test + public void shouldReturnValidRepositoryName() throws Exception { + assertEquals("sample", cdiController.getRepositoryName()); + } + + @Test + public void shouldLoadChildren() throws Exception { + cdiController.setParentPath("/"); + cdiController.loadChildren(); + assertTrue(!cdiController.getChildren().isEmpty()); + } + + @Test + public void shouldAddNewChild() throws Exception { + cdiController.setParentPath("/"); + cdiController.setNewNodeName("test"); + cdiController.addChildNode(); + assertTrue(cdiController.getChildren().contains("/test")); + } +} diff --git a/modeshape-cdi/src/test/java/org/modeshape/quickstart/cdi/SessionProducerTest.java b/modeshape-cdi/src/test/java/org/modeshape/quickstart/cdi/SessionProducerTest.java new file mode 100644 index 0000000..1d9e2e9 --- /dev/null +++ b/modeshape-cdi/src/test/java/org/modeshape/quickstart/cdi/SessionProducerTest.java @@ -0,0 +1,39 @@ +package org.modeshape.quickstart.cdi; + +import java.io.File; +import javax.inject.Inject; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.assertNotNull; + +/** + * Arquillian test for {@link SessionProducer} + * + * @author Horia Chiorean (hchiorea@redhat.com) + */ +@RunWith(Arquillian.class) +public class SessionProducerTest { + + @Inject + private SessionProducer sessionProducer; + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, "modeshape-cdi-producer-test.war") + .addClass(SessionProducer.class) + .addAsWebInfResource(new File("src/test/resources/log4j.properties")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/jboss-deployment-structure.xml")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/faces-config.xml")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/beans.xml")); + } + + @Test + public void shouldProduceValidSession() throws Exception { + assertNotNull(sessionProducer); + assertNotNull(sessionProducer.getSession()); + } +} diff --git a/modeshape-cdi/src/test/resources/log4j.properties b/modeshape-cdi/src/test/resources/log4j.properties new file mode 100644 index 0000000..8bc3a0c --- /dev/null +++ b/modeshape-cdi/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n + +# Root logger option +log4j.rootLogger=WARN, stdout + +# Set up the default logging to be INFO level, then override specific units +log4j.logger.org.modeshape=INFO +log4j.logger.org.junit=DEBUG +log4j.logger.org.hibernate=WARN +log4j.logger.org.hibernate.pretty.Printer=WARN +log4j.logger.org.hibernate.engine.Collections=WARN +log4j.logger.org.hibernate.cfg=WARN +log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=WARN +log4j.logger.org.hibernate.persister.entity.AbstractEntityPersister=WARN +log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=WARN +log4j.logger.org.hibernate.engine.TwoPhaseLoad=WARN +log4j.logger.org.hibernate.jdbc.AbstractBatcher=WARN +log4j.logger.org.hibernate.hql.ast=WARN +log4j.logger.org.hibernate.engine.loading.CollectionLoadContext=WARN \ No newline at end of file diff --git a/modeshape-cli/README.md b/modeshape-cli/README.md new file mode 100644 index 0000000..67a74fa --- /dev/null +++ b/modeshape-cli/README.md @@ -0,0 +1,123 @@ +Example Using ModeShape from a JSF application with CLI scripts that create the repository +========================================================================================== + + +What is it? +----------- + +This is a self-contained and deployable Maven 3 project that shows how to get access and use a repository bound in JNDI, from +a JSF application, after the ModeShape subsystem and the repository have be set up via CLI scripts. + +System requirements +------------------- + +All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better. +The application this project produces is designed to be run on JBoss Enterprise Application Platform 6. + +Install ModeShape's EAP kit into an existing JBoss EAP 6 server +----------------------------------------------------- +Before running this demo make sure that you have installed the ModeShape EAP kit into an existing JBoss EAP server. +The simplest way to do this is to follow the instructions provided [here](https://docs.jboss.org/author/display/MODE/Installing+ModeShape+into+AS7) + +Start JBoss EAP with the default configuration +-------------------------------------------------------------------------------- + +1. Open a command line and navigate to the root of the JBoss server directory. +2. The following shows the command line to start the server with the ModeShape profile: + + For Linux: JBOSS_HOME/bin/standalone.sh -c standalone.xml + For Windows: JBOSS_HOME\bin\standalone.bat -c standalone.xml + +Run the CLI script that creates the demo repository +-------------------------------------------------------------------------------- + +1. Open a command line and navigate to the root of the JBoss server directory. +2. The following shows the command line which runs the script that creates the repository: + + For Linux: JBOSS_HOME/bin/jboss-cli.sh -c --file QUICKSTART_ROOT/src/main/resources/create-repository.cli + For Windows: JBOSS_HOME\bin\jboss-cli.bat -c --file QUICKSTART_ROOT\src\main\resources\create-repository.cli + +Build and Deploy the Quickstart +------------------------- +_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must use the `settings.xml` +file from the root of this project. See [this ModeShape community article](http://community.jboss.org/wiki/ModeShapeandMaven) +for help on how to install and configure Maven 3._ + +1. Make sure you have started the JBoss Server and have ran the CLI script as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. Type this command to build and deploy the archive: + + mvn clean package jboss-as:deploy + +4. This will deploy `target/modeshape-cli.war` to the running instance of the server. + +Accessing the application +--------------------- + +The application will be running at the following URL: and will display a simple, +read-only form which displays information about the repository which was created via the CLI script. + +Undeploy the Archive +-------------------- + +1. Make sure you have started the JBoss Server as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. When you are finished testing, type this command to undeploy the archive: + + mvn jboss-as:undeploy + +4. The archive is also undeployed each time the following command is issued: + + mvn clean + +Remove the demo repository +--------------------------- +If you want to cleanup the repository and other ModeShape related data, you can run the following script: + + For Linux: JBOSS_HOME/bin/jboss-cli.sh -c --file QUICKSTART_ROOT/src/main/resources/remove-repository.cli + For Windows: JBOSS_HOME\bin\jboss-cli.bat -c --file QUICKSTART_ROOT\src\main\resources\remove-repository.cli + +Run the Arquillian Tests +------------------------- + +This quickstart provides Arquillian tests. By default, these tests are configured to be skipped as Arquillian tests require the use of a container. + +1. Make sure you have started the JBoss Server and have ran the CLI script as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. Type the following command to run the test goal with the following profile activated: + + mvn clean package -Parq-jbossas-remote + +The ModeShape project +--------------------- +ModeShape is an open source implementation of the JCR 2.0 +([JSR-283](http://www.jcp.org/en/jsr/detail?id=283])) specification and +standard API. To your applications, ModeShape looks and behaves like a +regular JCR repository. Applications can search, query, navigate, change, +version, listen for changes, etc. But ModeShape can store that content +in a variety of back-end stores (including relational databases, Infinispan +data grids, JBoss Cache, etc.), or it can access and update existing content +from *other* kinds of systems (including file systems, SVN repositories, +JDBC database metadata, and other JCR repositories). ModeShape's connector +architecture means that you can write custom connectors to access any +kind of system. And ModeShape can even federate multiple back-end systems +into a single, unified virtual repository. + +For more information on ModeShape, including getting started guides, +reference guides, and downloadable binaries, visit the project's website +at [http://www.modeshape.org]() or follow us on our [blog](http://modeshape.wordpress.org) +or on [Twitter](http://twitter.com/modeshape). Or hop into our +[IRC chat room](http://www.jboss.org/modeshape/chat) and talk our community +of contributors and users. + +The official Git repository for the project is also on GitHub at +[http://github.com/ModeShape/modeshape](). + +Need help ? +----------- + +ModeShape is open source software with a dedicated community. If you have +any questions or problems, post a question in our +[user forum](http://community.jboss.org/en/modeshape) or hop into our +[IRC chat room](http://www.jboss.org/modeshape/chat) and talk our +community of contributors and users. diff --git a/modeshape-cli/pom.xml b/modeshape-cli/pom.xml new file mode 100644 index 0000000..bc4ff14 --- /dev/null +++ b/modeshape-cli/pom.xml @@ -0,0 +1,308 @@ + + + 4.0.0 + org.modeshape.quickstarts + modeshape-cli + 1.0-SNAPSHOT + war + Example of a JSF web application that uses CLI scripts to create and remove a repository + + A simple self-contained JSF web application that provides some CLI scripts to set-up a repository. + + + + UTF-8 + 1.6 + 1.6 + + + 2.4 + 2.5 + 3.0 + 2.6 + 2.4 + 2.4 + 2.6 + 2.12.3 + 2.3 + 7.4.Final + + + 1.0.4.Final + 3.2.0.Final + + + + + + + org.jboss.bom + jboss-javaee-6.0-with-tools + ${version.org.jboss.bom} + pom + import + + + + + org.modeshape.bom + modeshape-bom-jbosseap + ${version.modeshape} + pom + import + + + + + + + javax.jcr + jcr + + + + org.modeshape + modeshape-jcr-api + + + + log4j + log4j + + + + + javax.enterprise + cdi-api + provided + + + + + org.jboss.spec.javax.annotation + jboss-annotations-api_1.1_spec + provided + + + + + org.jboss.spec.javax.faces + jboss-jsf-api_2.1_spec + provided + + + + + junit + junit + test + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.jboss.arquillian.protocol + arquillian-protocol-servlet + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-depchain + pom + test + + + + + ${project.artifactId} + + + + + org.apache.maven.plugins + maven-assembly-plugin + ${version.assembly.plugin} + + + org.apache.maven.plugins + maven-clean-plugin + ${version.clean.plugin} + + + org.apache.maven.plugins + maven-compiler-plugin + ${version.compiler.plugin} + + false + false + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + org.apache.maven.plugins + maven-dependency-plugin + ${version.dependency.plugin} + + + org.apache.maven.plugins + maven-install-plugin + ${version.install.plugin} + + + org.apache.maven.plugins + maven-jar-plugin + ${version.jar.plugin} + + + org.apache.maven.plugins + maven-resources-plugin + ${version.resources.plugin} + + + org.apache.maven.plugins + maven-surefire-plugin + ${version.surefire.plugin} + + + org.apache.maven.plugins + maven-war-plugin + ${version.war.plugin} + + false + + + + + + org.jboss.as.plugins + jboss-as-maven-plugin + ${version.org.jboss.as.plugins.maven.plugin} + + + + + + + + + org.jboss.as.plugins + jboss-as-maven-plugin + + + + undeploy + clean + + undeploy + + + true + + + + + + + + + + + + + default + + true + + + + + maven-surefire-plugin + ${version.surefire.plugin} + + true + + + + + + + + arq-jbossas-remote + + + org.jboss.as + jboss-as-arquillian-container-remote + test + + + + + diff --git a/modeshape-cli/settings.xml b/modeshape-cli/settings.xml new file mode 100644 index 0000000..fc2ab66 --- /dev/null +++ b/modeshape-cli/settings.xml @@ -0,0 +1,48 @@ + + + + + jboss-public-repository + + + jboss-public-repository-group + JBoss Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + default + + true + never + + + true + never + + + + + + jboss-public-repository-group + JBoss Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + default + + true + never + + + true + never + + + + + + + + jboss-public-repository + + + diff --git a/modeshape-cli/src/main/java/org/modeshape/quickstart/cli/CLIController.java b/modeshape-cli/src/main/java/org/modeshape/quickstart/cli/CLIController.java new file mode 100644 index 0000000..385b35a --- /dev/null +++ b/modeshape-cli/src/main/java/org/modeshape/quickstart/cli/CLIController.java @@ -0,0 +1,53 @@ +package org.modeshape.quickstart.cli; + +import java.util.Map; +import java.util.TreeMap; +import javax.annotation.Resource; +import javax.enterprise.context.RequestScoped; +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; +import javax.inject.Named; +import javax.jcr.Repository; + +/** + * A simple JSF controller, that uses CDI to obtain a ModeShape {@link javax.jcr.Repository} that was created via a CLI script + * and provides some information about the repository. + * + * @author Horia Chiorean (hchiorea@redhat.com) + */ +@Named("cliController") +@RequestScoped +public class CLIController { + + @Resource( mappedName = "java:/jcr/test-cli" ) + private Repository repository; + + /** + * Returns a map with the repository descriptors. + * + * @return a non-null {@link Map} + */ + public Map getRepositoryDescription() { + TreeMap descriptorsMap = new TreeMap(); + if (repository == null) { + FacesContext.getCurrentInstance().addMessage(null, + new FacesMessage( + "Repository was not injected correctly. Please check for any errors during server startup")); + } else { + for (String descriptorKey : repository.getDescriptorKeys()) { + descriptorsMap.put(descriptorKey, repository.getDescriptor(descriptorKey)); + } + } + return descriptorsMap; + } + + + /** + * Returns the name of the repository. + * + * @return a non-null string. + */ + public String getRepositoryName() { + return repository.getDescriptor(org.modeshape.jcr.api.Repository.REPOSITORY_NAME); + } +} diff --git a/modeshape-ejb/src/main/resources/create-repository.cli b/modeshape-cli/src/main/resources/create-repository.cli similarity index 74% rename from modeshape-ejb/src/main/resources/create-repository.cli rename to modeshape-cli/src/main/resources/create-repository.cli index 9f361cd..c3eb4a6 100644 --- a/modeshape-ejb/src/main/resources/create-repository.cli +++ b/modeshape-cli/src/main/resources/create-repository.cli @@ -12,12 +12,14 @@ end-if if (outcome != success) of /subsystem=infinispan/cache-container=modeshape-test:read-resource # Setup Infinispan /subsystem=infinispan/cache-container=modeshape-test:add - /subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb:add - /subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb/transaction=TRANSACTION:add(mode=NON_XA) - /subsystem=infinispan/cache-container=modeshape-test/local-cache=test-ejb/file-store=FILE_STORE:add(path="modeshape/store/test-ejb",relative-to="jboss.server.data.dir",passivation=false,purge=false) + /subsystem=infinispan/cache-container=modeshape-test/local-cache=test-cli:add + /subsystem=infinispan/cache-container=modeshape-test/local-cache=test-cli/transaction=TRANSACTION:add(mode=NON_XA) + /subsystem=infinispan/cache-container=modeshape-test/local-cache=test-cli/file-store=FILE_STORE:add(path="modeshape/store/test-cli",relative-to="jboss.server.data.dir",passivation=false,purge=false) end-if # Add the test repository -if (outcome != success) of /subsystem=modeshape/repository=test-ejb:read-resource - /subsystem=modeshape/repository=test-ejb:add(cache-container="modeshape-test") +if (outcome != success) of /subsystem=modeshape/repository=test-cli:read-resource + /subsystem=modeshape/repository=test-cli:add(cache-container="modeshape-test") end-if + +:reload diff --git a/modeshape-ejb/src/main/resources/remove-repository.cli b/modeshape-cli/src/main/resources/remove-repository.cli similarity index 79% rename from modeshape-ejb/src/main/resources/remove-repository.cli rename to modeshape-cli/src/main/resources/remove-repository.cli index b9a5c0d..163da5f 100644 --- a/modeshape-ejb/src/main/resources/remove-repository.cli +++ b/modeshape-cli/src/main/resources/remove-repository.cli @@ -1,10 +1,12 @@ # Remove the test repository if it exists -if (outcome == success) of /subsystem=modeshape/repository=test-ejb:read-resource - /subsystem=modeshape/repository=test-ejb:remove +if (outcome == success) of /subsystem=modeshape/repository=test-cli:read-resource + /subsystem=modeshape/repository=test-cli:remove end-if # Remove the Infinispan cache container if (outcome == success) of /subsystem=infinispan/cache-container=modeshape-test:read-resource # Setup Infinispan /subsystem=infinispan/cache-container=modeshape-test:remove -end-if \ No newline at end of file +end-if + +:reload \ No newline at end of file diff --git a/modeshape-cli/src/main/webapp/WEB-INF/beans.xml b/modeshape-cli/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..3f9d20e --- /dev/null +++ b/modeshape-cli/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,18 @@ + + + + + diff --git a/modeshape-cli/src/main/webapp/WEB-INF/faces-config.xml b/modeshape-cli/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000..fbe54e5 --- /dev/null +++ b/modeshape-cli/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/modeshape-cli/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/modeshape-cli/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000..4b3b7d9 --- /dev/null +++ b/modeshape-cli/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/modeshape-cli/src/main/webapp/WEB-INF/jboss-web.xml b/modeshape-cli/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000..f754a45 --- /dev/null +++ b/modeshape-cli/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,6 @@ + + + + /modeshape-cli + + diff --git a/modeshape-cli/src/main/webapp/index.html b/modeshape-cli/src/main/webapp/index.html new file mode 100644 index 0000000..10a2efd --- /dev/null +++ b/modeshape-cli/src/main/webapp/index.html @@ -0,0 +1,28 @@ + + + + + + diff --git a/modeshape-cli/src/main/webapp/main.xhtml b/modeshape-cli/src/main/webapp/main.xhtml new file mode 100644 index 0000000..d6fd337 --- /dev/null +++ b/modeshape-cli/src/main/webapp/main.xhtml @@ -0,0 +1,59 @@ + + + + + + + ModeShape CLI Example + + + + +

    ModeShape CLI Example

    + +
    + + + + + + + Repository Name: + + + Description: + + + + + + + + +
    + + \ No newline at end of file diff --git a/modeshape-cli/src/test/java/org/modeshape/quickstart/cli/CLIControllerTest.java b/modeshape-cli/src/test/java/org/modeshape/quickstart/cli/CLIControllerTest.java new file mode 100644 index 0000000..6723bb2 --- /dev/null +++ b/modeshape-cli/src/test/java/org/modeshape/quickstart/cli/CLIControllerTest.java @@ -0,0 +1,40 @@ +package org.modeshape.quickstart.cli; + +import java.io.File; +import javax.inject.Inject; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.assertNotNull; + +/** + * Arquillian test for {@link CLIController} + * + * @author Horia Chiorean (hchiorea@redhat.com) + */ +@RunWith(Arquillian.class) +public class CLIControllerTest { + + @Inject + private CLIController cliController; + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, "modeshape-cli-controller-test.war") + .addClass(CLIController.class) + .addAsWebInfResource(new File("src/test/resources/log4j.properties")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/jboss-deployment-structure.xml")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/faces-config.xml")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/beans.xml")); + } + + @Test + public void shouldReturnRepositoryDescription() throws Exception { + assertNotNull(cliController); + assertNotNull(cliController.getRepositoryName()); + assertNotNull(cliController.getRepositoryDescription()); + } +} diff --git a/modeshape-cli/src/test/resources/arquillian.xml b/modeshape-cli/src/test/resources/arquillian.xml new file mode 100644 index 0000000..01c6040 --- /dev/null +++ b/modeshape-cli/src/test/resources/arquillian.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/modeshape-cli/src/test/resources/log4j.properties b/modeshape-cli/src/test/resources/log4j.properties new file mode 100644 index 0000000..8bc3a0c --- /dev/null +++ b/modeshape-cli/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n + +# Root logger option +log4j.rootLogger=WARN, stdout + +# Set up the default logging to be INFO level, then override specific units +log4j.logger.org.modeshape=INFO +log4j.logger.org.junit=DEBUG +log4j.logger.org.hibernate=WARN +log4j.logger.org.hibernate.pretty.Printer=WARN +log4j.logger.org.hibernate.engine.Collections=WARN +log4j.logger.org.hibernate.cfg=WARN +log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=WARN +log4j.logger.org.hibernate.persister.entity.AbstractEntityPersister=WARN +log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=WARN +log4j.logger.org.hibernate.engine.TwoPhaseLoad=WARN +log4j.logger.org.hibernate.jdbc.AbstractBatcher=WARN +log4j.logger.org.hibernate.hql.ast=WARN +log4j.logger.org.hibernate.engine.loading.CollectionLoadContext=WARN \ No newline at end of file diff --git a/modeshape-ejb/pom.xml b/modeshape-ejb/pom.xml index 461a423..97c3721 100644 --- a/modeshape-ejb/pom.xml +++ b/modeshape-ejb/pom.xml @@ -224,64 +224,10 @@ true - true - - false - - - - - - diff --git a/modeshape-ejb/src/test/resources/log4j.properties b/modeshape-ejb/src/test/resources/log4j.properties new file mode 100644 index 0000000..8bc3a0c --- /dev/null +++ b/modeshape-ejb/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n + +# Root logger option +log4j.rootLogger=WARN, stdout + +# Set up the default logging to be INFO level, then override specific units +log4j.logger.org.modeshape=INFO +log4j.logger.org.junit=DEBUG +log4j.logger.org.hibernate=WARN +log4j.logger.org.hibernate.pretty.Printer=WARN +log4j.logger.org.hibernate.engine.Collections=WARN +log4j.logger.org.hibernate.cfg=WARN +log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=WARN +log4j.logger.org.hibernate.persister.entity.AbstractEntityPersister=WARN +log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=WARN +log4j.logger.org.hibernate.engine.TwoPhaseLoad=WARN +log4j.logger.org.hibernate.jdbc.AbstractBatcher=WARN +log4j.logger.org.hibernate.hql.ast=WARN +log4j.logger.org.hibernate.engine.loading.CollectionLoadContext=WARN \ No newline at end of file diff --git a/modeshape-servlet/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java b/modeshape-servlet/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java index 8997a62..464edbe 100644 --- a/modeshape-servlet/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java +++ b/modeshape-servlet/src/test/java/org/modeshape/quickstart/servlet/RepositoryServletTest.java @@ -24,9 +24,9 @@ public class RepositoryServletTest { @Deployment public static WebArchive createDeployment() { return ShrinkWrap.create(WebArchive.class, "modeshape-servlet-test.war").addClass(RepositoryServlet.class) - .addAsWebInfResource(new File("src/main/resources/log4j.properties")) .addAsWebInfResource(new File("src/main/webapp/WEB-INF/jboss-web.xml")) .addAsWebInfResource(new File("src/main/webapp/WEB-INF/jboss-deployment-structure.xml")) + .addAsWebInfResource(new File("src/test/resources/log4j.properties")) .addAsWebResource(new File("src/main/webapp/dblue106.gif")) .addAsWebResource(new File("src/main/webapp/lgrey029.jpg")) .addAsWebResource(new File("src/main/webapp/main.jsp")) diff --git a/modeshape-servlet/src/test/resources/log4j.properties b/modeshape-servlet/src/test/resources/log4j.properties new file mode 100644 index 0000000..8bc3a0c --- /dev/null +++ b/modeshape-servlet/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n + +# Root logger option +log4j.rootLogger=WARN, stdout + +# Set up the default logging to be INFO level, then override specific units +log4j.logger.org.modeshape=INFO +log4j.logger.org.junit=DEBUG +log4j.logger.org.hibernate=WARN +log4j.logger.org.hibernate.pretty.Printer=WARN +log4j.logger.org.hibernate.engine.Collections=WARN +log4j.logger.org.hibernate.cfg=WARN +log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=WARN +log4j.logger.org.hibernate.persister.entity.AbstractEntityPersister=WARN +log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=WARN +log4j.logger.org.hibernate.engine.TwoPhaseLoad=WARN +log4j.logger.org.hibernate.jdbc.AbstractBatcher=WARN +log4j.logger.org.hibernate.hql.ast=WARN +log4j.logger.org.hibernate.engine.loading.CollectionLoadContext=WARN \ No newline at end of file diff --git a/pom.xml b/pom.xml index dafae89..877fc8c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 org.modeshape.quickstarts - modeshape-quickstarts-aggregator + modeshape-quickstarts 1.0-SNAPSHOT ModeShape EAP Quickstarts Top-Level POM for building all of the quickstarts. @@ -18,5 +18,6 @@ modeshape-servlet modeshape-ejb modeshape-cdi + modeshape-cli From 5338e30fffd8dcd4770c561043626cc79ccb38e9 Mon Sep 17 00:00:00 2001 From: Horia Chiorean Date: Tue, 30 Apr 2013 12:53:52 +0300 Subject: [PATCH 09/11] MODE-1695 - Added distribution module for building the quickstarts. --- dist/pom.xml | 48 +++++++++++++++++++++++++++++ dist/src/main/assembly/assembly.xml | 30 ++++++++++++++++++ modeshape-cdi/README.md | 4 --- modeshape-cdi/pom.xml | 27 ---------------- modeshape-cli/README.md | 4 --- modeshape-cli/pom.xml | 17 ---------- modeshape-ejb/README.md | 4 --- modeshape-ejb/pom.xml | 20 ------------ modeshape-servlet/pom.xml | 18 ----------- pom.xml | 9 ++++++ 10 files changed, 87 insertions(+), 94 deletions(-) create mode 100644 dist/pom.xml create mode 100644 dist/src/main/assembly/assembly.xml diff --git a/dist/pom.xml b/dist/pom.xml new file mode 100644 index 0000000..7df1974 --- /dev/null +++ b/dist/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + org.modeshape.quickstarts + modeshape-quickstarts-dist + 1.0-SNAPSHOT + ModeShape EAP Quickstarts Distribution + POM for building the quickstarts distribution. + http://www.modeshape.org + pom + + + 2.4 + + + + + + org.apache.maven.plugins + maven-assembly-plugin + ${version.assembly.plugin} + + + + + + maven-assembly-plugin + + + distribution + package + + single + + + + src/main/assembly/assembly.xml + + modeshape-quickstarts-${project.version} + false + + + + + + + + diff --git a/dist/src/main/assembly/assembly.xml b/dist/src/main/assembly/assembly.xml new file mode 100644 index 0000000..6e836ae --- /dev/null +++ b/dist/src/main/assembly/assembly.xml @@ -0,0 +1,30 @@ + + + dist + modeshape-quickstarts-${project.version} + + zip + + + + + ${project.basedir}/.. + / + + **/*.war + dist/** + template/** + **/target/** + **/.project + **/.settings/** + **/.classpath + **/.gitignore + **/*.ipr/** + **/*.iml/** + **/.idea/** + + + + diff --git a/modeshape-cdi/README.md b/modeshape-cdi/README.md index 6974ce2..f8fbf91 100644 --- a/modeshape-cdi/README.md +++ b/modeshape-cdi/README.md @@ -68,10 +68,6 @@ Undeploy the Archive mvn jboss-as:undeploy -4. The archive is also undeployed each time the following command is issued: - - mvn clean - Run the Arquillian Tests ------------------------- diff --git a/modeshape-cdi/pom.xml b/modeshape-cdi/pom.xml index 486a0a2..9738bc3 100644 --- a/modeshape-cdi/pom.xml +++ b/modeshape-cdi/pom.xml @@ -196,33 +196,6 @@ - - - - org.jboss.as.plugins - jboss-as-maven-plugin - - - - undeploy - clean - - undeploy - - - true - true - - false - - - - - - - - - diff --git a/modeshape-cli/README.md b/modeshape-cli/README.md index 67a74fa..d8c32d8 100644 --- a/modeshape-cli/README.md +++ b/modeshape-cli/README.md @@ -66,10 +66,6 @@ Undeploy the Archive mvn jboss-as:undeploy -4. The archive is also undeployed each time the following command is issued: - - mvn clean - Remove the demo repository --------------------------- If you want to cleanup the repository and other ModeShape related data, you can run the following script: diff --git a/modeshape-cli/pom.xml b/modeshape-cli/pom.xml index bc4ff14..2d588fd 100644 --- a/modeshape-cli/pom.xml +++ b/modeshape-cli/pom.xml @@ -247,23 +247,6 @@ --> - - org.jboss.as.plugins - jboss-as-maven-plugin - - - - undeploy - clean - - undeploy - - - true - - - - diff --git a/modeshape-ejb/README.md b/modeshape-ejb/README.md index 3316ab3..bd99ba2 100644 --- a/modeshape-ejb/README.md +++ b/modeshape-ejb/README.md @@ -67,10 +67,6 @@ Undeploy the Archive mvn jboss-as:undeploy -4. The archive is also undeployed each time the following command is issued: - - mvn clean - Run the Arquillian Tests ------------------------- diff --git a/modeshape-ejb/pom.xml b/modeshape-ejb/pom.xml index 97c3721..7df1d58 100644 --- a/modeshape-ejb/pom.xml +++ b/modeshape-ejb/pom.xml @@ -209,26 +209,6 @@ - - - - org.jboss.as.plugins - jboss-as-maven-plugin - - - - undeploy - clean - - undeploy - - - true - - - - - diff --git a/modeshape-servlet/pom.xml b/modeshape-servlet/pom.xml index a98dc0e..43594cb 100644 --- a/modeshape-servlet/pom.xml +++ b/modeshape-servlet/pom.xml @@ -214,24 +214,6 @@ - - - org.jboss.as.plugins - jboss-as-maven-plugin - - - undeploy - clean - - undeploy - - - true - - - - - maven-surefire-plugin ${version.surefire.plugin} diff --git a/pom.xml b/pom.xml index 877fc8c..0b0864a 100644 --- a/pom.xml +++ b/pom.xml @@ -20,4 +20,13 @@ modeshape-cdi modeshape-cli + + + + dist + + dist + + + From 3409292abcd4b1589979044cdea9779d85daaf86 Mon Sep 17 00:00:00 2001 From: Horia Chiorean Date: Thu, 9 May 2013 10:31:55 +0300 Subject: [PATCH 10/11] MODE-1695 - Added clustering quickstart. --- modeshape-clustering/README.md | 132 ++++++ modeshape-clustering/pom.xml | 240 +++++++++++ modeshape-clustering/settings.xml | 48 +++ .../quickstart/cdi/ClusteringController.java | 210 ++++++++++ .../src/main/webapp/WEB-INF/beans.xml | 18 + .../src/main/webapp/WEB-INF/faces-config.xml | 20 + .../WEB-INF/jboss-deployment-structure.xml | 10 + .../src/main/webapp/WEB-INF/jboss-web.xml | 6 + .../src/main/webapp/WEB-INF/web.xml | 8 + .../src/main/webapp/index.html | 28 ++ .../src/main/webapp/main.xhtml | 79 ++++ .../cdi/ClusteringControllerTest.java | 72 ++++ .../src/test/resources/arquillian.xml | 32 ++ .../src/test/resources/log4j.properties | 23 ++ .../standalone-modeshape-ha-node1.xml | 379 +++++++++++++++++ .../standalone-modeshape-ha-node2.xml | 382 ++++++++++++++++++ pom.xml | 1 + 17 files changed, 1688 insertions(+) create mode 100644 modeshape-clustering/README.md create mode 100644 modeshape-clustering/pom.xml create mode 100644 modeshape-clustering/settings.xml create mode 100644 modeshape-clustering/src/main/java/org/modeshape/quickstart/cdi/ClusteringController.java create mode 100644 modeshape-clustering/src/main/webapp/WEB-INF/beans.xml create mode 100644 modeshape-clustering/src/main/webapp/WEB-INF/faces-config.xml create mode 100644 modeshape-clustering/src/main/webapp/WEB-INF/jboss-deployment-structure.xml create mode 100644 modeshape-clustering/src/main/webapp/WEB-INF/jboss-web.xml create mode 100644 modeshape-clustering/src/main/webapp/WEB-INF/web.xml create mode 100644 modeshape-clustering/src/main/webapp/index.html create mode 100644 modeshape-clustering/src/main/webapp/main.xhtml create mode 100644 modeshape-clustering/src/test/java/org/modeshape/quickstart/cdi/ClusteringControllerTest.java create mode 100644 modeshape-clustering/src/test/resources/arquillian.xml create mode 100644 modeshape-clustering/src/test/resources/log4j.properties create mode 100644 modeshape-clustering/standalone-modeshape-ha-node1.xml create mode 100644 modeshape-clustering/standalone-modeshape-ha-node2.xml diff --git a/modeshape-clustering/README.md b/modeshape-clustering/README.md new file mode 100644 index 0000000..8cb99bf --- /dev/null +++ b/modeshape-clustering/README.md @@ -0,0 +1,132 @@ +Example Clustering 2 ModeShape Repositories +=========================================== + +What is it? +----------- + +This is a self-contained and deployable Maven 3 project that shows how to cluster 2 ModeShape repositories. + +System requirements +------------------- + +All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better. +The application this project produces is designed to be run on JBoss Enterprise Application Platform 6. + +Install ModeShape's EAP kit into an existing JBoss EAP 6 server +----------------------------------------------------- +Before running this demo make sure that you have installed the ModeShape EAP kit into an existing JBoss EAP server. +The simplest way to do this is to follow the instructions provided [here](https://docs.jboss.org/author/display/MODE/Installing+ModeShape+into+AS7) + +Start 2 JBoss EAP instances with the configurations provided by this quickstart +----------------------------------------------------------------------------------------- + +1. Copy the `standalone-modeshape-ha-node1.xml` and `standalone-modeshape-ha-node2.xml` configuration files from the root of the quickstart +into the `JBOSS_HOME/standalone/configuration` folder +2. Open a command line and navigate to the root of the JBoss server directory. +3. Start the first server: + + For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-modeshape-ha-node1.xml + For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-modeshape-ha-node1.xml +4. Start the second server: + + For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-modeshape-ha-node2.xml + For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-modeshape-ha-node2.xml + + +Build and Deploy the Quickstart into each of the running servers +---------------------------------------------------------------- +_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must use the `settings.xml` +file from the root of this project. See [this ModeShape community article](http://community.jboss.org/wiki/ModeShapeandMaven) +for help on how to install and configure Maven 3._ + +1. Make sure you have started the 2 JBoss Server instances as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. Type this command to build and deploy the archive into the first server: + + mvn clean package jboss-as:deploy + +4. Type this command to build and deploy the archive into the second server: + + mvn clean package jboss-as:deploy -Djboss-as.port=10000 + +5. This will deploy `target/modeshape-clustering.war` to each of the running instances of the server. + +Accessing the application +--------------------- + +The application will be running at the following URLs: + + On the first server: + On the second server: + +Open the above URLs in two different browsers (or 2 different browser tabs/windows). + +The user is presented with a form where he can input one of the following: + +1. Parent Absolute Path - an absolute node path +2. New Node Name - a simple string which represents the name of new node that can be added +3. Search for Nodes Like - a simple string which represents the name pattern of nodes that will be searched + +based on which one of the following actions can be performed + +1. Show children - displays the children of node located at "Parent Absolute Path" +2. Add Node - add a new child with the given name under the node located at "Parent Absolute Path" +3. Search - searches for nodes which have in their name the given string pattern + +Undeploy the Archive +-------------------- + +1. Make sure you have started the 2 JBoss Server instances as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. When you are finished testing, type this command to undeploy the archive from the first server: + + mvn jboss-as:undeploy + +4. When you are finished testing, type this command to undeploy the archive from the second server: + + mvn jboss-as:undeploy -Djboss-as.port=10000 + +Run the Arquillian Tests +------------------------- + +This quickstart provides Arquillian tests. By default, these tests are configured to be skipped as Arquillian tests require the use of a container. + +1. Make sure you have started the JBoss Server corresponding to `node1` as described above. +2. Open a command line and navigate to the root directory of this quickstart. +3. Type the following command to run the test goal with the following profile activated: + + mvn clean package -Parq-jbossas-remote + +The ModeShape project +--------------------- +ModeShape is an open source implementation of the JCR 2.0 +([JSR-283](http://www.jcp.org/en/jsr/detail?id=283])) specification and +standard API. To your applications, ModeShape looks and behaves like a +regular JCR repository. Applications can search, query, navigate, change, +version, listen for changes, etc. But ModeShape can store that content +in a variety of back-end stores (including relational databases, Infinispan +data grids, JBoss Cache, etc.), or it can access and update existing content +from *other* kinds of systems (including file systems, SVN repositories, +JDBC database metadata, and other JCR repositories). ModeShape's connector +architecture means that you can write custom connectors to access any +kind of system. And ModeShape can even federate multiple back-end systems +into a single, unified virtual repository. + +For more information on ModeShape, including getting started guides, +reference guides, and downloadable binaries, visit the project's website +at [http://www.modeshape.org]() or follow us on our [blog](http://modeshape.wordpress.org) +or on [Twitter](http://twitter.com/modeshape). Or hop into our +[IRC chat room](http://www.jboss.org/modeshape/chat) and talk our community +of contributors and users. + +The official Git repository for the project is also on GitHub at +[http://github.com/ModeShape/modeshape](). + +Need help ? +----------- + +ModeShape is open source software with a dedicated community. If you have +any questions or problems, post a question in our +[user forum](http://community.jboss.org/en/modeshape) or hop into our +[IRC chat room](http://www.jboss.org/modeshape/chat) and talk our +community of contributors and users. \ No newline at end of file diff --git a/modeshape-clustering/pom.xml b/modeshape-clustering/pom.xml new file mode 100644 index 0000000..3fa1985 --- /dev/null +++ b/modeshape-clustering/pom.xml @@ -0,0 +1,240 @@ + + + 4.0.0 + org.modeshape.quickstarts + modeshape-clustering + 1.0-SNAPSHOT + war + Example of a JSF web application that uses ModeShape via CDI + + A simple self-contained JSF web application that injects a ModeShape repository via CDI and performs various operations. + + + + UTF-8 + 1.6 + 1.6 + + + 2.4 + 2.5 + 3.0 + 2.6 + 2.4 + 2.4 + 2.6 + 2.12.3 + 2.3 + 7.4.Final + + + 1.0.4.Final + 3.2.0.Final + + + + + + + org.jboss.bom + jboss-javaee-6.0-with-tools + ${version.org.jboss.bom} + pom + import + + + + + org.modeshape.bom + modeshape-bom-jbosseap + ${version.modeshape} + pom + import + + + + + + + javax.jcr + jcr + + + + org.modeshape + modeshape-jcr-api + + + + log4j + log4j + + + + + javax.enterprise + cdi-api + provided + + + + + org.jboss.spec.javax.annotation + jboss-annotations-api_1.1_spec + provided + + + + + org.jboss.spec.javax.faces + jboss-jsf-api_2.1_spec + provided + + + + + junit + junit + test + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.jboss.arquillian.protocol + arquillian-protocol-servlet + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-depchain + pom + test + + + + + ${project.artifactId} + + + + + org.apache.maven.plugins + maven-assembly-plugin + ${version.assembly.plugin} + + + org.apache.maven.plugins + maven-clean-plugin + ${version.clean.plugin} + + + org.apache.maven.plugins + maven-compiler-plugin + ${version.compiler.plugin} + + false + false + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + org.apache.maven.plugins + maven-dependency-plugin + ${version.dependency.plugin} + + + org.apache.maven.plugins + maven-install-plugin + ${version.install.plugin} + + + org.apache.maven.plugins + maven-jar-plugin + ${version.jar.plugin} + + + org.apache.maven.plugins + maven-resources-plugin + ${version.resources.plugin} + + + org.apache.maven.plugins + maven-surefire-plugin + ${version.surefire.plugin} + + + org.apache.maven.plugins + maven-war-plugin + ${version.war.plugin} + + false + + + + + + org.jboss.as.plugins + jboss-as-maven-plugin + ${version.org.jboss.as.plugins.maven.plugin} + + + + + + + + + + + default + + true + + + + + maven-surefire-plugin + ${version.surefire.plugin} + + true + + + + + + + + + arq-jbossas-remote + + + org.jboss.as + jboss-as-arquillian-container-remote + test + + + + + diff --git a/modeshape-clustering/settings.xml b/modeshape-clustering/settings.xml new file mode 100644 index 0000000..fc2ab66 --- /dev/null +++ b/modeshape-clustering/settings.xml @@ -0,0 +1,48 @@ + + + + + jboss-public-repository + + + jboss-public-repository-group + JBoss Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + default + + true + never + + + true + never + + + + + + jboss-public-repository-group + JBoss Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + default + + true + never + + + true + never + + + + + + + + jboss-public-repository + + + diff --git a/modeshape-clustering/src/main/java/org/modeshape/quickstart/cdi/ClusteringController.java b/modeshape-clustering/src/main/java/org/modeshape/quickstart/cdi/ClusteringController.java new file mode 100644 index 0000000..7c17e88 --- /dev/null +++ b/modeshape-clustering/src/main/java/org/modeshape/quickstart/cdi/ClusteringController.java @@ -0,0 +1,210 @@ +package org.modeshape.quickstart.cdi; + +import java.util.Collections; +import java.util.Set; +import java.util.TreeSet; +import javax.annotation.Resource; +import javax.enterprise.context.ApplicationScoped; +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; +import javax.inject.Named; +import javax.jcr.Node; +import javax.jcr.NodeIterator; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.query.Query; +import javax.jcr.query.QueryManager; +import javax.jcr.query.QueryResult; +import org.apache.log4j.Logger; + +/** + * A simple JSF controller, that uses a repository which is injected directly, + * + * @author Horia Chiorean (hchiorea@redhat.com) + */ +@Named( "clusteringController" ) +@ApplicationScoped +public class ClusteringController { + + private static final Logger LOGGER = Logger.getLogger(ClusteringController.class); + + @Resource(mappedName = "java:/jcr/clustered-repo") + private transient Repository clusteredRepository; + + private String parentPath = "/"; + private String newNodeName; + private String nodeNamePattern; + + private Set nodes = Collections.emptySet(); + + /** + * Sets a name for a new node to create. + * + * @param newNodeName a {@code non-null} string + */ + public void setNewNodeName( String newNodeName ) { + this.newNodeName = newNodeName; + } + + /** + * Returns the name of a new node which can be created. + * + * @return a {@code non-null} string + */ + public String getNewNodeName() { + return newNodeName; + } + + /** + * Returns the pattern of the name of the node to search after. + * + * @return a {@code non-null} string + */ + public String getNodeNamePattern() { + return nodeNamePattern; + } + + /** + * Sets the name pattern of the node to search after. + * + * @param nodeNamePattern a {@code non-null} string + */ + public void setNodeNamePattern( String nodeNamePattern ) { + this.nodeNamePattern = nodeNamePattern; + } + + /** + * Returns the absolute path of a parent node + * + * @return a {@code non-null} string + */ + public String getParentPath() { + return parentPath; + } + + /** + * Sets the absolute path of a parent node. + * + * @param parentPath a {@code non-null} string + */ + public void setParentPath( String parentPath ) { + this.parentPath = parentPath; + } + + /** + * Returns the children nodes of the node located at {@link ClusteringController#parentPath} + * + * @return a Set containing the paths of the children. + */ + public Set getNodes() { + return nodes; + } + + /** + * Searches for nodes that have a given pattern in their [jcr:name]. + * + * @return the view to redirect to. + */ + public String searchForNodes() { + nodes = new TreeSet(); + if (nodeNamePattern == null || nodeNamePattern.trim().length() == 0) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage( + "The node name pattern is required")); + } else { + Session repositorySession = null; + try { + repositorySession = newSession(); + QueryManager queryManager = repositorySession.getWorkspace().getQueryManager(); + String queryString = "select node.[jcr:name] from [nt:unstructured] as node where node.[jcr:name] like '%" + nodeNamePattern + "%'"; + LOGGER.info("Executing query:" + queryString); + QueryResult queryResult = queryManager.createQuery(queryString, Query.JCR_SQL2).execute(); + for (NodeIterator nodeIterator = queryResult.getNodes(); nodeIterator.hasNext(); ) { + nodes.add(nodeIterator.nextNode().getPath()); + } + } catch (RepositoryException e) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + } finally { + if (repositorySession != null) { + repositorySession.logout(); + } + } + } + return "/main.xhtml"; + } + + + /** + * Loads the children nodes of the node located at {@link ClusteringController#parentPath} + * + * @return the view to redirect to. + */ + public String loadChildren() { + nodes = new TreeSet(); + if (parentPath == null || parentPath.trim().length() == 0) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage( + "The absolute path of the parent node is required")); + } else { + Session repositorySession = null; + try { + repositorySession = newSession(); + Node parentNode = repositorySession.getNode(parentPath); + for (NodeIterator nodeIterator = parentNode.getNodes(); nodeIterator.hasNext(); ) { + nodes.add(nodeIterator.nextNode().getPath()); + } + } catch (RepositoryException e) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + } finally { + if (repositorySession != null) { + repositorySession.logout(); + } + } + } + return "/main.xhtml"; + } + + /** + * Adds a child node at {@link ClusteringController#parentPath} which has the name {@link ClusteringController#newNodeName} + * + * @return the view to redirect to. + */ + public String addChildNode() { + if (newNodeName == null || newNodeName.trim().length() == 0) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("The name of the new node is required")); + } else { + Session repositorySession = null; + try { + repositorySession = newSession(); + Node parentNode = repositorySession.getNode(parentPath); + parentNode.addNode(newNodeName); + repositorySession.save(); + } catch (RepositoryException e) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + } finally { + if (repositorySession != null) { + repositorySession.logout(); + } + } + } + return loadChildren(); + } + + /** + * Returns the name of the repository to which the session is bound. + * + * @return a non-null string. + * @throws RepositoryException if anything unexpected fails + */ + public String getRepositoryName() throws RepositoryException{ + Session repositorySession = newSession(); + try { + return repositorySession.getRepository().getDescriptor(org.modeshape.jcr.api.Repository.REPOSITORY_NAME); + } finally { + repositorySession.logout(); + } + } + + private Session newSession() throws RepositoryException { + return clusteredRepository.login(); + } +} diff --git a/modeshape-clustering/src/main/webapp/WEB-INF/beans.xml b/modeshape-clustering/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..3f9d20e --- /dev/null +++ b/modeshape-clustering/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,18 @@ + + + + + diff --git a/modeshape-clustering/src/main/webapp/WEB-INF/faces-config.xml b/modeshape-clustering/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000..fbe54e5 --- /dev/null +++ b/modeshape-clustering/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/modeshape-clustering/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/modeshape-clustering/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000..4b3b7d9 --- /dev/null +++ b/modeshape-clustering/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/modeshape-clustering/src/main/webapp/WEB-INF/jboss-web.xml b/modeshape-clustering/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000..afe0b9f --- /dev/null +++ b/modeshape-clustering/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,6 @@ + + + + /modeshape-clustering + + diff --git a/modeshape-clustering/src/main/webapp/WEB-INF/web.xml b/modeshape-clustering/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..7cf1da5 --- /dev/null +++ b/modeshape-clustering/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,8 @@ + + + + javax.faces.STATE_SAVING_METHOD + client + + diff --git a/modeshape-clustering/src/main/webapp/index.html b/modeshape-clustering/src/main/webapp/index.html new file mode 100644 index 0000000..10a2efd --- /dev/null +++ b/modeshape-clustering/src/main/webapp/index.html @@ -0,0 +1,28 @@ + + + + + + diff --git a/modeshape-clustering/src/main/webapp/main.xhtml b/modeshape-clustering/src/main/webapp/main.xhtml new file mode 100644 index 0000000..ce86e3f --- /dev/null +++ b/modeshape-clustering/src/main/webapp/main.xhtml @@ -0,0 +1,79 @@ + + + + + + + ModeShape Clustering Example + + + + +

    ModeShape Clustering Example

    + +
    + + + + + + + Repository Name: + + + Parent Absolute Path: + + + New Node Name: + + + Search for Nodes Like: + + + + + + + + + + + + + + + + + + +
    + + + \ No newline at end of file diff --git a/modeshape-clustering/src/test/java/org/modeshape/quickstart/cdi/ClusteringControllerTest.java b/modeshape-clustering/src/test/java/org/modeshape/quickstart/cdi/ClusteringControllerTest.java new file mode 100644 index 0000000..177087b --- /dev/null +++ b/modeshape-clustering/src/test/java/org/modeshape/quickstart/cdi/ClusteringControllerTest.java @@ -0,0 +1,72 @@ +package org.modeshape.quickstart.cdi; + +import java.io.File; +import javax.inject.Inject; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * Arquillian test for {@link ClusteringController} + * + * @author Horia Chiorean (hchiorea@redhat.com) + */ +@RunWith(Arquillian.class) +public class ClusteringControllerTest { + + @Inject + private ClusteringController clusteringController; + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, "modeshape-clustering-controller-test.war") + .addClass(ClusteringController.class) + .addAsWebInfResource(new File("src/test/resources/log4j.properties")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/jboss-deployment-structure.xml")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/faces-config.xml")) + .addAsWebInfResource(new File("src/main/webapp/WEB-INF/beans.xml")); + } + + @Before + public void before() { + assertNotNull("Clustering controller not injected", clusteringController); + } + + @Test + public void shouldReturnValidRepositoryName() throws Exception { + assertEquals("clustered-repo", clusteringController.getRepositoryName()); + } + + @Test + public void shouldLoadChildren() throws Exception { + clusteringController.setParentPath("/"); + clusteringController.loadChildren(); + assertTrue(!clusteringController.getNodes().isEmpty()); + } + + @Test + public void shouldAddNewChild() throws Exception { + clusteringController.setParentPath("/"); + clusteringController.setNewNodeName("test"); + clusteringController.addChildNode(); + assertTrue(clusteringController.getNodes().contains("/test")); + } + + @Test + public void shouldSearchForNodes() throws Exception { + clusteringController.setParentPath("/"); + clusteringController.setNewNodeName("test"); + clusteringController.addChildNode(); + + clusteringController.setNodeNamePattern("test"); + clusteringController.searchForNodes(); + assertTrue(clusteringController.getNodes().contains("/test")); + } +} diff --git a/modeshape-clustering/src/test/resources/arquillian.xml b/modeshape-clustering/src/test/resources/arquillian.xml new file mode 100644 index 0000000..01c6040 --- /dev/null +++ b/modeshape-clustering/src/test/resources/arquillian.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/modeshape-clustering/src/test/resources/log4j.properties b/modeshape-clustering/src/test/resources/log4j.properties new file mode 100644 index 0000000..8bc3a0c --- /dev/null +++ b/modeshape-clustering/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n + +# Root logger option +log4j.rootLogger=WARN, stdout + +# Set up the default logging to be INFO level, then override specific units +log4j.logger.org.modeshape=INFO +log4j.logger.org.junit=DEBUG +log4j.logger.org.hibernate=WARN +log4j.logger.org.hibernate.pretty.Printer=WARN +log4j.logger.org.hibernate.engine.Collections=WARN +log4j.logger.org.hibernate.cfg=WARN +log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=WARN +log4j.logger.org.hibernate.persister.entity.AbstractEntityPersister=WARN +log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=WARN +log4j.logger.org.hibernate.engine.TwoPhaseLoad=WARN +log4j.logger.org.hibernate.jdbc.AbstractBatcher=WARN +log4j.logger.org.hibernate.hql.ast=WARN +log4j.logger.org.hibernate.engine.loading.CollectionLoadContext=WARN \ No newline at end of file diff --git a/modeshape-clustering/standalone-modeshape-ha-node1.xml b/modeshape-clustering/standalone-modeshape-ha-node1.xml new file mode 100644 index 0000000..bf2454c --- /dev/null +++ b/modeshape-clustering/standalone-modeshape-ha-node1.xml @@ -0,0 +1,379 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 + h2 + + sa + sa + + + + + org.h2.jdbcx.JdbcDataSource + + + + + + + + + false + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + ${jboss.bind.address:127.0.0.1} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modeshape-clustering/standalone-modeshape-ha-node2.xml b/modeshape-clustering/standalone-modeshape-ha-node2.xml new file mode 100644 index 0000000..00e249c --- /dev/null +++ b/modeshape-clustering/standalone-modeshape-ha-node2.xml @@ -0,0 +1,382 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 + h2 + + sa + sa + + + + + org.h2.jdbcx.JdbcDataSource + + + + + + + + + false + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + ${jboss.bind.address:127.0.0.1} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 0b0864a..8ef616b 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ modeshape-ejb modeshape-cdi modeshape-cli + modeshape-clustering From 408391655f076aa86c97dc9c413a45e562a64549 Mon Sep 17 00:00:00 2001 From: Horia Chiorean Date: Wed, 15 May 2013 16:43:59 +0300 Subject: [PATCH 11/11] MODE-1695 - Updated the configuration, UI and readme with a working indexing example. --- modeshape-clustering/README.md | 43 ++++++++------- .../quickstart/cdi/ClusteringController.java | 1 + .../src/main/webapp/main.xhtml | 2 +- ...e1.xml => standalone-modeshape-master.xml} | 55 +++++++++++++++++-- ...de2.xml => standalone-modeshape-slave.xml} | 43 ++++++++++++--- 5 files changed, 113 insertions(+), 31 deletions(-) rename modeshape-clustering/{standalone-modeshape-ha-node1.xml => standalone-modeshape-master.xml} (87%) rename modeshape-clustering/{standalone-modeshape-ha-node2.xml => standalone-modeshape-slave.xml} (90%) diff --git a/modeshape-clustering/README.md b/modeshape-clustering/README.md index 8cb99bf..73843f5 100644 --- a/modeshape-clustering/README.md +++ b/modeshape-clustering/README.md @@ -4,7 +4,10 @@ Example Clustering 2 ModeShape Repositories What is it? ----------- -This is a self-contained and deployable Maven 3 project that shows how to cluster 2 ModeShape repositories. +This is a self-contained and deployable Maven 3 project that shows how to cluster 2 ModeShape repositories. This example +contains 2 configuration files for a simple master/slave setup. However, in production, it's likely that a _Highly Available_ +setup is desired. If that is the case, the only configuration difference from this quickstart is that HornetQ (or the chosen JMS solution) +will need to be set up for high availability. System requirements ------------------- @@ -13,39 +16,41 @@ All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3 The application this project produces is designed to be run on JBoss Enterprise Application Platform 6. Install ModeShape's EAP kit into an existing JBoss EAP 6 server ------------------------------------------------------ +--------------------------------------------------------------- + Before running this demo make sure that you have installed the ModeShape EAP kit into an existing JBoss EAP server. The simplest way to do this is to follow the instructions provided [here](https://docs.jboss.org/author/display/MODE/Installing+ModeShape+into+AS7) -Start 2 JBoss EAP instances with the configurations provided by this quickstart ------------------------------------------------------------------------------------------ +Start 2 JBoss EAP instances with the provided configurations +------------------------------------------------------------ -1. Copy the `standalone-modeshape-ha-node1.xml` and `standalone-modeshape-ha-node2.xml` configuration files from the root of the quickstart +1. Copy the `standalone-modeshape-ha-master.xml` and `standalone-modeshape-ha-slave.xml` configuration files from the root of the quickstart into the `JBOSS_HOME/standalone/configuration` folder 2. Open a command line and navigate to the root of the JBoss server directory. -3. Start the first server: +3. Start the `master` server: - For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-modeshape-ha-node1.xml - For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-modeshape-ha-node1.xml -4. Start the second server: + For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-modeshape-ha-master.xml + For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-modeshape-ha-master.xml +4. Start the `slave` server: - For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-modeshape-ha-node2.xml - For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-modeshape-ha-node2.xml + For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-modeshape-ha-slave.xml + For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-modeshape-ha-slave.xml Build and Deploy the Quickstart into each of the running servers ---------------------------------------------------------------- + _NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must use the `settings.xml` file from the root of this project. See [this ModeShape community article](http://community.jboss.org/wiki/ModeShapeandMaven) for help on how to install and configure Maven 3._ 1. Make sure you have started the 2 JBoss Server instances as described above. 2. Open a command line and navigate to the root directory of this quickstart. -3. Type this command to build and deploy the archive into the first server: +3. Type this command to build and deploy the archive into the `master` server: mvn clean package jboss-as:deploy -4. Type this command to build and deploy the archive into the second server: +4. Type this command to build and deploy the archive into the `slave` server: mvn clean package jboss-as:deploy -Djboss-as.port=10000 @@ -56,8 +61,8 @@ Accessing the application The application will be running at the following URLs: - On the first server: - On the second server: + On the `master` server: + On the `slave` server: Open the above URLs in two different browsers (or 2 different browser tabs/windows). @@ -65,7 +70,7 @@ The user is presented with a form where he can input one of the following: 1. Parent Absolute Path - an absolute node path 2. New Node Name - a simple string which represents the name of new node that can be added -3. Search for Nodes Like - a simple string which represents the name pattern of nodes that will be searched +3. Search for Nodes Names Like - a simple string which represents the name pattern of nodes that will be searched based on which one of the following actions can be performed @@ -78,11 +83,11 @@ Undeploy the Archive 1. Make sure you have started the 2 JBoss Server instances as described above. 2. Open a command line and navigate to the root directory of this quickstart. -3. When you are finished testing, type this command to undeploy the archive from the first server: +3. When you are finished testing, type this command to undeploy the archive from the `master` server: mvn jboss-as:undeploy -4. When you are finished testing, type this command to undeploy the archive from the second server: +4. When you are finished testing, type this command to undeploy the archive from the `slave` server: mvn jboss-as:undeploy -Djboss-as.port=10000 @@ -91,7 +96,7 @@ Run the Arquillian Tests This quickstart provides Arquillian tests. By default, these tests are configured to be skipped as Arquillian tests require the use of a container. -1. Make sure you have started the JBoss Server corresponding to `node1` as described above. +1. Make sure you have started the JBoss Server corresponding to `master` as described above. 2. Open a command line and navigate to the root directory of this quickstart. 3. Type the following command to run the test goal with the following profile activated: diff --git a/modeshape-clustering/src/main/java/org/modeshape/quickstart/cdi/ClusteringController.java b/modeshape-clustering/src/main/java/org/modeshape/quickstart/cdi/ClusteringController.java index 7c17e88..2c23a33 100644 --- a/modeshape-clustering/src/main/java/org/modeshape/quickstart/cdi/ClusteringController.java +++ b/modeshape-clustering/src/main/java/org/modeshape/quickstart/cdi/ClusteringController.java @@ -130,6 +130,7 @@ public String searchForNodes() { } } } + return "/main.xhtml"; } diff --git a/modeshape-clustering/src/main/webapp/main.xhtml b/modeshape-clustering/src/main/webapp/main.xhtml index ce86e3f..35bb242 100644 --- a/modeshape-clustering/src/main/webapp/main.xhtml +++ b/modeshape-clustering/src/main/webapp/main.xhtml @@ -51,7 +51,7 @@ New Node Name: - Search for Nodes Like: + Search for Node Names Like: + - + @@ -187,12 +188,15 @@ - - + + - @@ -250,6 +254,48 @@ + + + false + true + NIO + 2 + + + + + + + + + + jms.queue.DLQ + jms.queue.ExpiryQueue + 0 + 10485760 + BLOCK + 10 + + + + + + + + + + + + + + + + + + + + + @@ -372,6 +418,7 @@ + diff --git a/modeshape-clustering/standalone-modeshape-ha-node2.xml b/modeshape-clustering/standalone-modeshape-slave.xml similarity index 90% rename from modeshape-clustering/standalone-modeshape-ha-node2.xml rename to modeshape-clustering/standalone-modeshape-slave.xml index 00e249c..e1adb5a 100644 --- a/modeshape-clustering/standalone-modeshape-ha-node2.xml +++ b/modeshape-clustering/standalone-modeshape-slave.xml @@ -27,10 +27,11 @@ + - + @@ -187,12 +188,16 @@ - - + + + - @@ -250,6 +255,33 @@ + + + false + false + + + org.hornetq.core.remoting.impl.netty.NettyConnectorFactory + + + + + + + + + + + + + + + + + + + + @@ -372,9 +404,6 @@ - - -