Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r363 - in trunk/java/ch/idok: common/client service/common service/server/admin/rest service/server/io service/server/io/rest service/server/rest

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r363 - in trunk/java/ch/idok: common/client service/common service/server/admin/rest service/server/io service/server/io/rest service/server/rest


Chronological Thread 
  • From: "AFS account Stephan Egli" <egli AT savannah.psi.ch>
  • To: idok-commit AT lists.psi.ch
  • Subject: [idok-commit] idok commit r363 - in trunk/java/ch/idok: common/client service/common service/server/admin/rest service/server/io service/server/io/rest service/server/rest
  • Date: Wed, 13 May 2009 14:35:31 +0200
  • List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
  • List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>

Author: egli
Date: Wed May 13 14:35:31 2009
New Revision: 363

Log:
First extensions to a RESTinterface for document access - not yet usable or
complete in any way... !

Added:
trunk/java/ch/idok/common/client/RESTClientHandler.java (contents, props
changed)
trunk/java/ch/idok/service/server/io/
trunk/java/ch/idok/service/server/io/rest/
trunk/java/ch/idok/service/server/io/rest/RestIOServiceResource.java
(contents, props changed)
Modified:
trunk/java/ch/idok/service/common/dms.jks
trunk/java/ch/idok/service/server/admin/rest/RestAdminServiceResource.java
trunk/java/ch/idok/service/server/rest/IdokAppConfig.java
trunk/java/ch/idok/service/server/rest/RestServer.java

Added: trunk/java/ch/idok/common/client/RESTClientHandler.java
==============================================================================
--- (empty file)
+++ trunk/java/ch/idok/common/client/RESTClientHandler.java Wed May 13
14:35:31 2009
@@ -0,0 +1,157 @@
+package ch.idok.common.client;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.util.Date;
+import java.util.logging.Logger;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.SecurityContext;
+
+import ch.idok.common.config.Setup;
+import ch.idok.common.errorhandling.DmsException;
+import ch.idok.common.errorhandling.ErrorType;
+import ch.idok.common.util.DmsCredentials;
+import ch.idok.common.util.FileUtil;
+import ch.idok.service.server.rest.IdokNegotiateFilter;
+
+
+/**
+ * A "ClientHandler" that gets the authentitication information from the REST
+ * request
+ */
+public class RESTClientHandler implements ClientHandler {
+
+ /**
+ * Logger object.
+ */
+ // todo: which is the right logger ?
+ private Logger logger_ =
Setup.getInstance().getLogger("common.client");
+
+ /**
+ * @see
ch.idok.common.client.ClientHandler#getCredentials(java.lang.String,
+ * java.net.URL, java.lang.String)
+ */
+ public DmsCredentials getCredentials(String kind, String serviceName,
+ String realm) throws DmsException {
+ // todo: meaning of kind, servicename etc...
+ DmsCredentials cred = IdokNegotiateFilter.getDmsCredentials();
+ return cred;
+ }
+
+ // Todo: what of the remaining methods are really needed ?
+ /**
+ * @see
ch.idok.common.client.ClientHandler#appendFileName(java.lang.String,
+ * java.lang.String)
+ */
+ public String appendFileName(String parent, String child)
+ throws DmsException {
+ return parent + File.separator + child;
+ }
+
+ /**
+ * @see
ch.idok.common.client.ClientHandler#getAbsolutePath(java.lang.String)
+ */
+ public String getAbsolutePath(String pathname) throws DmsException {
+ return new File(pathname).getAbsolutePath();
+ }
+
+ /**
+ * @see
ch.idok.common.client.ClientHandler#getFileName(java.lang.String)
+ */
+ public String getFileName(String pathname) throws DmsException {
+ return new File(pathname).getName();
+ }
+
+ /**
+ * @see
ch.idok.common.client.ClientHandler#getLastModified(java.lang.String)
+ */
+ public Date getLastModified(String pathname) throws DmsException {
+ return new Date(new File(pathname).lastModified());
+ }
+
+ /**
+ * @see ch.idok.common.client.ClientHandler#getMD5(java.lang.String)
+ */
+ public String getMD5(String pathname) throws DmsException {
+ try {
+ FileInputStream is = new FileInputStream(pathname);
+ return FileUtil.getMD5(is);
+ } catch (FileNotFoundException e) {
+ throw new DmsException(ErrorType.FILE_ACCESS, this,
+ "Error opening file", "", e);
+ }
+ }
+
+ /**
+ * @see ch.idok.common.client.ClientHandler#getSystemOut()
+ */
+ public PrintStream getSystemOut() throws DmsException {
+ return System.out;
+ }
+
+ /**
+ * @see
ch.idok.common.client.ClientHandler#isDirectory(java.lang.String)
+ */
+ public boolean isDirectory(String pathname) throws DmsException {
+ return new File(pathname).isDirectory();
+ }
+
+ /**
+ * @see ch.idok.common.client.ClientHandler#isFile(java.lang.String)
+ */
+ public boolean isFile(String pathname) throws DmsException {
+ return new File(pathname).isFile();
+ }
+
+ /**
+ * @see
ch.idok.common.client.ClientHandler#listFiles(java.lang.String)
+ */
+ public String[] listFiles(String pathname) throws DmsException {
+ File[] files = new File(pathname).listFiles();
+ String[] names = new String[files.length];
+ for (int i = 0; i < files.length; ++i)
+ names[i] = files[i].getPath();
+ return names;
+ }
+
+ /**
+ * @see
ch.idok.common.client.ClientHandler#getFileInputStream(java.lang.String)
+ */
+ public InputStream getFileInputStream(String pathname) throws
DmsException {
+ try {
+ return new FileInputStream(pathname);
+ } catch (FileNotFoundException e) {
+ throw new DmsException(ErrorType.FILE_ACCESS, this,
+ "File not found", "", e);
+ }
+ }
+
+ /**
+ * @see ch.idok.common.client.ClientHandler#mkdir(java.lang.String)
+ */
+ public void mkdir(String pathname) throws DmsException {
+ if (new File(pathname).mkdir() == false) {
+ throw new DmsException(ErrorType.FILE_ACCESS, this,
+ "Could not create directory", "");
+ }
+ }
+
+ /**
+ * @see
ch.idok.common.client.ClientHandler#getFileOutputStream(java.lang.String)
+ */
+ public OutputStream getFileOutputStream(String pathname)
+ throws DmsException {
+ try {
+ return new FileOutputStream(pathname);
+ } catch (FileNotFoundException e) {
+ throw new DmsException(ErrorType.FILE_ACCESS, this,
+ "cannot open file for writing", "",
e);
+ }
+ }
+}

