[infinispan-commits] Infinispan SVN: r1633 - in trunk/demos/gridfs-webdav/src/main: webapp/WEB-INF and 1 other directory.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon Mar 29 11:00:59 EDT 2010
Author: manik.surtani at jboss.com
Date: 2010-03-29 11:00:59 -0400 (Mon, 29 Mar 2010)
New Revision: 1633
Added:
trunk/demos/gridfs-webdav/src/main/java/org/infinispan/demos/gridfs/GridStore.java
trunk/demos/gridfs-webdav/src/main/webapp/WEB-INF/web.xml
Log:
[ISPN-383] Build Infinispan demo using GridFS and a webdav webapp
Added: trunk/demos/gridfs-webdav/src/main/java/org/infinispan/demos/gridfs/GridStore.java
===================================================================
--- trunk/demos/gridfs-webdav/src/main/java/org/infinispan/demos/gridfs/GridStore.java (rev 0)
+++ trunk/demos/gridfs-webdav/src/main/java/org/infinispan/demos/gridfs/GridStore.java 2010-03-29 15:00:59 UTC (rev 1633)
@@ -0,0 +1,204 @@
+package org.infinispan.demos.gridfs;
+
+
+import net.sf.webdav.*;
+import net.sf.webdav.exceptions.WebdavException;
+
+import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
+import java.io.*;
+import java.security.Principal;
+
+import org.infinispan.Cache;
+import org.infinispan.io.GridFile;
+import org.infinispan.io.GridFilesystem;
+import org.infinispan.util.Util;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+
+/**
+ * @author Bela Ban
+ */
+public class GridStore implements IWebdavStore {
+ private static Log log = LogFactory.getLog(GridStore.class);
+ private static int BUF_SIZE = 65536;
+ private final Cache<String, byte[]> data;
+ private final Cache<String, GridFile.Metadata> metadata;
+ private final GridFilesystem fs;
+
+
+ private File root = null;
+
+ public GridStore(File root) {
+ data = CacheManagerHolder.cacheManager.getCache(CacheManagerHolder.dataCacheName);
+ metadata = CacheManagerHolder.cacheManager.getCache(CacheManagerHolder.metadataCacheName);
+
+ try {
+ data.start();
+ metadata.start();
+ } catch (Exception e) {
+ throw new RuntimeException("creation of cluster failed", e);
+ }
+
+ fs = new GridFilesystem(data, metadata);
+
+ this.root = fs.getFile(root.getPath());
+ if (!this.root.mkdirs())
+ throw new WebdavException("root path: " + root.getAbsolutePath() + " does not exist and could not be created");
+ }
+
+ public void destroy() {
+ if (data != null)
+ data.stop();
+ if (metadata != null)
+ metadata.stop();
+ }
+
+ public ITransaction begin(Principal principal) throws WebdavException {
+ log.trace("GridStore.begin()");
+ if (!root.exists()) {
+ if (!root.mkdirs()) {
+ throw new WebdavException("root path: "
+ + root.getAbsolutePath()
+ + " does not exist and could not be created");
+ }
+ }
+ return null;
+ }
+
+ public void checkAuthentication(ITransaction transaction) throws SecurityException {
+ log.trace("GridStore.checkAuthentication()");
+ }
+
+ public void commit(ITransaction transaction) throws WebdavException {
+ log.trace("GridStore.commit()");
+ }
+
+ public void rollback(ITransaction transaction) throws WebdavException {
+ log.trace("GridStore.rollback()");
+ }
+
+ public void createFolder(ITransaction transaction, String uri) throws WebdavException {
+ log.trace("GridStore.createFolder(" + uri + ")");
+ File file = fs.getFile(root, uri);
+ if (!file.mkdir())
+ throw new WebdavException("cannot create folder: " + uri);
+ }
+
+ public void createResource(ITransaction transaction, String uri) throws WebdavException {
+ log.trace("GridStore.createResource(" + uri + ")");
+ File file = fs.getFile(root, uri);
+ try {
+ if (!file.createNewFile())
+ throw new WebdavException("cannot create file: " + uri);
+ }
+ catch (IOException e) {
+ log.error("GridStore.createResource(" + uri + ") failed");
+ throw new WebdavException(e);
+ }
+ }
+
+ public long setResourceContent(ITransaction transaction, String uri,
+ InputStream is, String contentType, String characterEncoding)
+ throws WebdavException {
+
+ log.trace("GridStore.setResourceContent(" + uri + ")");
+ File file = fs.getFile(root, uri);
+ try {
+ OutputStream os = fs.getOutput((GridFile) file);
+ // OutputStream os=new BufferedOutputStream(fs.getOutput((GridFile)file), BUF_SIZE);
+ try {
+ int read;
+ byte[] copyBuffer = new byte[BUF_SIZE];
+
+ while ((read = is.read(copyBuffer, 0, copyBuffer.length)) != -1) {
+ os.write(copyBuffer, 0, read);
+ }
+ }
+ finally {
+ Util.close(is);
+ Util.close(os);
+ }
+ }
+ catch (IOException e) {
+ log.error("GridStore.setResourceContent(" + uri + ") failed");
+ throw new WebdavException(e);
+ }
+ long length = -1;
+
+ try {
+ length = file.length();
+ }
+ catch (SecurityException e) {
+ log.error("GridStore.setResourceContent(" + uri + ") failed" + "\nCan't get file.length");
+ }
+ return length;
+ }
+
+ public String[] getChildrenNames(ITransaction transaction, String uri) throws WebdavException {
+ log.trace("GridStore.getChildrenNames(" + uri + ")");
+ File file = fs.getFile(root, uri);
+ String[] childrenNames = null;
+ if (file.isDirectory()) {
+ File[] children = file.listFiles();
+ List<String> childList = new ArrayList<String>();
+ String name = null;
+ for (int i = 0; i < children.length; i++) {
+ name = children[i].getName();
+ childList.add(name);
+ log.trace("Child " + i + ": " + name);
+ }
+ childrenNames = new String[childList.size()];
+ childrenNames = childList.toArray(childrenNames);
+ }
+ return childrenNames;
+ }
+
+ public void removeObject(ITransaction transaction, String uri) throws WebdavException {
+ File file = fs.getFile(root, uri);
+ boolean success = file.delete();
+ log.trace("GridStore.removeObject(" + uri + ")=" + success);
+ if (!success)
+ throw new WebdavException("cannot delete object: " + uri);
+ }
+
+ public InputStream getResourceContent(ITransaction transaction, String uri) throws WebdavException {
+ log.trace("GridStore.getResourceContent(" + uri + ")");
+ File file = fs.getFile(root, uri);
+
+ InputStream in;
+ try {
+ // in=new BufferedInputStream(fs.getInput(file));
+ in = fs.getInput(file);
+ }
+ catch (IOException e) {
+ log.error("GridStore.getResourceContent(" + uri + ") failed");
+ throw new WebdavException(e);
+ }
+ return in;
+ }
+
+ public long getResourceLength(ITransaction transaction, String uri) throws WebdavException {
+ log.trace("GridStore.getResourceLength(" + uri + ")");
+ File file = fs.getFile(root, uri);
+ return file.length();
+ }
+
+ public StoredObject getStoredObject(ITransaction transaction, String uri) {
+
+ StoredObject so = null;
+
+ File file = fs.getFile(root, uri);
+ if (file.exists()) {
+ so = new StoredObject();
+ so.setFolder(file.isDirectory());
+ so.setLastModified(new Date(file.lastModified()));
+ so.setCreationDate(new Date(file.lastModified()));
+ so.setResourceLength(getResourceLength(transaction, uri));
+ }
+
+ return so;
+ }
+
+}
Property changes on: trunk/demos/gridfs-webdav/src/main/java/org/infinispan/demos/gridfs/GridStore.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/demos/gridfs-webdav/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/demos/gridfs-webdav/src/main/webapp/WEB-INF/web.xml (rev 0)
+++ trunk/demos/gridfs-webdav/src/main/webapp/WEB-INF/web.xml 2010-03-29 15:00:59 UTC (rev 1633)
@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+ <display-name>Infinispan-GridGF-WebDAV</display-name>
+ <description>WebDAV interface to Infinispan's GridFS</description>
+
+ <!-- a startup servlet to init caches -->
+ <servlet>
+ <servlet-name>InitServlet</servlet-name>
+ <servlet-class>org.infinispan.demos.gridfs.CacheManagerHolder</servlet-class>
+
+ <!--
+ All of the values below can be overridden using JVM system properties.
+ E.g.,
+
+ -Dinfinispan.gridfs.cache.data=some_other_cache
+
+ would override the data cache used to 'some_other_cache' as defined in your configuration XML.
+ -->
+
+ <!-- specify your cache configuration file -->
+ <init-param>
+ <param-name>infinispan.gridfs.cfg</param-name>
+ <param-value>default.xml</param-value>
+ </init-param>
+
+ <!-- specify your data cache name, as defined in your configuration file -->
+ <init-param>
+ <param-name>infinispan.gridfs.cache.data</param-name>
+ <param-value>data</param-value>
+ </init-param>
+
+ <!-- specify your metadata cache name, as defined in your configuration file -->
+ <init-param>
+ <param-name>infinispan.gridfs.cache.metadata</param-name>
+ <param-value>metadata</param-value>
+ </init-param>
+
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet>
+ <servlet-name>webdav</servlet-name>
+ <servlet-class>
+ net.sf.webdav.WebdavServlet
+ </servlet-class>
+ <init-param>
+ <param-name>ResourceHandlerImplementation</param-name>
+ <param-value>
+ org.infinispan.demos.gridfs.GridStore
+ </param-value>
+ <description>
+ name of the class that implements
+ net.sf.webdav.WebdavStore
+ </description>
+ </init-param>
+ <init-param>
+ <param-name>rootpath</param-name>
+ <param-value>/tmp/webdav</param-value>
+ <description>
+ place where to store the webdavcontent on the filesystem
+ </description>
+ </init-param>
+
+ <init-param>
+ <param-name>lazyFolderCreationOnPut</param-name>
+ <param-value>0</param-value>
+ <description>
+ Overriding RFC 2518, the folders of resources being
+ created, can be created too if they do not exist.
+ </description>
+ </init-param>
+ <init-param>
+ <param-name>no-content-length-headers</param-name>
+ <param-value>0</param-value>
+ <description>
+ TODO
+ </description>
+ </init-param>
+ <init-param>
+ <param-name>default-index-file</param-name>
+ <param-value></param-value>
+ </init-param>
+ <init-param>
+ <param-name>instead-of-404</param-name>
+ <param-value></param-value>
+ </init-param>
+ <init-param>
+ <param-name>maxUploadSize</param-name>
+ <param-value>2000000000</param-value>
+ <!-- set to 2G -->
+ </init-param>
+
+ </servlet>
+
+ <!-- The mapping for the webdav servlet -->
+ <!-- Using /* as the mapping ensures that jasper, welcome files etc are
+ over-ridden and all requests are processed by the webdav servlet.
+ This also overcomes a number of issues with some webdav clients
+ (including MS Webfolders) that do not respond correctly
+ to the
+ redirects (302) that result from using a mapping of / -->
+ <servlet-mapping>
+ <servlet-name>webdav</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+ <!-- ================ Security Constraints for Testing =============== -->
+
+ <!--
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>The Entire Web Application</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>webdav</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>Tomcat Supported Realm</realm-name>
+ </login-config>
+
+ <security-role>
+ <description>
+ An example role defined in "conf/tomcat-users.xml"
+ </description>
+ <role-name>webdav</role-name>
+ </security-role>
+ -->
+
+ <welcome-file-list>
+ <welcome-file />
+ </welcome-file-list>
+
+</web-app>
Property changes on: trunk/demos/gridfs-webdav/src/main/webapp/WEB-INF/web.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the infinispan-commits
mailing list