Commit cf5a82ad authored by toaster's avatar toaster
Browse files

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@132 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent 0a4106a8
......@@ -175,6 +175,18 @@
<artifactId>irods-api</artifactId>
<version>1.6</version>
</dependency>
<!-- web services -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
</project>
......
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.rest;
import edu.umiacs.ace.util.PersistUtil;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.log4j.Logger;
/**
* A filter called when any ACE rest service is invoked. This replaces the older
* EntityManagerServlet model.
*
* This filter will take care of closing any open entity manager
*
* @author toaster
*/
public class PersistenceServiceFilter implements Filter {
private static final Logger LOG = Logger.getLogger(PersistenceServiceFilter.class);
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Throwable problem = null;
try {
chain.doFilter(request, response);
} catch (Throwable t) {
problem = t;
} finally {
PersistUtil.closeLocalManager();
}
if (problem != null) {
if (problem instanceof ServletException) {
throw (ServletException) problem;
}
if (problem instanceof IOException) {
throw (IOException) problem;
}
LOG.error("Unexpected error in filter: ", problem);
throw new IOException(problem);
}
}
public void destroy() {
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.rest;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.log4j.Logger;
/**
* Service for manipulating whole token stores
*
* @author toaster
*/
@Path("tokenstore")
public class TokenStoreUpload {
private static final Logger LOG = Logger.getLogger(TokenStoreUpload.class);
@POST
@Path("{collectionid}")
public Response loadTokenStore(@PathParam("collectionid") long collectionId,
@Context HttpServletRequest request)
{
LOG.info("Form Field: " + collectionId);
if (ServletFileUpload.isMultipartContent(request))
{
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = null;
try {
items = upload.parseRequest(request);
LOG.info("item size: " + items.size());
for (FileItem item : items)
{
LOG.info("item " + item.getSize() + " " + item.getName() + " " + item.getContentType() ) ;
}
return Response.ok().build();
}
catch (FileUploadException e)
{
LOG.error("Error parsing token store upload",e);
return Response.serverError().build();
}
}
LOG.info("No file included, returning error");
return Response.status(Status.OK).build();
}
}
/*
* RESTful services for the ACE Audit Manager
*/
package edu.umiacs.ace.rest;
......@@ -51,9 +51,28 @@ public final class PersistUtil {
/** db connection to aceamdb. */
private static DataSource ds = null;
private static ThreadLocal<EntityManager> localEntityManager = new ThreadLocal<EntityManager>();
/**
*
*/
public static EntityManager getLocalManager()
{
if (localEntityManager.get() == null)
{
localEntityManager.set(getEntityManager());
}
return localEntityManager.get();
}
public static void closeLocalManager()
{
if (localEntityManager.get() != null)
{
localEntityManager.get().close();
localEntityManager.remove();
}
}
private PersistUtil() {
}
......
......@@ -8,7 +8,8 @@ import edu.umiacs.ace.token.AceToken;
import edu.umiacs.ace.token.AceTokenBuilder;
/**
*
* Convert DB stored token to an AceToken compatible object.
*
* @author toaster
*/
public class TokenUtil {
......
......@@ -5,6 +5,16 @@
<param-name>checkPeriod</param-name>
<param-value>5</param-value>
</context-param>
<filter>
<filter-name>PersistenceFilter</filter-name>
<filter-class>edu.umiacs.ace.rest.PersistenceServiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PersistenceFilter</filter-name>
<url-pattern>/rest/*</url-pattern>
</filter-mapping>
<listener>
<description>listener to configure log4j properties</description>
<listener-class>edu.umiacs.ace.util.LogContextListener</listener-class>
......@@ -48,7 +58,16 @@
<description>srb file opening throttle</description>
<listener-class>edu.umiacs.ace.driver.QueryThrottle</listener-class>
</listener>
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>edu.umiacs.ace.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>ManageCollection</servlet-name>
<servlet-class>edu.umiacs.ace.monitor.core.ManageCollectionServlet</servlet-class>
......@@ -149,6 +168,11 @@
<servlet-name>ChangePassword</servlet-name>
<servlet-class>edu.umiacs.ace.monitor.users.ChangePasswordServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ManageCollection</servlet-name>
<url-pattern>/ManageCollection</url-pattern>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment