Apache Pluto和Hymanrabbit集成示例教程

时间:2020-02-23 14:29:40  来源:igfitidea点击:

根据多种来源和标准,您可以将Content Repository定义为数字内容存储(结构化/非结构化),并具有一组相关的设施,例如数据管理,全文搜索,版本控制,事务和允许应用程序的访问方法-独立访问内容。

访问这些内容已经变得很重要,因为这应该通过使用定义明确,通用的标准和有组织的方式来完成。
这实际上将帮助您获得很多功能,其中最重要的一项是可交换性。

这恰恰意味着,在修改Content Engine时,您无需花费很多时间/精力来获取/学习实践和信息,就可以将这个新的Content Repository集成到您的基础架构中。

随着Portal重要性的增加,与Content Repository集成的需求也越来越高,尤其是当您知道像WebLogic Portal这样非常著名的Portal已与最强大的内容管理系统之一进行自我集成时作为Stellent-UCM(当前称为oracle Stellent-UCM)。

尽管stellentucm已经提供了一个单独的API来进行集成,但是Oracle已经通过使用JCR/jsr170内置的控件进行了集成

如今,提供了许多种类的内容存储库,其中一些是开源的,例如Apache Hymanrabbit,而另一些仍是封闭的,您可能会发现某些限制,例如Alfresco。

此限制来自社区副本的可用性,但是如果您想获得更强大的支持,则可能需要购买许可证。

本教程是一个可靠的试用版,旨在为您提供有关内容存储库概念的切实见解,以及如何使用该JCR标准API进行集成,并为您提供与可能需要或者可能与其他存储库进行通信的其他选项。
可能无法为您提供一种标准的交流方式。

将Hymanrabbit运行到Apache

对Apache Hymanrabbit的定义与对JCR本身的定义并没有分开,JCR代表Java Content Repository或者Java的Content Repository API,它是Java平台的规范,用于以统一的方式访问内容库。

Apache Hymanrabbit内容存储库是针对Java技术API的内容存储库API(JCR – Java内容存储库)的完整且完全受投诉的实现,因此,其主要API由JCR定义。

Hymanrabbit支持所有JCR规范,实际上,Hymanrabbit 2.8支持JCR 2.0,而最后一个支持JCR 1.0的Hymanrabbit版本是Hymanrabbit 1.6。

要开始使用Hymanrabbit内容存储库并通过使用标准JCR 2.0与之通信,只需执行以下步骤:

  • 从Apache官方下载Hymanrabbit。

  • 将Hymanrabbit解压缩到您的目录中。
    我们假设您是在D:\Hymanrabbit \ Hymanrabbit-2.8.0上执行此操作的。

  • 打开您的Hymanrabbit-webapp并修改populate.jsp如下所示:

populate.jsp