Modified: trunk/java/ch/idok/service/common/dms.jks
==============================================================================
Binary files. No diff available.

Modified:
trunk/java/ch/idok/service/server/admin/rest/RestAdminServiceResource.java
==============================================================================
---
trunk/java/ch/idok/service/server/admin/rest/RestAdminServiceResource.java
(original)
+++
trunk/java/ch/idok/service/server/admin/rest/RestAdminServiceResource.java
Wed May 13 14:35:31 2009
@@ -298,7 +298,7 @@
}

/**
- * Create a new iDok project
+ * Create a new iDok repository
*
* @param project
* project name

Added: trunk/java/ch/idok/service/server/io/rest/RestIOServiceResource.java
==============================================================================
--- (empty file)
+++ trunk/java/ch/idok/service/server/io/rest/RestIOServiceResource.java
Wed May 13 14:35:31 2009
@@ -0,0 +1,143 @@
+package ch.idok.service.server.io.rest;
+
+import java.net.URI;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+
+import ch.idok.common.client.ClientHandler;
+import ch.idok.common.client.RESTClientHandler;
+import ch.idok.common.errorhandling.DmsException;
+import ch.idok.common.impl.repository.svn.SvnRepositoryManager;
+import ch.idok.common.repository.DocumentId;
+import ch.idok.common.repository.PathType;
+import ch.idok.common.repository.Repository;
+import ch.idok.common.repository.RepositoryDirEntry;
+import ch.idok.common.repository.RepositoryId;
+import ch.idok.common.repository.RepositoryManager;
+import ch.idok.common.util.URIUtil;
+import ch.idok.service.server.rest.RestExceptionResponse;
+import ch.idok.service.server.rest.RestServer;
+
+/*
+ * Copyright (C) 2006-2008 iDok team.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
+ */
+
+/**
+ * JAX-RS resource class for the iDok Document IO service
+ *
+ * Example URI for accessing a folder via this service: \c
+ * https://dms.psi.ch/api/v1/io/ait/intern/Events
+ *
+ * The example URI can be broken down into the following components:
+ *
+ * @li \c https://dms.psi.ch/api is the base URI for accessing the ReST
service.
+ * This part of the URI is site-specific.
+ * @li \c v1 specifies the version of the ReST API to be used.
+ * @li \c io specifies that the \em io service should be accessed
+ * @li \c ait/intern/Events is the folder, for which the content should be
+ * displayed A specification of the XML output format, e.g. as a DTD or
an
+ * XML Schema, is currently missing.
+ *
+ */
+
+@Path("io")
+public class RestIOServiceResource {
+
+ static Logger logger;
+
+ /**
+ * JAX-RS security context
+ */
+ @Context
+ SecurityContext securityContext;
+
+ /**
+ * Provides both static and dynamic, per-request information, about
the
+ * components of a request URI.
+ */
+ @Context
+ UriInfo uriInfo;
+
+ static String baseURI;
+
+
+ static public void init(RestServer server) throws DmsException {
+ logger = server.getLogger();
+ baseURI = server.getBaseURI();
+ }
+
+ /**
+ * Resource method for getting folder contents
+ */
+ @GET
+ @Path(value = "{path:.+}")
+ @Produces("text/html")
+ public Response queryFolderContent(@PathParam("path") String path) {
+ logger.entering(this.getClass().getName(),
"queryFolderContent");
+ // Parse project, repository and folder
+ String project;
+ String repository = null;
+ String folder = null;
+
+ String[] sa = path.split("/", 3);
+ project = sa[0];
+ if (sa.length > 1)
+ repository = sa[1];
+ if (sa.length > 2)
+ folder = sa[2];
+ ClientHandler handler = new RESTClientHandler();
+ RepositoryManager mgr = new SvnRepositoryManager(handler);
+ try {
+ // todo: create URI from path - is there a more
direct way in
+ // defining the path to the document ?
+ URI uri =
URIUtil.parseUserURI(baseURI+project+"/"+repository);
+ RepositoryId repoId = mgr.getRepositoryId(uri,
+ RepositoryManager.LocationType.ROOT);
+ Repository repo = mgr.getRepository(repoId);
+ DocumentId docId = repo.getDocumentId(folder);
+ Iterable<RepositoryDirEntry> entries =
repo.getDir(repo
+ .getRepositoryPath(docId));
+ StringBuilder sb = new StringBuilder();
+ sb.append("<html><head><title>Revision" +
repo.getLatestVersion() + ": /</title></head>");
+ for (RepositoryDirEntry entry : entries) {
+ if (entry.getType() == PathType.DIRECTORY) {
+ // fillFolderRow(parent,
entry.getId().getTail());
+ // sb.append...
+ } else if (entry.getType() == PathType.FILE) {
+ // fillDocumentRow(entry);
+ }
+ }
+ return Response.ok().entity(sb).build();
+ } catch (Exception e) {
+ // TODO: handle exception
+ logger.log(Level.FINER, "Error in REST call", e);
+ return RestExceptionResponse.generateXHTML(e);
+ }
+ }
+ // Use Formencoding as a result format for meta data (p.151 Restful
Web
+ // Services
+}