<%-
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you Jan not use this file except in compliance with
the License.  You Jan obtain a copy of the License at

     https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--%><%@ page import="java.io.FilterInputStream,
                   java.io.IOException,
                   java.io.InputStream,
                   java.io.InputStreamReader,
                   java.net.URL,
                   java.net.URLConnection,
                   java.net.URLDecoder,
                   java.net.URLEncoder,
                   java.util.ArrayList,
                   java.util.Arrays,
                   java.util.Calendar,
                   java.util.Collections,
                   java.util.Iterator,
                   java.util.List,
                   javax.jcr.Node,
                   javax.jcr.Repository,
                   javax.jcr.Session,
                   javax.jcr.SimpleCredentials,
                   org.apache.Hymanrabbit.j2ee.RepositoryAccessServlet,
                   org.apache.Hymanrabbit.util.Text,
                   org.json.simple.JSONArray,
                   org.json.simple.JSONObject,
                   org.json.simple.JSONValue"
 %><%@ page contentType="text/html;charset=UTF-8" %><%
  Repository rep;
  Session jcrSession;
  String wspName;
  try {
      rep = RepositoryAccessServlet.getRepository(pageContext.getServletContext());
      jcrSession = rep.login(new SimpleCredentials("admin", "admin".toCharArray()));
      wspName = jcrSession.getWorkspace().getName();
  } catch (Throwable e) {
      %>Error while accessing the repository: <font color="red"><%= Text.encodeIllegalXMLCharacters(e.getMessage()) %></font><br><%
      %>Check the configuration or use the <a href="admin/">easy setup</a> wizard.<%
      return;
  }
  try {
      String seedWord = request.getParameter("seed");
      if (seedWord != null) {
          seedWord = new String(seedWord.getBytes("ISO-8859-1"), "UTF-8");
      }
      int numDocs = 0;
      List filetypes = new ArrayList();
      if (request.getParameter("num") != null) {
          try {
              numDocs = Integer.parseInt(request.getParameter("num"));
          } catch (NumberFormatException e) {
              //ignore
          }
      }
      String[] types = request.getParameterValues("filetype");
      if (types != null) {
          filetypes.addAll(Arrays.asList(types));
      } else {
          filetypes = DEFAULT_TYPES;
      }

if (seedWord != null && numDocs > 0 && filetypes.size() > 0) { %>
<html>
<head>
<title>Welcome to Apache Hymanrabbit - Populate workspace: <%= Text.encodeIllegalXMLCharacters(wspName) %></title>
<link rel="shortcut icon" href="<%= Text.encodeIllegalXMLCharacters(request.getContextPath()) %>/images/favicon.ico" type="image/vnd.microsoft.icon">
<style type="text/css" media="all">
    @import url("<%= Text.encodeIllegalXMLCharacters(request.getContextPath()) %>/css/default.css");
</style>
<script><!-
function draw() {
	//draw the bar
      document.write('<table cellspacing="0" cellpadding="0" style="border-color:' + this.borderColor + '; border-width:' + this.borderWidth + '; border-style:' + this.borderStyle + '">');
      document.write('<tr><td>');
      document.write('<table border="0" cellspacing="0" cellpadding="0" style="">');
      document.write('<tr><td style="background-color:' + this.barColor +'"><img src="<%= Text.encodeIllegalXMLCharacters(request.getContextPath()) %>/images/0.gif" id="' + this.id + 'barFG" width="0" height="' + this.height + '"</td>');
      document.write('<td><img src="<%= Text.encodeIllegalXMLCharacters(request.getContextPath()) %>/images/0.gif" id="' + this.id + 'barBG" width="' + this.width + '" height="' + this.height + '"</td></tr>');
      document.write('</table>');
      document.write('</tr></td>');
      document.write('</table>');
      document.write('<table>');
      document.write('<tr><td><img src="<%= Text.encodeIllegalXMLCharacters(request.getContextPath()) %>/images/0.gif" width="' + this.width + '" height="0"</td></tr>');
      document.write('<tr><td align="center"><span id="' + this.id + 'barValue">0%</td></tr>');
      document.write('<tr><td align="center"><span id="' + this.id + 'barInfo"> </td></tr>');
      document.write('</table>');

	this.barFG = document.getElementById(this.id + 'barFG');
	this.barBG = document.getElementById(this.id + 'barBG');
	this.barValue = document.getElementById(this.id + 'barValue').firstChild;
	this.barInfo = document.getElementById(this.id + 'barInfo').firstChild;
}

//informs the progress bar about the current value
function inform(value, info) {
	var barWidth = Math.floor(this.width * value/this.maxValue);
	var spaceWidth = this.width - barWidth;
	var perCent = Math.floor(100 * value/this.maxValue);
	this.barFG.width = barWidth;
	this.barBG.width = spaceWidth;
	this.barValue.nodeValue = perCent + '%';
	this.barInfo.nodeValue = info;
}

//constructor
function ProgressBar(maxValue, width, height) {
	this.maxValue = maxValue;
	this.width = width;
	this.height = height;
	this.id = '' + Math.round(Math.random() * 10000);
	this.inform = inform;
	this.draw = draw;
}

//default values
ProgressBar.prototype.barColor = "green";
ProgressBar.prototype.borderColor = "grey";
ProgressBar.prototype.borderStyle = "groove";
ProgressBar.prototype.borderWidth = "2px";

//-->
</script>
</head>
<body>
<div style="background: white; border: 1px solid black; padding: 50px; width: 510px; margin: 50px auto;">
<h2>Populate workspace: "<%= Text.encodeIllegalXMLCharacters(wspName) %>"</h2><br>
  <p>Overall progress</p>
  <script>var pb = new ProgressBar(<%= numDocs %>, 500, 30);pb.draw();</script>

  <p>Downloading document</p>
  <script>var dp = new ProgressBar(1000, 500, 30);dp.draw();</script>
  <%
          Node root = jcrSession.getRootNode();
          int n = 0;
          for (int typeIdx = 0; typeIdx < filetypes.size(); typeIdx++) {
              String type = (String) filetypes.get(typeIdx);
              int offset = 0;
              while (n < numDocs * (typeIdx + 1)/filetypes.size()) {
                  final URL[] urls = new Search(type, seedWord, offset).getURLs();
                  if (urls.length == 0) {
                      break;
                  }
                  for (int i = 0; i < urls.length; i++) {
                      final URL currentURL = urls[i];
                      String path = urls[i].getPath();
                      if (path.startsWith("/")) {
                          path = path.substring(1);
                      }
                      final String host = urls[i].getHost();
                      List folderNames = new ArrayList();
                      folderNames.addAll(Arrays.asList(host.split("\.")));
                      Collections.reverse(folderNames);
                      folderNames.addAll(Arrays.asList(path.split("/", 0)));
                      final String fileName = URLDecoder.decode((String) folderNames.remove(folderNames.size() - 1), "UTF-8").replaceAll(":", "_");
                      Node node = root;
                      for (Iterator fn = folderNames.iterator(); fn.hasNext(); ) {
                          String name = URLDecoder.decode((String) fn.next(), "UTF-8");
                          name = name.replaceAll(":", "_");
                          if (name.length() == 0) {
                              continue;
                          }
                          if (!node.hasNode(name)) {
                              node.addNode(name, "nt:folder");
                          }
                          node = node.getNode(name);
                      }
                      if (!node.hasNode(fileName)) {
                          final JspWriter fOut = out;
                          Node file = node.addNode(fileName, "nt:file");
                          final Node resource = file.addNode("jcr:content", "nt:resource");
                          final Exception[] ex = new Exception[1];
                          Thread t = new Thread(new Runnable() {
                              public void run() {
                                  try {
                                      String info = fileName + " (" + host + ")";
                                      URLConnection con = currentURL.openConnection();
                                      InputStream in = con.getInputStream();
                                      try {
                                          synchronized (fOut) {
                                              fOut.println("<script>dp.inform(0, '" + Text.encodeIllegalXMLCharacters(info) + "')</script>");
                                              fOut.flush();
                                          }
                                          int length = con.getContentLength();
                                          if (length != -1) {
                                              in = new ProgressInputStream(in, length, info, "dp", fOut);
                                          }
                                          resource.setProperty("jcr:data", in);
                                          String mimeType = URLConnection.guessContentTypeFromName(fileName);
                                          if (mimeType == null) {
                                              if (fileName.endsWith(".doc")) {
                                                  mimeType = "application/msword";
                                              } else if (fileName.endsWith(".xls")) {
                                                  mimeType = "application/vnd.ms-excel";
                                              } else if (fileName.endsWith(".ppt")) {
                                                  mimeType = "application/mspowerpoint";
                                              } else {
                                                  mimeType = "application/octet-stream";
                                              }
                                          }
                                          resource.setProperty("jcr:mimeType", mimeType);
                                          Calendar lastModified = Calendar.getInstance();
                                          lastModified.setTimeInMillis(con.getLastModified());
                                          resource.setProperty("jcr:lastModified", lastModified);
                                      } finally {
                                          in.close();
                                      }
                                  } catch (Exception e) {
                                      ex[0] = e;
                                  }
                              }
                          });
                          t.start();
                          for (int s = 0; t.isAlive(); s++) {
                              Thread.sleep(100);
                              if (s % 10 == 0) {
                                  synchronized (fOut) {
                                      fOut.println("<script>pb.inform(" + n + ", '')</script>");
                                      fOut.flush();
                                  }
                              }
                          }
                          if (ex[0] == null) {
                              jcrSession.save();
                              n++;
                              synchronized (fOut) {
                                  fOut.println("<script>pb.inform(" + n + ", '')</script>");
                                  fOut.flush();
                              }
                              if (n >= numDocs * (typeIdx + 1)/filetypes.size()) {
                                  break;
                              }
                          } else {
                              jcrSession.refresh(false);
                          }
                      }
                  }
                  offset += 10;
              }
          }
%>  </div>
</body>
</html>
<% } else {
request.setAttribute("title", "Populate workspace " + wspName);
%><jsp:include page="header.jsp"
<p>
This page allows you to populate the workspace with documents downloaded
from the Internet.
</p>
  <form method="POST">
    <table>
    <tr><td>Seed word (optional):</td><td><input name="seed" type="text" size="30" value="<%= seedWord == null ? "" : Text.encodeIllegalXMLCharacters(seedWord) %>"</td></tr>
    <tr><td>Number of documents:</td><td><input name="num" type="text" size="30" value="<%= numDocs == 0 ? 100 : numDocs %>"</td></tr>
    <tr valign="top"><td>Document types:</td><td><input name="filetype" type="checkbox" value="pdf" <%= filetypes.contains("pdf") ? "checked" : "" %> Adobe Acrobat PDF<br<input name="filetype" type="checkbox" value="rtf" <%= filetypes.contains("rtf") ? "checked" : "" %> Rich Text Format<br<input name="filetype" type="checkbox" value="doc" <%= filetypes.contains("doc") ? "checked" : "" %> Microsoft Word<br<input name="filetype" type="checkbox" value="ppt" <%= filetypes.contains("ppt") ? "checked" : "" %> Microsoft PowerPoint<br<input name="filetype" type="checkbox" value="xls" <%= filetypes.contains("xls") ? "checked" : "" %> Microsoft Excel<br</td></tr>
    <tr><td> </td><td><input type="submit" value="Populate!"</td></tr>
    </table>
  </form>
<jsp:include page="footer.jsp"
<%    }
  } finally {
      if (jcrSession != null) {
          jcrSession.logout();
      }
  }
%><%!

  public static final List DEFAULT_TYPES = Arrays.asList(
          new String[]{"pdf", "rtf", "doc", "ppt", "xls"});

  public static class Search {

      private static final String CHARSET = "UTF-8";

      private final String filetype;

      private final String term;

      private final int start;

      public Search(String filetype, String term, int start) {
          this.filetype = filetype;
          this.term = term;
          this.start = start;
      }

      public URL[] getURLs() throws Exception {
          List<URL> urls = new ArrayList<URL>();
          String googleBaseUrl = "https://ajax.googleapis.com/ajax/services/search/web";
          String googleQueryString = "?v=1.0&start=" + start + "&rsz=8&q=";
          String query = term + " filetype:" + this.filetype;
          URL google = new URL(googleBaseUrl + googleQueryString + URLEncoder.encode(query, CHARSET));
          InputStreamReader reader = null;
          try {
              URLConnection conn = google.openConnection();
              conn.setRequestProperty("Referer", "https://Hymanrabbit.apache.org/");
              reader = new InputStreamReader(conn.getInputStream(), CHARSET);
              Object obj = JSONValue.parse(reader);
              JSONObject jsonObject = (JSONObject) obj;
              JSONObject responseData = (JSONObject) jsonObject.get("responseData");
              if (responseData != null) {
                  JSONArray results = (JSONArray) responseData.get("results");
                  if (results != null) {
                      for (int i = 0; i < results.size(); i++) {
                          JSONObject result = (JSONObject) results.get(i);
                          if (result != null) {
                              String urlString = (String) result.get("url");
                              URL url = new URL(new URL("http", "www.google.com", "dummy"), urlString);
                              if (!url.getHost().contains("google")) {
                                  urls.add(url);
                              }
                          }
                      }
                  }
              }
          } finally {
              reader.close();
          }
          return urls.toArray(new URL[urls.size()]);
      }
  }

  public static class ProgressInputStream extends FilterInputStream {

      private final int length;

      private final String fileName;

      private final String varName;

      private final JspWriter out;

      private long read;

      private long nextReport = (16 * 1024);

      public ProgressInputStream(InputStream in, int length, String fileName,
                                 String varName, JspWriter out) {
          super(in);
          this.length = length;
          this.fileName = fileName;
          this.varName = varName;
          this.out = out;
      }

      public int read() throws IOException {
          int r = super.read();
          reportProgress(r);
          return r;
      }

      public int read(byte b[]) throws IOException {
          int r = super.read(b);
          reportProgress(r);
          return r;
      }

      public int read(byte b[], int off, int len) throws IOException {
          int r = super.read(b, off, len);
          reportProgress(r);
          return r;
      }

      private void reportProgress(int r) throws IOException {
          if (r != -1) {
              read += r;
              if (read > nextReport || read == length) {
                  //report every 16k
                  synchronized (out) {
                      double s = 1000d * (double) read/(double) length;
                      out.println("<script>" + varName + ".inform(" +
                              Math.min((int) Math.ceil(s), 1000) +
                              ", '" + Text.encodeIllegalXMLCharacters(fileName) + "')</script>");
                      out.flush();
                  }
                  nextReport += (16 * 1024);
              }
          }
      }
  }
%>
  • 对您的Hymanrabbit-webapp项目执行mvn clean install

  • 您已经在计算机中安装了Maven以及就绪的系统变量。

  • 您应该为以后的Maven命令获得成功的构建,如下所示。

  • 打开您的Eclipse。

  • 创建新的Apache Tomcat 7服务器。

  • 通过设置如下所示的服务器位置来配置创建的Apache Tomcat:

  • 从您的Hymanrabbit-webapp项目部署Hymanrabbit Web应用程序。

  • 从此处将JCR 2.0 API JAR下载到您的Apache Tomcat库中。

  • 从Eclipse运行Tomcat服务器。

  • 访问" https://localhost:8080/Hymanrabbit-webapp-2.8.0 /"以打开Apache Hymanrabbit的主页。

  • 通过单击创建内容存储库来创建新的存储库。
    就像您在上面看到的那样,您的存储库主目录将是Hymanrabbit。

  • 现在,您可以在Eclipse控制台下列出的我的存储库配置以及我的存储库都在D:\theitroad \ eclipse \ Hymanrabbit中创建。

Hymanrabbit配置