Modified: trunk/java/ch/idok/service/server/rest/IdokAppConfig.java
==============================================================================
--- trunk/java/ch/idok/service/server/rest/IdokAppConfig.java (original)
+++ trunk/java/ch/idok/service/server/rest/IdokAppConfig.java Wed May 13
14:35:31 2009
@@ -25,6 +25,7 @@
import javax.ws.rs.core.Application;

import ch.idok.service.server.admin.rest.RestAdminServiceResource;
+import ch.idok.service.server.io.rest.RestIOServiceResource;
import ch.idok.service.server.search.rest.RestSearchServiceResource;

public class IdokAppConfig extends Application {
@@ -37,6 +38,7 @@
Set<Class<?>> rrcs = new HashSet<Class<?>>();
rrcs.add(RestSearchServiceResource.class);
rrcs.add(RestAdminServiceResource.class);
+ rrcs.add(RestIOServiceResource.class);
return rrcs;
}


Modified: trunk/java/ch/idok/service/server/rest/RestServer.java
==============================================================================
--- trunk/java/ch/idok/service/server/rest/RestServer.java (original)
+++ trunk/java/ch/idok/service/server/rest/RestServer.java Wed May 13
14:35:31 2009
@@ -38,6 +38,7 @@
import ch.idok.common.errorhandling.ErrorType;
import ch.idok.service.common.Provider;
import ch.idok.service.server.admin.rest.RestAdminServiceResource;
+import ch.idok.service.server.io.rest.RestIOServiceResource;
import ch.idok.service.server.search.rest.RestSearchServiceResource;

/**
@@ -84,6 +85,7 @@
this.serviceProvider = serviceProvider;
RestSearchServiceResource.init(this);
RestAdminServiceResource.init(this);
+ RestIOServiceResource.init(this);
}

/**



  • [idok-commit] idok commit r363 - in trunk/java/ch/idok: common/client service/common service/server/admin/rest service/server/io service/server/io/rest service/server/rest, AFS account Stephan Egli, 05/13/2009

Archive powered by MHonArc 2.6.19.

Top of Page