2014-12-30 20:42:34.499 INFO  [http-bio-8080-exec-7] Installer.java:159 Creating new repository home 'Hymanrabbit'
2014-12-30 20:42:34.500 INFO  [http-bio-8080-exec-7] Installer.java:197 Creating new repository config: Hymanrabbit\repository.xml
2014-12-30 20:42:34.505 INFO  [http-bio-8080-exec-7] Installer.java:221 Creating new bootstrap properties: Hymanrabbit\bootstrap.properties
2014-12-30 20:42:34.527 INFO  [http-bio-8080-exec-7] RepositoryStartupServlet.java:253 RepositoryStartupServlet initializing...
2014-12-30 20:42:34.528 INFO  [http-bio-8080-exec-7] AbstractConfig.java:101 Configuration of BootstrapConfig
2014-12-30 20:42:34.528 INFO  [http-bio-8080-exec-7] AbstractConfig.java:102 ---------------------------------------------
2014-12-30 20:42:34.536 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   valid: true
2014-12-30 20:42:34.536 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiConfig: org.apache.Hymanrabbit.j2ee.RMIConfig@36db4bcf
2014-12-30 20:42:34.536 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   repositoryConfig: Hymanrabbit\repository.xml
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   class: class org.apache.Hymanrabbit.j2ee.BootstrapConfig
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   repositoryHome: Hymanrabbit
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   repositoryName: Hymanrabbit.repository
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   jndiConfig: org.apache.Hymanrabbit.j2ee.JNDIConfig@774e1f2b
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:108 ---------------------------------------------
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:101 Configuration of JNDIConfig
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:102 ---------------------------------------------
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   valid: true
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   jndiName: Hymanrabbit.repository
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   jndiEnabled: true
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   class: class org.apache.Hymanrabbit.j2ee.JNDIConfig
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   jndiEnv: {java.naming.provider.url=https://www.apache.org/Hymanrabbit, java.naming.factory.initial=org.apache.Hymanrabbit.core.jndi.provider.DummyInitialContextFactory}
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:108 ---------------------------------------------
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:101 Configuration of RMIConfig
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:102 ---------------------------------------------
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   valid: true
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiName: Hymanrabbit.repository
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   class: class org.apache.Hymanrabbit.j2ee.RMIConfig
2014-12-30 20:42:34.540 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiUri: //localhost:1099/Hymanrabbit.repository
2014-12-30 20:42:34.540 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiPort: 1099
2014-12-30 20:42:34.540 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiEnabled: true
2014-12-30 20:42:34.540 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiHost: localhost
2014-12-30 20:42:34.540 INFO  [http-bio-8080-exec-7] AbstractConfig.java:108 ---------------------------------------------
2014-12-30 20:42:34.810 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:258 Starting repository...
2014-12-30 20:42:34.816 INFO  [http-bio-8080-exec-7] LocalFileSystem.java:166 LocalFileSystem initialized at path D:\theitroad\eclipse\Hymanrabbit\repository
2014-12-30 20:42:35.011 INFO  [http-bio-8080-exec-7] NodeTypeRegistry.java:841 no custom node type definitions found
2014-12-30 20:42:35.094 INFO  [http-bio-8080-exec-7] LocalFileSystem.java:166 LocalFileSystem initialized at path D:\theitroad\eclipse\Hymanrabbit\version
2014-12-30 20:42:44.290 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:2034 initializing workspace 'default'...
2014-12-30 20:42:44.291 INFO  [http-bio-8080-exec-7] LocalFileSystem.java:166 LocalFileSystem initialized at path D:\theitroad\eclipse\Hymanrabbit\workspaces\default
2014-12-30 20:42:52.648 INFO  [http-bio-8080-exec-7] ClusterNode.java:432 not started: namespace operation ignored.
2014-12-30 20:42:52.657 INFO  [http-bio-8080-exec-7] ClusterNode.java:432 not started: namespace operation ignored.
2014-12-30 20:42:52.663 INFO  [http-bio-8080-exec-7] ClusterNode.java:432 not started: namespace operation ignored.
2014-12-30 20:42:53.948 INFO  [http-bio-8080-exec-7] MultiIndex.java:1221 indexing... /jcr:system/jcr:nodeTypes/rep:Token/jcr:propertyDefinition (100)
2014-12-30 20:42:54.451 INFO  [http-bio-8080-exec-7] SearchIndex.java:602 Index initialized: D:\theitroad\eclipse\Hymanrabbit/repository/index Version: 3
2014-12-30 20:42:54.537 INFO  [http-bio-8080-exec-7] SearchIndex.java:602 Index initialized: D:\theitroad\eclipse\Hymanrabbit\workspaces\default/index Version: 3
2014-12-30 20:42:54.537 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:2038 workspace 'default' initialized
2014-12-30 20:42:54.544 INFO  [http-bio-8080-exec-7] ClusterNode.java:1064 not started: namespace operation ignored.
2014-12-30 20:42:54.545 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:546 created system workspace: security
2014-12-30 20:42:54.552 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:454 SecurityManager = class org.apache.Hymanrabbit.core.DefaultSecurityManager
2014-12-30 20:42:54.553 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:2034 initializing workspace 'security'...
2014-12-30 20:42:54.553 INFO  [http-bio-8080-exec-7] LocalFileSystem.java:166 LocalFileSystem initialized at path D:\theitroad\eclipse\Hymanrabbit\workspaces\security
2014-12-30 20:43:02.458 INFO  [http-bio-8080-exec-7] SearchIndex.java:602 Index initialized: D:\theitroad\eclipse\Hymanrabbit\workspaces\security/index Version: 3
2014-12-30 20:43:02.459 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:2038 workspace 'security' initialized
2014-12-30 20:43:02.470 INFO  [http-bio-8080-exec-7] DefaultSecurityManager.java:173 init: use Repository Login-Configuration for Hymanrabbit
2014-12-30 20:43:02.512 INFO  [http-bio-8080-exec-7] UserManagerImpl.java:446 Admin user does not exist.
2014-12-30 20:43:02.793 INFO  [http-bio-8080-exec-7] ClusterNode.java:631 not started: update create ignored.
2014-12-30 20:43:02.803 INFO  [http-bio-8080-exec-7] ClusterNode.java:652 not started: update prepare ignored.
2014-12-30 20:43:02.840 INFO  [http-bio-8080-exec-7] ClusterNode.java:695 not started: update commit ignored.
2014-12-30 20:43:02.857 INFO  [http-bio-8080-exec-7] UserManagerImpl.java:1010 ... created admin user with id 'admin' and default pw.
2014-12-30 20:43:02.886 INFO  [http-bio-8080-exec-7] ClusterNode.java:631 not started: update create ignored.
2014-12-30 20:43:02.887 INFO  [http-bio-8080-exec-7] ClusterNode.java:652 not started: update prepare ignored.
2014-12-30 20:43:02.915 INFO  [http-bio-8080-exec-7] ClusterNode.java:695 not started: update commit ignored.
2014-12-30 20:43:02.918 INFO  [http-bio-8080-exec-7] DefaultSecurityManager.java:627 ... created anonymous user with id 'anonymous' ...
2014-12-30 20:43:02.967 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:366 Repository started (28157ms)
2014-12-30 20:43:03.230 INFO  [http-bio-8080-exec-7] RepositoryStartupServlet.java:597 Repository bound via RMI with name: //localhost:1099/Hymanrabbit.repository
2014-12-30 20:43:03.234 INFO  [http-bio-8080-exec-7] RepositoryStartupServlet.java:487 Repository bound to JNDI with name: Hymanrabbit.repository
2014-12-30 20:43:03.234 INFO  [http-bio-8080-exec-7] RepositoryStartupServlet.java:260 RepositoryStartupServlet initialized.
  • 通过单击左窗格的默认工作区下面的Populate链接来填充来自Google的随机内容,接受所有选项,然后按Populate!然后等到内容收集过程完成
<p>Don't miss the step that's fixing the populate.jsp mentioned later. Even you Jan use the latest version of Hymanrabbit 2.8.0 but actually this is also contained a known bug in populate page that prevents you from populating contents.</p>
  • 为确保您确实将内容填充到存储库中,只需访问以下链接https://localhost:8080/Hymanrabbit-webapp-2.8.0/repository/default /此链接也称为WebDAV客户端。
    可能会要求您提供用户名和密码,而其中的任何一个都足够公平。
    WebDAV是可用于访问存储库内容的方法之一。
    以后可以考虑采用不同的方式。

  • 按照上面的链接将您的内容访问到存储库中,就像下图所示。
    标记为黄色的URL已链接到PDF文档。

JCR/JSR 170和283入门

不提内容存储库的主要概念就不适合开始讨论JCR/JSR 170。
首先让我们定义存储库模型,一个内容存储库由一个或者多个工作区组成,每个工作区都包含一棵项目树。

基本上,树中的每个项目都是节点或者属性,每个节点可以具有零个或者多个子节点以及零个或者多个子属性。
每个工作区只有一个根节点,没有父节点。
所有其他节点都有一个父节点。
财产有一个父母,不能有孩子;它们实际上是树上的叶子。

下图描述了存储库的外观:

下面是上述图的详细说明:

  • 对于每个工作区,只有一个根节点。

  • 每个根节点都有许多作为子节点的节点。

  • 每个节点都有一个节点或者属性。

  • 节点可能有也可能没有孩子,而属性则永远不会有孩子。

现在,让我们看看JCR/JSR 170的API基础知识,以及如何利用它来连接Hymanrabbit内容存储库。
以下是有关JCR/JSR 170/283 API的主要要点:

  • javax.jcr.Repository类代表您可能连接的整个存储库的引用。
    实际上,这是存储库的入口点。

  • 针对您的Repository实例调用getRootNode()将返回默认工作空间的Root节点。

  • 您可以通过使用node.getProperties()获得节点的所有属性。

  • 您可以通过调用node.getNodes()获得所有节点的子节点。

  • 您可以获取特定节点的特定属性,就像获取为其创建节点的二进制数据一样。

实际上,在讨论内容存储库概念时,您需要处理很多事情。
数据管理,查询工具,事务以及更多内容可能是下一本教程的主题,这些教程绝对可以为您提供全面的知识,而专注于此处发生的集成。

访问存储库–本地访问/JNDI

即使Hymanrabbit通过" Hymanrabbit-webapp-2.8.0"本地的Dummy JNDI目录定义了其存储库,但实际上该资源不是Global JNDI资源,因为您无法在Web应用程序中定义" ResourceLink"来访问此定义的存储库实例。

实际上,您可以参考Pankaj撰写的出色文章来定义JNDI资源,并了解本地资源和全局资源之间的区别,因为定义Hymanrabbit Repository Global资源的过程可能需要您了解很多与该领域相关的信息。

遵循以下定义Hymanrabbit存储库所需的步骤,然后通过一个简单的Servlet对其进行访问:

  • 确保您能够通过WebDAV查看存储库内容,如前所述。
    通过访问https://localhost:8080/Hymanrabbit-webapp-2.8.0/repository/default / URL将通过调用本地定义的JNDI来检索所有内容,并确保已正确安装了存储库。

  • 关闭您的服务器(Apache Tomcat 7),并确保已删除已展开的文件夹" Hymanrabbit-webapp-2.8.0"或者WAR副本,以防止此Hymanrabbit Web应用程序锁定存储库。

  • 打开位于Apache Server主目录下的conf目录下的server.xml文件。

  • 将您的存储库全局存储库资源添加到您的GlobalNamingResources中,如下所示:

server.xml

<GlobalNamingResources>
  <!-- Editable user database that can also be used by
       UserDatabaseRealm to authenticate users
  -->
  <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"

	<Resource configFilePath="D:\theitroad\eclipse\Hymanrabbit\repository.xml"
			  factory="org.apache.Hymanrabbit.core.jndi.BindableRepositoryFactory"
			  name="Hymanrabbit.repository" repHomeDir="D:\theitroad\eclipse\Hymanrabbit"
			  type="javax.jcr.Repository"
			  auth="Container" 
</GlobalNamingResources>
  • 将所有JAR文件从Hymanrabbit-webapp-2.8.0 \ WEB-INF \ lib复制到Tomact的库文件夹" D:\Apache Api \ apache-tomcat-7.0.35 \ lib"中。
    这恰好使创建存储库JNDI全局资源成为可能。

  • 创建Maven Web应用程序。

  • 通过使用JNDI创建简单的Servlet来获取JCR Repository实例,如下所示:

LocalAccess.java

package com.theitroad.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Properties;

import javax.jcr.LoginException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.users.MemoryUserDatabase;

/**
 * Servlet implementation class LocalAccess
 */
public class LocalAccess extends HttpServlet {
	private static final long serialVersionUID = 1L;

  /**
   * Default constructor.
   */
  public LocalAccess() {
      //TODO Auto-generated constructor stub
  }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {

			//Acquire initial context
			InitialContext context = new InitialContext();

			//Print out context reference
			System.out.println(context);

			//Access environment context
			Context envCtx = (Context)context.lookup("java:comp/env");

			//Lookup JNDI local resource
			MemoryUserDatabase memoryDB = (MemoryUserDatabase)
					  envCtx.lookup("jdbc/MyDB");

			//Print out the memoryUserDatabase reference
			System.out.println(memoryDB);

			//Lookup Global JNDI for JCR Repository
			Repository repository = (Repository) envCtx.lookup("Hymanrabbit.repository");

			//Print out reference variable
			System.out.println(repository);

			//Get Repository session by loggin into
			Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			response.getWriter().print("You're logged in successfully ::");
			//Print out the root node
			System.out.println(session.getRootNode());

			response.getWriter().print("Repository Acquired :: Root Node Identifier Is :: "+session.getRootNode().getIdentifier()+" & Its Path Is :: "+session.getRootNode().getPath());

		} catch (NamingException e) {
			e.printStackTrace();
		} catch (LoginException e) {
			//TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RepositoryException e) {
			//TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
  • 您可以在web.xml中定义任意数量的资源,但是由于资源创建的限制和要求,您可能无法定义其中的一些资源。
    为此,Tomcat定义了应在webapp/META-INF/context.xml下定义的context.xml文件才能生效。
    以下是LocalAccess应用程序的上下文文件。

context.xml

<Context path="/LocalAccess" docBase="${catalina.home}/webapps/LocalAccess" crossContext="true"
			privileged="true" antiResourceLocking="false" antiJARLocking="false">
	<GlobalNamingResources>
		<Resource name="jdbc/MyDB" auth="Container"
		            type="org.apache.catalina.UserDatabase"
		     			description="Memory Database"
		     			factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
	</GlobalNamingResources>
	<ResourceLink name="jdbc/MyDB"
          global="jdbc/MyDB"
          	type="org.apache.catalina.UserDatabase"
          		description="Memory Database"
		     			factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
	<ResourceLink name="Hymanrabbit.repository"
          global="Hymanrabbit.repository"
		        auth="Container"
		        	type="javax.jcr.Repository"
</Context>

目前,您已经采取了很多步骤,其中大多数步骤都需要为您澄清。
以下是上面列出的代码的详细说明:

  • 通过参考Pankaj教程,您可能能够知道所提到的这些资源。
    我们在server.xml中定义了两个全局资源,在本地定义了三个资源(在context.xml中与LocalAccess相关)。

  • 如果您未在localAccess的上下文文件中为其提供资源链接,则可能无法访问在server.xml中定义的存储库全局JNDI资源。

  • 根据Apache Tomcat的说法,不建议使用server.xml来定义您的上下文和/或者全局资源,因为该文件没有得到反映,而是在Tomcat服务器重新启动时反映出来的。

  • 您可以在许多情况下使用本地上下文文件,真是太好了。

  • 在特殊情况下,如果您在本地定义存储库,则可能看不到初始化的存储库,因此您可以在上面的server.xml中看到其全局定义。

  • Apache Tomcat为在其下运行的每个Web应用程序/上下文提供了一个JNDI InitialContext实现实例。
    因此,您可以安全地使用InitialContext ctx = new InitialContext()。

  • 您可能会注意到,我们已经使用Hymanrabbit-webapp.2.8.0来初始化Hymanrabbit信息库,然后我们省略了它。
    如果您在Tomcat的web应用程序下仍定义" Hymanrabbit-webapp.2.8.0"的同时定义Global JNDI资源,则由于Global JNDI资源已锁定存储库,因此Hymanrabbit-webapp.2.8.0将会失败。

现在,在下面查看预期的结果:

在此处找到通过JNDI示例获取Hymanrabbit存储库。

访问存储库–本地访问/Servlet上下文

与以前的JNDI资源相比,这种访问Hymanrabbit存储库的类型非常容易。
其中您所需要做的只是配置上下文以支持跨上下文,因此,您可以通过从Hymanrabbit-webapp-2.8.0上下文属性获取它来访问Hymanrabbit存储库。

如果已打印出Hymanrabbit-webapp-2.8.0内部的所有已定义属性,则将看到以下结果:

LocalAccess-Context属性

javax.jcr.Repository
Hymanrabbit.webdav.jcr.resourcepath
org.apache.tomcat.InstanceManager
org.apache.catalina.jsp_classpath
repository.access.servlet
Hymanrabbit.webdav.simple.resourcepath
org.apache.tomcat.util.scan.MergedWebXml
javax.servlet.context.tempdir
org.apache.catalina.resources
org.apache.tomcat.JarScanner
org.apache.jasper.compiler.comLocationsCache
repository.startup.servet

根据之前的结果,有一个名为javax.jrc.Repository的属性绑定到真实的Hymanrabbit Repository实例中。
要使用此方法,您可以按照以下步骤操作:

  • 创建新的Maven Web应用程序。
    我们假定您创建了LocalAccess-Context。

  • 如下所示创建LocalAccess Servlet并使用ServletContext访问Hymanrabbit-webapp-2.8.0中定义的存储库实例。

LocalAccess.java

package com.theitroad.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Properties;

import javax.jcr.LoginException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.users.MemoryUserDatabase;

/**
 * Servlet implementation class LocalAccess
 */
public class LocalAccess extends HttpServlet {
	private static final long serialVersionUID = 1L;

  /**
   * Default constructor.
   */
  public LocalAccess() {
      //TODO Auto-generated constructor stub
  }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			//Acquire ServletContext
			ServletContext context = this.getServletContext();

			//Asking ServletContext get you Hymanrabbit context
			ServletContext HymanrabbitCtx = context.getContext("/Hymanrabbit-webapp-2.8.0");

			//Get all attributes
			Enumeration<String> enums = HymanrabbitCtx.getAttributeNames();

			for(;enums.hasMoreElements();){
				System.out.println(enums.nextElement());
			}

			Repository repository = (Repository)HymanrabbitCtx.getAttribute(Repository.class.getName());

			//Print out reference variable
			System.out.println(repository);

			//Get Repository session by loggin into
			Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			response.getWriter().print("You're logged in successfully ::");
			//Print out the root node
			System.out.println(session.getRootNode());

			response.getWriter().print("Repository Acquired :: Root Node Identifier Is :: "+session.getRootNode().getIdentifier()+" & Its Path Is :: "+session.getRootNode().getPath());
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

}

以下是上面列出的代码的详细说明:

  • 我们假设为您提供了属性为crossContext =" true"的"context.xml`文件。
    如果没有提供,则可能会因CauseNullPointerException导致异常,因为context.getContext("/Hymanrabbit-webapp-2.8.0")没有返回任何实例。

  • Hymanrabbit-webapp-2.8.0已将Hymanrabbit存储库引用定义为属性。

  • 确保已启动并运行Hymanrabbit-webapp-2.8.0。

在此处找到通过上下文属性示例获取Hymanrabbit存储库。

访问存储库–本地访问/JCR-Servlet

这种存储库访问方式与使用Hymanrabbit-webapp-2.8.0上下文的旧版本不同。
区别在于,您现在使用的是Hymanrabbit提供的新Maven库,可以从上下文中具有javax.jcr.Repository实例的任何HttpServlet创建一个Repository。

要使用此方法,请执行以下步骤:

  • 创建Maven Web应用程序。

  • 在您的应用程序内部创建一个Servlet,使其看起来如下所示:

LocalAccess.java

package com.theitroad.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Properties;

import javax.jcr.LoginException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.users.MemoryUserDatabase;
import org.apache.Hymanrabbit.servlet.ServletRepository;

/**
 * Servlet implementation class LocalAccess
 */
public class LocalAccess extends HttpServlet {
	private static final long serialVersionUID = 1L;

  /**
   * Default constructor.
   */
  public LocalAccess() {
      //TODO Auto-generated constructor stub
  }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {

			//Acquire ServletContext
			ServletContext context = this.getServletContext();

			//Asking ServletContext get you Hymanrabbit context
			ServletContext HymanrabbitCtx = context.getContext("/Hymanrabbit-webapp-2.8.0");

			//Create Repository through using of ServletRepository
			Repository repository = new ServletRepository((HttpServlet)HymanrabbitCtx.getAttribute("repository.access.servlet"));

			//Print out reference variable
			System.out.println(repository);

			//Get Repository session by loggin into
			Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			response.getWriter().print("You're logged in successfully ::");
			//Print out the root node
			System.out.println(session.getRootNode());

			response.getWriter().print("Repository Acquired :: Root Node Identifier Is :: "+session.getRootNode().getIdentifier()+" & Its Path Is :: "+session.getRootNode().getPath());
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

}

以下是上面列出的代码的详细说明:

  • 我们在您的项目依赖项中添加了Hymanrabbit-jcr-servlet Maven库。

  • 就像以前一样,我们已经获得了Hymanrabbit Servlet上下文。

  • 我们获得了在Hymanrabbit上下文中定义的repository.access.servlet的HttpServlet参考。

  • 将Hymanrabbit获得的Servlet传递到ServletRepository中,稍后后者将能够识别所传递的Servlet中的Repository,它将为您返回一个Repository实例。

  • 确保已启动并运行Hymanrabbit-webapp-2.8.0。

在这里找到通过JCR Servlet示例获取Hymanrabbit存储库。

访问存储库–远程访问/RMI

Hymanrabbit Repository已像您的消费者应用程序一样部署在同一台计算机上,从而满足了所有以前的方法。
但是,如果要从完全不同的虚拟机访问存储库,该怎么办。

解决方案是通过直接使用RMI注册表或者通过HTTP协议引用它来使用RMI注册表。
请按照以下步骤进行操作:

  • 创建Maven Web应用程序。

  • Hymanrabbit-jcr-rmi依赖项添加到Pom文件中。

  • 创建简单的Servlet的外观如下所示:

RemoteAccess.java

package com.theitroad.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.users.MemoryUserDatabase;
import org.apache.Hymanrabbit.rmi.repository.RMIRemoteRepository;
import org.apache.Hymanrabbit.rmi.repository.URLRemoteRepository;

/**
 * Servlet implementation class LocalAccess
 */
public class RemoteAccess extends HttpServlet {
	private static final long serialVersionUID = 1L;

  /**
   * Default constructor.
   */
  public RemoteAccess() {
      //TODO Auto-generated constructor stub
  }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			//Acquiring Repository using RMI Registry
			Repository repository =
				    new RMIRemoteRepository("//localhost/Hymanrabbit.repository");

			response.getWriter().print("Repository Is Acquired By Using RMI Registry :: "+repository +"\n");
			//Acquiring Repository using direct HTTP
			Repository repo =
				    new URLRemoteRepository("https://localhost:8080/Hymanrabbit-webapp-2.8.0/rmi");

			response.getWriter().print("Repository Is Acquired By Using HTTP RMI Registry :: "+repo +"\n");

			//Get Repository session by loggin into
			Session rmiSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			response.getWriter().print("You're logged in successfully Using RMI :: \n");
			//Print out the root node
			System.out.println(rmiSession.getRootNode());

			response.getWriter().print("Repository Acquired :: Root Node Identifier Is :: "+rmiSession.getRootNode().getIdentifier()+" & Its Path Is :: "+rmiSession.getRootNode().getPath()+"\n");

			//Get Repository session by loggin into
			Session httpRmiSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			response.getWriter().print("You're logged in successfully Using HTTP RMI :: \n");
			//Print out the root node
			System.out.println(httpRmiSession.getRootNode());

			response.getWriter().print("Repository Acquired :: Root Node Identifier Is :: "+httpRmiSession.getRootNode().getIdentifier()+" & Its Path Is :: "+httpRmiSession.getRootNode().getPath()+"\n");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
  • 通过使用RMI注册表访问Hymanrabbit存储库。
    可以通过直接访问RMI或者通过HTTP协议访问它来实现。
    两种情况都可以确保您获得了Hymanrabbit存储库存根。

  • 确保已启动并运行Hymanrabbit-webapp-2.8.0。

在此处找到通过RMI示例进行的存储库访问。

Apache Pluto和Hymanrabbit集成

不管您访问Hymanrabbit存储库的方式如何,无论您需要进行哪种类型的操作以进行集成,这都是一个简单的Portlet,它能够通过使用JCR/JSR 170/283标准库与Apache Hymanrabbit Content Repository通信。

遵循以下步骤来实现此目标所需的一切:

  • 确保您熟悉Apache Pluto门户,创建Portlet,创建门户页面并将Portlet部署到门户页面等,这些内容可以在Apache Pluto入门教程中找到。

  • 我将使用RMI来实现这一目标,因为Hymanrabbit-webapp-2.8.0已经部署在Apache 7上,而Apache Pluto Portal将部署在不同的Apache Tomcat实例上。

  • 就像在入门教程中一样,将Apache Pluto导入到Eclipse中。
    您现在需要做的一项主要修改是修改服务器端口,如下所示:

  • 修改tomcat-users.xml以确保tomcat用户已正确认证和授权。
    您的文件应类似于简介中已配置的文件。

  • 从Eclipse运行Apache Pluto并访问新的端口,它应该可以正常工作。

  • 创建名为JCR-Integration的Maven Web应用程序,并添加所有Apache Pluto随附的文件,例如portlet.xml和那些重要的Pom.xml条目。
    简介中已经对此进行了介绍,您可以从此处进行引用。

  • 将JCR标准API和RMI依赖项都添加到Pom.xml文件中。
    在下面查看文件:

pom.xml

<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.theitroad</groupId>
	<artifactId>JCR-Integration</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>JCR-Integration</name>
	<url>https://maven.apache.org</url>
	<properties>
		<deployFolder>D:/ApachePluto/pluto-2.0.3/webapps</deployFolder>
	</properties>
	<dependencies>
		<!-- Java Portlet Specification V2.0 -->
		<dependency>
			<groupId>org.apache.portals</groupId>
			<artifactId>portlet-api_2.0_spec</artifactId>
			<version>1.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.4</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>commons-beanutils</groupId>
			<artifactId>commons-beanutils</artifactId>
			<version>1.7.0</version>
		</dependency>
		<dependency>
			<groupId>commons-collections</groupId>
			<artifactId>commons-collections</artifactId>
			<version>3.1</version>
		</dependency>
		<dependency>
			<groupId>commons-digester</groupId>
			<artifactId>commons-digester</artifactId>
			<version>1.7</version>
		</dependency>
		<dependency>
			<groupId>commons-digester</groupId>
			<artifactId>commons-digester</artifactId>
			<version>1.7</version>
		</dependency>
		<dependency>
			<groupId>org.apache.velocity</groupId>
			<artifactId>velocity</artifactId>
			<version>1.5</version>
		</dependency>
		<dependency>
			<groupId>org.apache.velocity</groupId>
			<artifactId>velocity-tools</artifactId>
			<version>2.0</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.pluto</groupId>
			<artifactId>pluto-taglib</artifactId>
			<version>1.1.7</version>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.32</version>
		</dependency>
		<dependency>
			<groupId>org.apache.portals.bridges</groupId>
			<artifactId>portals-bridges-perl</artifactId>
			<version>1.0.4</version>
			<exclusions>
				<exclusion>
					<groupId>org.apache.portals.jetspeed-2:</groupId>
					<artifactId>jetspeed-rewriter</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.apache.portals.jetspeed-2</groupId>
			<artifactId>jetspeed-rewriter</artifactId>
			<version>2.1.4</version>
			<exclusions>
				<exclusion>
					<groupId>castor</groupId>
					<artifactId>castor</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>castor</groupId>
			<artifactId>castor</artifactId>
			<version>1.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.portals.bridges</groupId>
			<artifactId>portals-bridges-common</artifactId>
			<version>2.0</version>
		</dependency>
		<dependency>
			<groupId>javax.jcr</groupId>
			<artifactId>jcr</artifactId>
			<version>2.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.Hymanrabbit</groupId>
			<artifactId>Hymanrabbit-jcr-rmi</artifactId>
			<version>2.8.0</version>
		</dependency>
	</dependencies>
	<build>
		<finalName>${project.artifactId}</finalName>
		<plugins>
			<!-- bind 'pluto2:assemble' goal to 'process-resources' lifecycle -->
			<!-- This plugin will read your portlet.xml and web.xml and injects required
				lines -->
			<plugin>
				<groupId>org.apache.portals.pluto</groupId>
				<artifactId>maven-pluto-plugin</artifactId>
				<version>2.1.0-M3</version>
				<executions>
					<execution>
						<id>generate-sources</id>
						<phase>generate-sources</phase>
						<goals>
							<goal>assemble</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<!-- configure maven-war-plugin to use updated web.xml -->
			<!-- This plugin will make sure your WAR will contain the updated web.xml -->
			<plugin>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.1.1</version>
				<configuration>
					<webXml>${project.build.directory}/pluto-resources/web.xml</webXml>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>
					<execution>
						<id>copy</id>
						<phase>integration-test</phase>
						<configuration>
							<tasks>
								<copy file="target/${project.artifactId}.war" tofile="${deployFolder}/${project.artifactId}.war" 
							</tasks>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
					<execution>
						<id>delete</id>
						<phase>clean</phase>
						<configuration>
							<tasks>
								<delete file="${deployFolder}/${project.artifactId}.war" 
								<delete dir="${deployFolder}/${project.artifactId}" 
							</tasks>
							<detail>true</detail>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

同样,您可能会在下面找到一个现成的Portlet,该Portlet旨在遍历您的存储库中的所有宇宙并将所有二进制文档暴露在C:/files下的假定目录内。

JCRIntegrator.java

package com.theitroad.portlet;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Value;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.apache.Hymanrabbit.rmi.repository.URLRemoteRepository;

public class JCRIntegrator extends GenericPortlet{
	private Repository repository = null;
	private Session session = null;

	{
		try {
			//Acquiring Repository using RMI Registry
			this.repository =
				    new URLRemoteRepository("https://localhost:8080/Hymanrabbit-webapp-2.8.0/rmi");

			System.out.println("Repository Is Acquired By Using RMI Registry :: "+repository +"\n");

			//Get Repository session by log into
			this.session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			System.out.println("You're logged in successfully Using RMI :: \n");
			//Print out the root node
			System.out.println(this.session.getRootNode());

			System.out.println("Repository Acquired :: Root Node Identifier Is :: "+this.session.getRootNode().getIdentifier()+
						" & Its Path Is :: "+this.session.getRootNode().getPath()+"\n");
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

	public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
		try {

			if(this.session.isLive()){
				//Get root node for the current workspace
				Node root = this.session.getRootNode();

				//Traverse node
				traverseNode(root);

				//Traverse has finished
				response.getWriter().println("Traverse whole repository has been finished :: Please review C:/files directory as it should contain all Binay documents ::");

				//Logout session
				this.session.logout();
			}
			else {
				//Login again
				this.session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
			}

		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

	//Recursive traverse node
	public void traverseNode(Node node){
		try {
				//Specify whether the node has child or not
				if(node.getNodes().getSize() != 0){
					//Get child iterator
					NodeIterator iterator =  node.getNodes();

					//Loop over child and traverse them one by one
					while(iterator.hasNext()){
						Node _node = (Node)iterator.next();
						traverseNode(_node);
					}
				}
				else {
					//Print out node information
					System.out.println("Node Name :: "+node.getName()+" :: Node Path :: "+node.getPath()+" :: Node Identifier :: "+node.getIdentifier());

					//Print out properties
					System.out.println("Node Properties :: ");

					PropertyIterator iterator =  node.getProperties();

					while(iterator.hasNext()){
						//Get property
						Property property = (Property)iterator.next();

						//Get specific property like jcr:data
						if(node.getProperty("jcr:data") != null){
							//Get binary stream
							InputStream content = node.getProperty("jcr:data").getBinary().getStream();

							//Create bytes array by number of available bytes
							byte [] bytes = new byte [content.available()];

							//Read contents
							content.read(bytes,0,content.available());

							//Create file, we've assumed that we will persist all binary data into C:/files
							File file = new File("c:/files/"+node.getIdentifier()+node.getPath().substring(node.getPath().indexOf("."),node.getPath().indexOf(".")+4));

							//Create file output stream
							FileOutputStream wf = new FileOutputStream(file);

							//Write binary
							wf.write(bytes);
							//Flush
							wf.flush();
							//Close
							wf.close();
						}
						//Specify whether the property has multiple values or not
						if(property.isMultiple()){
							//Print out the property information
							System.out.print("Property Name :: "+property.getName()+" :: Property Type :: "+property.getType() + " :: Property Value :: ");
							for(Value value : property.getValues()){
								System.out.print("Value :: "+value);
							}
							System.out.println("\n");
						}
						else {
							//Print out the property information
							System.out.println("Property Name :: "+property.getName()+" :: Property Type :: "+property.getType() + " :: Property Value :: "+property.getValue());
						}

					}
				}
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
	}

	public Repository getRepository() {
		return repository;
	}

	public void setRepository(Repository repository) {
		this.repository = repository;
	}

	public Session getSession() {
		return session;
	}

	public void setSession(Session session) {
		this.session = session;
	}

}

以下是上面列出的代码的详细说明:

  • 在用于我们的存储库之前,您应该可以打开一个会话。

  • 可以通过调用直接注销方法来关闭此会话。

  • 要确保打开某些会话,只需调用isLive方法。

  • 您可能无法再次打开该会话,但是您可以使用存储库对象来打开新的会话。

  • 我们使用了遍历递归方法,该方法旨在打印出与内容存储库结构中特定节点相关的所有信息。

  • 该节点已经确定了其主要属性。
    名称,路径,标识符等等可以通过针对节点对象的直接方法来调用。

  • 我们已经使用RMI方法将其与JCR存储库系统集成。

通过访问URLhttps://localhost:8181/pluto/portal/theitroad,您将看到以下结果:

这是Portlet成功响应的下方,因为它通知您遍历过程已成功完成,并且您可能会看到位于上述目录下的所有文件。

在下面,您还可以找到Eclipse的控制台,因为Traverse已打印出与每个被遍历的节点相关的所有信息。

另外,您可能会在C:/files目录下找到该目录,其中包含保留在Hymanrabbit存储库中的所有二进制数据。