Index: src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java	(revision 6266)
+++ src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java	(revision 6267)
@@ -121,7 +121,7 @@
  * @author leinfelder
  *
  */
-public class MNResourceHandler extends ResourceHandler{
+public class MNResourceHandler extends D1ResourceHandler{
 
     // MN-specific API Resources
     protected static final String RESOURCE_MONITOR = "monitor";
@@ -301,7 +301,7 @@
             serializeException(be, out);
         } catch (Exception e) {
             logMetacat.error(e.getClass() + ": " + e.getMessage());
-            System.out.println("Error in ResourceHandler.handle(): " + e.getClass() + ": " + e.getMessage());
+            System.out.println("Error handle(): " + e.getClass() + ": " + e.getMessage());
             e.printStackTrace();
         }
     }
@@ -545,7 +545,7 @@
         }
         catch(Exception e)
         {
-            logMetacat.error("Error getting output stream in ResourceHandler.describeObject: " + e.getClass() + ": " + e.getMessage());
+            logMetacat.error("Error getting output stream in describeObject: " + e.getClass() + ": " + e.getMessage());
             return;
         }
         response.setStatus(200);
@@ -738,7 +738,7 @@
                             "Here's the error: " + e.getClass() + ": " + e.getMessage());
                     e.printStackTrace();
                     ServiceFailure sf = new ServiceFailure("1030", 
-                            "IO Error in ResourceHandler.getObject: " + e.getClass() + ": " + e.getMessage());
+                            "IO Error in getObject: " + e.getClass() + ": " + e.getMessage());
                     serializeException(sf, out); 
                 }
             }
@@ -836,7 +836,7 @@
             e.printStackTrace();
             response.setStatus(500);
             ServiceFailure sf = new ServiceFailure("1030", 
-                    "IO Error in ResourceHandler.getObject: " + e.getMessage());
+                    "IO Error in getObject: " + e.getMessage());
             serializeException(sf, out); 
         } catch(NumberFormatException ne) {
             response.setStatus(500);
@@ -879,7 +879,7 @@
         } catch (IOException e) {
             response.setStatus(500);
             ServiceFailure sf = new ServiceFailure("1030", 
-                    "IO Error in ResourceHandler.getSystemMetadataObject: " + e.getMessage());
+                    "IO Error in getSystemMetadataObject: " + e.getMessage());
             serializeException(sf, out);
         } finally {
             IOUtils.closeQuietly(out);
@@ -983,7 +983,7 @@
      */
     @Override
     protected void putObject(String pid, String action) {
-        System.out.println("ResourceHandler: putObject with pid " + pid);
+        System.out.println("putObject with pid " + pid);
         logMetacat.debug("Entering putObject: " + pid + "/" + action);
         OutputStream out = null;
         try {
@@ -1218,7 +1218,7 @@
         catch(Exception e)
         {
             response.setStatus(500);
-            printError("Error setting access in ResourceHandler: " + e.getClass() + ": " + e.getMessage(), response);
+            printError("Error setting access: " + e.getClass() + ": " + e.getMessage(), response);
             throw e;
         }
     }
Index: src/edu/ucsb/nceas/metacat/restservice/CNRestServlet.java
===================================================================
--- src/edu/ucsb/nceas/metacat/restservice/CNRestServlet.java	(revision 6266)
+++ src/edu/ucsb/nceas/metacat/restservice/CNRestServlet.java	(revision 6267)
@@ -33,13 +33,13 @@
  * Routes CN REST service requests to the appropriate handler
  *  
  */
-public class CNRestServlet extends RestServlet {
+public class CNRestServlet extends D1RestServlet {
     
 	/**
-	 * Provide a CNResourceHandler subclass of ResourceHandler
+	 * Provide a CNResourceHandler subclass of D1ResourceHandler
 	 */
 	@Override
-    protected ResourceHandler createHandler(HttpServletRequest request, HttpServletResponse response) 
+    protected D1ResourceHandler createHandler(HttpServletRequest request, HttpServletResponse response) 
     	throws ServletException, IOException {
         return new CNResourceHandler(getServletContext(), request, response);
     }
Index: src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java	(revision 6266)
+++ src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java	(revision 6267)
@@ -114,7 +114,7 @@
  * @author leinfelder
  *
  */
-public class CNResourceHandler extends ResourceHandler {
+public class CNResourceHandler extends D1ResourceHandler {
 
 	/** CN-specific operations **/
     protected static final String RESOURCE_RESERVE = "reserve";
@@ -515,7 +515,7 @@
                             "Here's the error: " + e.getClass() + ": " + e.getMessage());
                     e.printStackTrace();
                     ServiceFailure sf = new ServiceFailure("1030", 
-                            "IO Error in ResourceHandler.getObject: " + e.getClass() + ": " + e.getMessage());
+                            "IO Error in D1ResourceHandler.getObject: " + e.getClass() + ": " + e.getMessage());
                     serializeException(sf, out); 
                 }
             }
@@ -524,7 +524,7 @@
             e.printStackTrace();
             response.setStatus(500);
             ServiceFailure sf = new ServiceFailure("1030", 
-                    "IO Error in ResourceHandler.getObject: " + e.getMessage());
+                    "IO Error in D1ResourceHandler.getObject: " + e.getMessage());
             serializeException(sf, out); 
         } catch(NumberFormatException ne) {
             response.setStatus(500);
@@ -572,7 +572,7 @@
         } catch (IOException e) {
             response.setStatus(500);
             ServiceFailure sf = new ServiceFailure("1030", 
-                    "IO Error in ResourceHandler.getSystemMetadataObject: " + e.getMessage());
+                    "IO Error in D1ResourceHandler.getSystemMetadataObject: " + e.getMessage());
             serializeException(sf, out);
         } finally {
             IOUtils.closeQuietly(out);
@@ -587,7 +587,7 @@
      * @throws IOException
      */
     protected void putObject(String pid, String action) {
-        logMetacat.debug("ResourceHandler: putObject with pid " + pid);
+        logMetacat.debug("putObject with pid " + pid);
         logMetacat.debug("Entering putObject: " + pid + "/" + action);
         OutputStream out = null;
         try {
@@ -782,7 +782,7 @@
 	      
       } catch (IOException ioe) {
       	logMetacat.error("Could not get the output stream for writing" +
-      	  "in ResourceHandler.listFormats()");
+      	  "in D1ResourceHandler.listFormats()");
       
       }
 
@@ -839,7 +839,7 @@
 	      
       } catch (IOException ioe) {
       	logMetacat.error("Could not get the output stream for writing" +
-      	  "in ResourceHandler.listFormats()");
+      	  "in D1ResourceHandler.listFormats()");
       
       }
       
Index: src/edu/ucsb/nceas/metacat/restservice/D1RestServlet.java
===================================================================
--- src/edu/ucsb/nceas/metacat/restservice/D1RestServlet.java	(nonexistent)
+++ src/edu/ucsb/nceas/metacat/restservice/D1RestServlet.java	(revision 6267)
@@ -0,0 +1,113 @@
+/**
+ *  '$RCSfile$'
+ *  Copyright: 2000 Regents of the University of California and the
+ *              National Center for Ecological Analysis and Synthesis
+ *
+ *   '$Author: Serhan AKIN $'
+ *     '$Date: 2009-06-13 13:28:21 +0300  $'
+ *
+ * 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
+ */
+package edu.ucsb.nceas.metacat.restservice;
+
+import java.io.IOException;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Metacat implemantation of Earthgrid (Ecogrid) REST API as a servlet. In each request
+ * REST Servlet initialize a D1ResourceHandler object and then D1ResourceHandler object 
+ * handles with request and writes approriate response. 
+ *  
+ */
+public class D1RestServlet extends HttpServlet {
+
+    protected Logger logMetacat;
+    protected D1ResourceHandler handler;
+
+    /**
+     * Subclasses should override this method to provide the appropriate handler subclass
+     * @param request
+     * @param response
+     * @return
+     * @throws ServletException
+     * @throws IOException
+     */
+    protected D1ResourceHandler createHandler(HttpServletRequest request, HttpServletResponse response) 
+		throws ServletException, IOException {
+	    D1ResourceHandler handler = new D1ResourceHandler(getServletContext(), request, response);
+	    return handler;
+	}
+    
+    /**
+     * Initalize servlet by setting logger
+     */
+    @Override
+    public void init(ServletConfig config) throws ServletException {
+        logMetacat = Logger.getLogger(this.getClass());
+        super.init(config);
+    }
+
+    /** Handle "GET" method requests from HTTP clients */
+    @Override
+    protected void doGet(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+        System.out.println("HTTP Verb: GET");
+        handler = createHandler(request, response);
+        handler.handle(D1ResourceHandler.GET);
+    }
+
+    /** Handle "POST" method requests from HTTP clients */
+    @Override
+    protected void doPost(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+        System.out.println("HTTP Verb: POST");
+        handler = createHandler(request, response);
+        handler.handle(D1ResourceHandler.POST);
+    }
+
+    /** Handle "DELETE" method requests from HTTP clients */
+    @Override
+    protected void doDelete(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+        System.out.println("HTTP Verb: DELETE");
+        handler = createHandler(request, response);
+        handler.handle(D1ResourceHandler.DELETE);
+    }
+
+    /** Handle "PUT" method requests from HTTP clients */
+    @Override
+    protected void doPut(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+        System.out.println("HTTP Verb: PUT");
+        handler = createHandler(request, response);
+        handler.handle(D1ResourceHandler.PUT);
+    }
+
+    /** Handle "PUT" method requests from HTTP clients */
+    @Override
+    protected void doHead(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException {
+        System.out.println("HTTP Verb: HEAD");
+        handler = createHandler(request, response);
+        handler.handle(D1ResourceHandler.HEAD);
+    }
+}

Property changes on: src/edu/ucsb/nceas/metacat/restservice/D1RestServlet.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java	(nonexistent)
+++ src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java	(revision 6267)
@@ -0,0 +1,2259 @@
+/**
+ *  '$RCSfile$'
+ *  Copyright: 2011 Regents of the University of California and the
+ *              National Center for Ecological Analysis and Synthesis
+ *
+ *   '$Author: Serhan AKIN $'
+ *     '$Date: 2009-06-13 15:28:13 +0300  $'
+ *
+ * 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
+ */
+package edu.ucsb.nceas.metacat.restservice;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.net.URL;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.Timer;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.apache.maven.artifact.ant.shaded.IOUtil;
+import org.dataone.client.MNode;
+import org.dataone.client.ObjectFormatCache;
+import org.dataone.client.auth.CertificateManager;
+import org.dataone.mimemultipart.MultipartRequest;
+import org.dataone.mimemultipart.MultipartRequestResolver;
+import org.dataone.service.NodeListParser;
+import org.dataone.service.exceptions.BaseException;
+import org.dataone.service.exceptions.IdentifierNotUnique;
+import org.dataone.service.exceptions.InsufficientResources;
+import org.dataone.service.exceptions.InvalidRequest;
+import org.dataone.service.exceptions.InvalidSystemMetadata;
+import org.dataone.service.exceptions.InvalidToken;
+import org.dataone.service.exceptions.NotAuthorized;
+import org.dataone.service.exceptions.NotFound;
+import org.dataone.service.exceptions.NotImplemented;
+import org.dataone.service.exceptions.ServiceFailure;
+import org.dataone.service.exceptions.UnsupportedType;
+import org.dataone.service.types.AccessPolicy;
+import org.dataone.service.types.Checksum;
+import org.dataone.service.types.DescribeResponse;
+import org.dataone.service.types.Event;
+import org.dataone.service.types.Identifier;
+import org.dataone.service.types.Log;
+import org.dataone.service.types.Node;
+import org.dataone.service.types.NodeList;
+import org.dataone.service.types.NodeReference;
+import org.dataone.service.types.NodeType;
+import org.dataone.service.types.ObjectFormat;
+import org.dataone.service.types.ObjectFormatIdentifier;
+import org.dataone.service.types.ObjectFormatList;
+import org.dataone.service.types.ObjectList;
+import org.dataone.service.types.Service;
+import org.dataone.service.types.Services;
+import org.dataone.service.types.Session;
+import org.dataone.service.types.SystemMetadata;
+import org.dataone.service.types.util.ServiceTypeUtil;
+import org.jibx.runtime.BindingDirectory;
+import org.jibx.runtime.IBindingFactory;
+import org.jibx.runtime.IUnmarshallingContext;
+import org.jibx.runtime.JiBXException;
+
+import edu.ucsb.nceas.metacat.DBUtil;
+import edu.ucsb.nceas.metacat.IdentifierManager;
+import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
+import edu.ucsb.nceas.metacat.MetaCatServlet;
+import edu.ucsb.nceas.metacat.MetacatHandler;
+import edu.ucsb.nceas.metacat.dataone.CNodeService;
+import edu.ucsb.nceas.metacat.dataone.HealthService;
+import edu.ucsb.nceas.metacat.dataone.MNodeService;
+import edu.ucsb.nceas.metacat.properties.PropertyService;
+import edu.ucsb.nceas.metacat.service.SessionService;
+import edu.ucsb.nceas.metacat.util.RequestUtil;
+import edu.ucsb.nceas.metacat.util.SessionData;
+import edu.ucsb.nceas.metacat.util.SystemUtil;
+import edu.ucsb.nceas.utilities.PropertyNotFoundException;
+/**
+ * 
+ * Implements Earthgrid REST API to Metacat <br/><br/> 
+ * 
+ * <ul>
+ * <li>
+ * <h3> EarthGrid Query Service</h3>
+ * <ul><li>
+ * <h3>Get & Authenticated Get:</h3> 
+ * is equal to Metacat's read action and returns a data file having
+ * the specified <doc-id> in the resource path. For authenticated Get service, a session id must be provided 
+ * in the query string. <br/><br/>
+ * 
+ * <b>REST URL:</b> <code>GET, [context-root]/object/[doc-id]?sessionid=[sessionid] </code><br/>
+ * <b>Returns:</b> data file <br/><br/>
+ * </li>
+ * 
+ * <li>
+ * <h3>Query & Authenticated Query:</h3> 
+ * Metacat's equivalent is squery action but this function 
+ * receives a Earthgrid query document and returns Earthgrid resultset document by transforming those documents
+ * to Metacat's equivalents by the means of Metacat Implementation in Earthgrid library. For authenticated Query service 
+ * a session id must be provided in the query string. See Earthgrid (a.k.a. Ecogrid) project for XSD files of 
+ * query and resultset documents<br/><br/>
+ * 
+ * <b>REST URL:</b> <code>POST, [context-root]/object?sessionid=[sessionid]</code>    <br/>
+ * <b>POST Data:</b> Earthgrid query document , Content-type: <code>text/xml</code><br/>
+ * <b>Returns:</b> Earthgrid resultset document<br/><br/>
+ * 
+ * </li>
+ * </ul>
+ * 
+ * </li>
+ * 
+ * <li>
+ * <h3> EarthGrid Authentication Service</h3>
+ * <ul><li>
+ * <h3>Login: </h3> 
+ * Receives username and password parameters in POST data and 
+ * returns SessionId (in XML format) or failure message and uses MetacatHandler's handleLoginAction function<br/><br/>
+ *  
+ * <b>REST URL:</b> <code>POST, [context-root]/session?op=login</code> <br/>
+ * <b>POST Data:</b> username=[username]&password=[password], Content-type: <code>application/x-www-form-urlencoded</code>
+ * <b>Returns:</b> sessionId in XML format<br/><br/>
+ * </li>
+ * 
+ * <li>
+ * <h3>Logout: </h3> 
+ * Receives session Id parameters in querystring and returns xml message, calls 
+ * MetacatHandler's handleLogoutAction function<br/><br/>
+ *  
+ * <b>REST URL:</b> <code>GET, [context-root]/session?op=logout&sessionid=[sessionid]</code>   <br/>
+ * <b>Returns:</b> message in XML format<br/><br/>
+ * </li>
+ * </ul>
+ * 
+ * <li>
+ * <h3>EarthGrid Put Service</h3>
+ * 
+ * <ul>
+ * <li><h3>Update/Insert: </h3>     
+ * <br/>
+ * <b>REST URL:</b> <code>PUT, [context-root]/object/[doc-id]?op={update|insert}&sessionid=[sessionid]</code>   <br/>
+ * <b>POST Data:</b> document object, Content-type: <code>text/xml</code><br/>
+ * <b>Returns:</b> message in XML format<br/><br/>
+ * </li>
+ * 
+ * <li><h3>Delete: </h3>        
+ * <br/>
+ * <b>REST URL:</b> <code>DELETE, [context-root]/object/[doc-id]?sessionid=[sessionid]</code>   <br/>
+ * <b>Returns:</b> message in XML format<br/><br/>
+ * </li>
+
+ * </ul>
+ * </li>
+ * 
+ * <li>
+ * <h3>EarthGrid Identifier Service</h3><br/>
+ * 
+ * <ul>
+ * <li><h3>isRegistered: </h3>      <br/>
+ * <b>REST URL:</b> <code>GET, [context-root]/identifier/[doc-id]?op=isregistered</code>   <br/>
+ * <b>Returns:</b> message in XML format<br/><br/>
+ * </li>
+
+ * <li><h3>getAllDocIds:</h3>       <br/>       
+ * <b>REST URL:</b> <code>GET, [context-root]/identifier?op=getalldocids</code>   <br/>
+ * <b>Returns:</b> document id list in XML format<br/><br/>
+ * </li>
+ * 
+ * <li><h3>addLSID Function:</h3> 
+ * Metacat does not support this function       <br/>
+ * <b>REST URL:</b> <code>PUT, [context-root]/identifier/[doc-id]</code>   <br/>
+ * <b>Returns:</b> error message in XML format<br/><br/>
+ * </li>
+ * 
+ * <li><h3>getNextRevision:</h3>        <br/>
+ * <b>REST URL:</b> <code>GET, [context-root]/identifier/[doc-id]?op=getnextrevision</code>   <br/>
+ * <b>Returns:</b> message in XML format<br/><br/>
+ * </li>
+ * 
+ * <li><h3>getNextObject:</h3>      <br/>
+ * <b>REST URL:</b> <code>GET, [context-root]/identifier?op=getnextobject&scope=[scope]</code>   <br/>
+ * <b>Returns:</b> message in XML format<br/><br/>
+ * </li>
+ * 
+ * </li>
+ * </ul>
+ * 
+ */
+public class D1ResourceHandler {
+
+    /**HTTP Verb GET*/
+    public static final byte GET = 1;
+    /**HTTP Verb POST*/
+    public static final byte POST = 2;
+    /**HTTP Verb PUT*/
+    public static final byte PUT = 3;
+    /**HTTP Verb DELETE*/
+    public static final byte DELETE = 4;
+    /**HTTP Verb HEAD*/
+    public static final byte HEAD = 5;
+
+    /*
+     * API Resources
+     */
+    protected static final String RESOURCE_OBJECTS = "object";
+    protected static final String RESOURCE_FORMATS = "formats";
+    protected static final String RESOURCE_META = "meta";
+    protected static final String RESOURCE_SESSION = "session";
+    protected static final String RESOURCE_IDENTIFIER = "identifier";
+    protected static final String RESOURCE_LOG = "log";
+    protected static final String RESOURCE_CHECKSUM = "checksum";
+    protected static final String RESOURCE_MONITOR = "monitor";
+    protected static final String RESOURCE_BASE_URL = "d1";
+    protected static final String RESOURCE_REPLICATE = "replicate";
+    
+    protected static final String RESOURCE_IS_AUTHORIZED = "isAuthorized";
+    protected static final String RESOURCE_ACCESS_RULES = "accessRules";
+
+    /*
+     * API Functions used as URL parameters
+     */
+    protected static final String FUNCTION_KEYWORD = "op";
+    protected static final String FUNCTION_NAME_LOGIN = "login";
+    protected static final String FUNCTION_NAME_LOGOUT = "logout";
+    protected static final String FUNCTION_NAME_SET_ACCESS = "setaccess";
+    protected static final String FUNCTION_NAME_ISREGISTERED = "isregistered";
+    protected static final String FUNCTION_NAME_GETALLDOCS = "getalldocids";
+    protected static final String FUNCTION_NAME_GETNEXTREV = "getnextrevision";
+    protected static final String FUNCTION_NAME_GETNEXTOBJ = "getnextobject";
+    protected static final String FUNCTION_NAME_INSERT = "insert";
+    protected static final String FUNCTION_NAME_UPDATE = "update";
+    protected static final String FUNCTION_NAME_GENERATE_MISSING_SYSTEM_METADATA = "generatemissingsystemmetadata";
+
+    protected static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+    
+    protected ServletContext servletContext;
+    protected Logger logMetacat;
+    protected MetacatHandler handler;
+    protected HttpServletRequest request;
+    protected HttpServletResponse response;
+    protected String username;
+    protected String password;
+    protected String sessionId;
+    protected String[] groupNames;
+
+    protected Hashtable<String, String[]> params;
+    
+    // D1 certificate-based authentication
+    protected Session session;
+
+    /**Initializes new instance by setting servlet context,request and response*/
+    public D1ResourceHandler(ServletContext servletContext,
+            HttpServletRequest request, HttpServletResponse response) {
+        this.servletContext = servletContext;
+        this.request = request;
+        this.response = response;
+    }
+
+    /**
+     * This function is called from REST APU servlet and handles each request to the servlet 
+     * 
+     * @param httpVerb (GET, POST, PUT or DELETE)
+     */
+    public void handle(byte httpVerb) {
+        logMetacat = Logger.getLogger(D1ResourceHandler.class);
+        try {
+            String resource = request.getServletPath();
+            if(resource.endsWith("d1/") || resource.endsWith("d1"))
+            {
+                resource = RESOURCE_BASE_URL;
+            }
+            else
+            {
+                //substring off the /d1/
+                resource = resource.substring(resource.indexOf("d1/") + 3, resource.length());
+                resource = resource.trim();
+            }
+            
+            String verb = "";
+            
+            System.out.println("handling verb " + httpVerb + " request with resource '" + resource + "'");
+            System.out.println("resource: '" + resource + "'");
+            System.out.println("resource_monitor: '" + RESOURCE_MONITOR + "'");
+            boolean status = false;
+            // load session the old way
+            loadSessionData();
+            
+            // load session from certificate in request
+            session = CertificateManager.getInstance().getSession(request);
+            
+            
+            if (resource != null) {
+                //resource = request.getServletPath().substring(1);
+
+                params = new Hashtable<String, String[]>();
+                initParams();
+
+                Timer timer = new Timer();
+                handler = new MetacatHandler(timer);
+
+                if(resource.equals(RESOURCE_BASE_URL)) {
+                    //node registry response
+                    System.out.println("Using resource 'd1' (node registry response)");
+                    createNodeResponse();
+                    status = true;
+                    
+                } else if (resource.equals(RESOURCE_SESSION) && 
+                        httpVerb == POST && 
+                        params.get(FUNCTION_KEYWORD) != null) {
+                    System.out.println("Using resource 'session'");
+                    //System.out.println("function_keyword: " + params.get(FUNCTION_KEYWORD)[0]);
+                    if (params.get(FUNCTION_KEYWORD)[0].equals(FUNCTION_NAME_LOGIN)) {
+                        login();
+                        status = true;
+                    } else if (params.get(FUNCTION_KEYWORD)[0].equals(FUNCTION_NAME_LOGOUT)) {
+                        logout();
+                        status = true;
+                    } else if (params.get(FUNCTION_KEYWORD)[0].equals(FUNCTION_NAME_SET_ACCESS)) {
+                        setaccess();
+                        status = true;
+                        System.out.println("done setting access");
+                    }
+                } else if (resource.equals(RESOURCE_META)) {
+                    System.out.println("Using resource 'meta'");
+                    if (params != null && params.get(FUNCTION_KEYWORD) != null &&
+                            params.get(FUNCTION_KEYWORD)[0].equals(FUNCTION_NAME_GENERATE_MISSING_SYSTEM_METADATA))
+                    { 
+                        status = true;
+                    }
+                    else
+                    {
+                        String objectId = request.getPathInfo();
+                        if (objectId != null && objectId.length() > 1) 
+                        {
+                            objectId = request.getPathInfo().substring(1);
+                        }
+                        
+                        // get
+                        if (httpVerb == GET) {
+	                        getSystemMetadataObject(objectId);
+	                        status = true;
+                        }
+                        
+                        // post to register system metadata
+                        if (httpVerb == POST) {
+                        	registerSystemMetadata(objectId);
+                        	status = true;
+                        }
+                        
+                    }
+
+                } else if (resource.equals(RESOURCE_OBJECTS)) {
+                    System.out.println("Using resource 'object'");
+                    logMetacat.debug("D1 Rest: Starting resource processing...");
+                    loadSessionData();
+
+                    String objectId = request.getPathInfo();
+                    if (objectId != null && objectId.length() > 1) 
+                    {
+                        objectId = request.getPathInfo().substring(1);
+                    }
+                    else
+                    {
+                        objectId = null;
+                    }
+                    
+                    System.out.println("objectId in ReasourceHandler.handle: " + objectId);
+
+                    logMetacat.debug("verb:" + httpVerb);
+
+                    if (httpVerb == GET) {
+                        getObject(objectId);
+                        status = true;
+                    } else if (httpVerb == POST) {
+                        putObject(objectId, FUNCTION_NAME_INSERT);
+                        status = true;
+                    } else if (httpVerb == PUT) {
+                        putObject(objectId, FUNCTION_NAME_UPDATE);
+                        status = true;
+                    } else if (httpVerb == DELETE) {
+                        deleteObject(objectId);
+                        status = true;
+                    } else if (httpVerb == HEAD) {
+                        describeObject(objectId);
+                        status = true;
+                    }
+                    
+                } else if (resource.equals(RESOURCE_FORMATS)) {
+                  System.out.println("Using resource 'formats'");
+                  
+                  // check for a format identifier
+                  String fmtid = request.getPathInfo();
+                  
+                  if ( fmtid != null && fmtid.length() > 1 ) {
+                  	fmtid = request.getPathInfo().substring(1);
+                  	
+                  } else {
+                  	fmtid = null;
+                  	
+                  }
+                  
+                  // handle each verb
+                  if ( httpVerb == GET ) {
+                  	if ( fmtid == null ) {
+                      // list the formats collection
+                  		listFormats();
+                  		
+                  	} else {
+                  		// get the specified format
+                  		getFormat(fmtid);
+
+                  	}
+                  	status = true;
+                  
+                  } else if ( httpVerb == PUT ) {
+                  	status = true;
+                  	
+                  } else if ( httpVerb == POST ) {
+                  	status = true;
+                  	
+                  } else if ( httpVerb == DELETE ) {
+                  	status = true;
+                  	
+                  } else if ( httpVerb == HEAD ) {
+                  	status = true;
+                  	
+                  }
+                  
+                } else if (resource.equals(RESOURCE_IDENTIFIER)) {
+                    System.out.println("Using resource 'identifier'");
+                    String identifierId = request.getPathInfo();
+                    if (identifierId != null && identifierId.length() > 1)
+                        identifierId = request.getPathInfo().substring(1); //trim the slash
+
+                    if (httpVerb == GET) {
+                        String op = params.get(FUNCTION_KEYWORD)[0];
+                        if (op.equals(FUNCTION_NAME_ISREGISTERED)) {
+                            isRegistered(identifierId);
+                            status = true;
+                        } else if (op.equals(FUNCTION_NAME_GETALLDOCS)) {
+                            getAllDocIds();
+                            status = true;
+                        } else if (op.equals(FUNCTION_NAME_GETNEXTREV)) {
+                            getNextRevision(identifierId);
+                            status = true;
+                        } else if (op.equals(FUNCTION_NAME_GETNEXTOBJ)) {
+                            getNextObject();
+                            status = true;
+                        } 
+
+                    } else if (httpVerb == PUT) {
+                        //Earthgrid API > Identifier Service > addLSID Function 
+                        response.setStatus(501);
+                        printError(
+                                "This method is not supported by metacat.  To "
+                                + "add a new LSID, add a document to metacat.",
+                                response);
+                        status = true;
+                    }
+
+                } else if (resource.equals(RESOURCE_LOG)) {
+                    System.out.println("Using resource 'log'");
+                    //handle log events
+                    if(httpVerb == GET)
+                    {
+                        getLog();
+                        status = true;
+                    }
+                    else
+                    {
+                        //change to D1 spec for specifying which http methods are allowed for a resource
+                        response.setStatus(501);
+                        printError("POST, PUT, DELETE is not supported for logs.", response);
+                        status = true;
+                    }
+
+                } else if(resource.equals(RESOURCE_CHECKSUM)) {
+                    System.out.println("Using resource 'checksum'");
+                    //handle checksum requests
+                    if(httpVerb == GET)
+                    {
+                        String checksumAlgorithm = "MD5";
+                    
+                        String guid = request.getPathInfo();
+                        if (guid != null && guid.length() > 1)
+                            guid = request.getPathInfo().substring(1); //trim the slash
+                        
+                        Identifier guidid = new Identifier();
+                        guidid.setValue(guid);
+                        try
+                        {
+                            checksumAlgorithm = params.get("checksumAlgorithm")[0];
+                        }
+                        catch(Exception e)
+                        {
+                            //do nothing.  default to MD5
+                        }
+                        System.out.println("getting checksum for object " + guid +
+                                " with algorithm " + checksumAlgorithm);
+                        try
+                        {
+                            Checksum c = MNodeService.getInstance().getChecksum(session, guidid, checksumAlgorithm);
+                            System.out.println("got checksum " + c.getValue());
+                            response.setStatus(200);
+                            System.out.println("serializing response");
+                            serializeServiceType(Checksum.class, c, response.getOutputStream());
+                            System.out.println("done serializing response.");
+                        }
+                        catch(NotAuthorized na)
+                        {
+                            na.setDetail_code("1400");
+                            serializeException(na, response.getOutputStream());
+                        }
+                        catch(NotFound nf)
+                        {
+                            nf.setDetail_code("1420");
+                            serializeException(nf, response.getOutputStream());
+                        }
+                        catch(InvalidRequest ir)
+                        {
+                            ir.setDetail_code("1402");
+                            serializeException(ir, response.getOutputStream());
+                        }
+                        catch(ServiceFailure sf)
+                        {
+                            sf.setDetail_code("1410");
+                            serializeException(sf, response.getOutputStream());
+                        }
+                        catch(InvalidToken it)
+                        {
+                            it.setDetail_code("1430");
+                            serializeException(it, response.getOutputStream());
+                        }
+                        status = true;
+                    }
+                } else if(resource.equals(RESOURCE_MONITOR)) {
+                    //health monitoring calls
+                    System.out.println("processing monitor request");
+                    String pathInfo = request.getPathInfo();
+                    if(httpVerb == GET)
+                    {
+                        System.out.println("verb is GET");
+                        System.out.println("pathInfo is " + pathInfo);
+                        pathInfo = pathInfo.substring(1);
+                        HealthService hs = new HealthService(request, response);
+                        if (pathInfo.toLowerCase().equals("ping")) {
+                            System.out.println("processing ping request");
+                            hs.ping();
+                        } else if (pathInfo.toLowerCase().equals("status")) {
+                            System.out.println("processing status request");
+                            hs.getStatus();
+                        } else if (pathInfo.toLowerCase().equals("object")) {
+                            System.out.println("processing object request");
+                            boolean day = false;
+                            Identifier pid = null;
+                            String url = null;
+                            ObjectFormat of = null;
+                            Date time = null;
+                            
+                            if(params.containsKey("day"))
+                            {
+                               day = true; 
+                            }
+                            if(params.containsKey("pid"))
+                            {
+                                String id = params.get("pid")[0];
+                                pid = new Identifier();
+                                pid.setValue(id);
+                            }
+                            if(params.containsKey("url"))
+                            {
+                                url = params.get("url")[0];
+                            }
+                            if(params.containsKey("format"))
+                            {
+                                String format = params.get("format")[0];
+                                of = ObjectFormatCache.getInstance().getFormat(format);
+                            }
+                            if(params.containsKey("time"))
+                            {
+                                String t = params.get("time")[0];
+                                time = dateFormat.parse(t);
+                            }
+                            
+                            hs.getObjectStatistics(day, pid, url, of, time);
+                        } else if (pathInfo.toLowerCase().equals("event")) {
+                            System.out.println("processing event request");
+                            boolean day = false;
+                            Identifier pid = null;
+                            Date created = null;
+                            ObjectFormat of = null;
+                            Date time = null;
+                            String ipAddress = null;
+                            String event = null;
+                            
+                            if(params.containsKey("day"))
+                            {
+                               day = true; 
+                            }
+                            if(params.containsKey("pid"))
+                            {
+                                String id = params.get("pid")[0];
+                                pid = new Identifier();
+                                pid.setValue(id);
+                            }
+                            if(params.containsKey("created"))
+                            {
+                                String t = params.get("created")[0];
+                                created = dateFormat.parse(t);
+                            }
+                            if(params.containsKey("format"))
+                            {
+                                String format = params.get("format")[0];
+                                of = ObjectFormatCache.getInstance().getFormat(format);
+                            }
+                            if(params.containsKey("eventtime"))
+                            {
+                                String t = params.get("eventtime")[0];
+                                time = dateFormat.parse(t);
+                            }
+                            if(params.containsKey("ip_address"))
+                            {
+                                ipAddress = params.get("ip_address")[0];
+                            }
+                            if(params.containsKey("event"))
+                            {
+                                event = params.get("event")[0];
+                            }
+                            
+                            hs.getOperationStatistics(day, pid, of, created, time, ipAddress, event);
+                        }
+                    }
+                    status = true;
+                } else if(resource.equals(RESOURCE_REPLICATE)) {
+                    System.out.println("processing replicate request");
+                    replicate(httpVerb, request, response);
+                    status = true;
+                }
+                    
+                if (!status)
+                {
+                    response.setStatus(400);
+                    printError("Incorrect parameters!", response);
+                }
+            } else {
+                response.setStatus(400);
+                printError("Incorrect resource!", response);
+            }
+        } catch (Exception e) {
+            logMetacat.error(e.getClass() + ": " + e.getMessage());
+            System.out.println("Error in D1ResourceHandler.handle(): " + e.getClass() + ": " + e.getMessage());
+            e.printStackTrace();
+        }
+    }
+    
+		/**
+     * handle the /replicate action
+     * @param httpVerb
+     * @param request
+     * @param response
+     * @throws Exception
+     */
+    private void replicate(int httpVerb, HttpServletRequest request, HttpServletResponse response)
+        throws Exception
+    {
+        if(httpVerb == POST)
+        {
+            System.out.println("in POST replicate()");
+            /*InputStream is = request.getInputStream();
+            String input = IOUtils.toString(is);
+            System.out.println("input: " + input);
+            is = IOUtils.toInputStream(input);*/
+            
+            File tmpDir = getTempDirectory();
+            File tmpSMFile = new File(tmpDir + 
+                    ".sysmeta." + new Date().getTime() + ".tmp");
+            System.out.println("temp dir: " + tmpDir.getAbsolutePath());
+            MultipartRequestResolver mrr = new MultipartRequestResolver(
+                    tmpDir.getAbsolutePath(), 1000000000, 0);
+            MultipartRequest mr = mrr.resolveMultipart(request);
+            Map<String, File> files = mr.getMultipartFiles();
+            Iterator keys = files.keySet().iterator();
+            while(keys.hasNext())
+            {
+                String key = (String)keys.next();
+                System.out.println("files key: " + key);
+                System.out.println("files value: " + files.get(key));
+            }
+            
+            Map<String, List<String>> params = mr.getMultipartParameters();
+            keys = params.keySet().iterator();
+            while(keys.hasNext())
+            {
+                String key = (String)keys.next();
+                System.out.println("params key: " + key);
+                System.out.println("params value: " + params.get(key));
+            }
+            
+            //File f = files.get("sysmeta");
+            //the files are not being keyed by the part name, but rather the filename
+            File f = files.get(files.keySet().iterator().next());
+            
+            System.out.println("file: " + f.getAbsolutePath());
+            String sourceNode = params.get("sourceNode").get(0);
+            System.out.println("sourceNode: " + sourceNode);
+            FileInputStream fis = new FileInputStream(f);
+            
+            //lookup the id in the registry
+            URL url = new URL("http://cn.dataone.org/cn/node");
+            InputStream urlis = url.openStream();
+            Map<String,String> m = NodeListParser.parseNodeListFile(urlis);
+            String nodeUrl = m.get(sourceNode);
+            System.out.println("sourceNodeId: " + sourceNode);
+            System.out.println("resolved sourceNodeUrl: " + nodeUrl);
+            
+            if(nodeUrl == null)
+            {
+                response.setStatus(500);
+                response.getOutputStream().write(("Member Node id " + 
+                        sourceNode + " not found in node registry.").getBytes());
+                response.getOutputStream().close();
+            }
+            
+            //respond to cn with 200/OK
+            //String s;
+            //s = "sysmeta: " + IOUtils.toString(fis);
+            //s += "\n\n";
+            response.setStatus(200);
+            //response.getOutputStream().write(("sourceNode: " + sourceNode + "\n\n").getBytes());
+            //response.getOutputStream().write(("s: " + s).getBytes());
+            OutputStream out = response.getOutputStream();
+            out.write("OK\n".getBytes());
+            out.write(("sourceNodeId: " + sourceNode + "\n").getBytes());
+            out.write(("sourceNodeUrl: " + nodeUrl + "\n").getBytes());
+            out.close();
+            
+            //parse the systemMetadata
+            SystemMetadata sm = (SystemMetadata)deserializeServiceType(SystemMetadata.class, fis);
+            NodeReference nr = sm.getOriginMemberNode();
+            nr.setValue(sourceNode);
+            sm.setOriginMemberNode(nr);
+            //get the document
+            MNode mnode = new MNode(nodeUrl);
+            //get the doc from the remote host
+            InputStream docStream = mnode.get(session, sm.getIdentifier());
+            File outputTmpFile = getTempFile();
+            System.out.println("wrote xml file to " + outputTmpFile.getAbsolutePath());
+            FileOutputStream outputTmpFileStream = new FileOutputStream(outputTmpFile);
+            IOUtils.copy(docStream, outputTmpFileStream);
+            
+            //verify checksum
+            System.out.println("verifying checksum");
+            Checksum sourceFileChecksum = ServiceTypeUtil.checksum(new FileInputStream(outputTmpFile), 
+                    sm.getChecksum().getAlgorithm());
+            
+            String cs1 = sm.getChecksum().getValue();
+            String cs2 = sourceFileChecksum.getValue();
+            System.out.println("original checksum: " + cs1);
+            System.out.println(" created checksum: " + cs2);
+            
+            if(!cs1.equals(cs2))
+            {
+                System.out.println("ERROR: Checksums do not match!");
+            }
+            
+            //insert the document in local db
+            //System.out.println("creating new doc");
+            //CrudService.getInstance().create(token, 
+            //        sm.getIdentifier(), new FileInputStream(outputTmpFile), sm);
+            //call cn.setReplicationStatus(guid, COMPLETE)
+            
+        }
+    }
+    
+    /**
+     * create the root node registry response.  
+     * @throws JiBXException
+     * @throws IOException
+     */
+    private void createNodeResponse() 
+        throws JiBXException, IOException
+    {
+        String nodeName = null;
+        String nodeId = null;
+        String nodeUrl = null;
+        String nodeDesc = null;
+        String nodeType = null;
+        
+        try
+        {
+            nodeId = PropertyService.getProperty("dataone.memberNodeId");
+            nodeName = PropertyService.getProperty("dataone.nodeName");
+            nodeUrl = SystemUtil.getContextURL() + "/d1/";
+            nodeDesc = PropertyService.getProperty("dataone.nodeDescription");
+            nodeType = PropertyService.getProperty("dataone.nodeType");
+        }
+        catch(PropertyNotFoundException pnfe)
+        {
+            logMetacat.error("createNodeResponse: " +
+                    "property not found: " + pnfe.getMessage());
+        }
+        
+        NodeList nl = new NodeList();
+        Node n = new Node();
+        NodeReference nr = new NodeReference();
+        nr.setValue(nodeId);
+        n.setIdentifier(nr);
+        n.setBaseURL(nodeUrl);
+        n.setDescription(nodeDesc);
+        n.setName(nodeName + " -- WAR version WARVERSION");
+        n.setType(NodeType.convert(nodeType));
+        
+        //create the services
+        Service mnCrud03 = new Service();
+        mnCrud03.setName("Metacat MN_Crud Services Version 0.3");
+        mnCrud03.setVersion("0.3");
+        
+        Service mnCrud04 = new Service();
+        mnCrud04.setName("Metacat MN_Crud Services Version 0.4");
+        mnCrud04.setVersion("0.4");
+        
+        Service mnCrud09 = new Service();
+        mnCrud09.setName("Metacat MN_Crud Services Version 0.9");
+        mnCrud09.setVersion("0.9");
+        
+        Service mnReplication03 = new Service();
+        mnReplication03.setName("Metcat MN_Replication Version 0.3");
+        mnReplication03.setVersion("0.3");
+        
+        Service mnHealth04 = new Service();
+        mnHealth04.setName("Metacat MN_Health Version 0.4");
+        mnHealth04.setVersion("0.4");
+        
+        Service mnHealth06 = new Service();
+        mnHealth06.setName("Metacat MN_Health Version 0.6");
+        mnHealth06.setVersion("0.6");
+        
+        Service mnAuthentication07 = new Service();
+        mnAuthentication07.setName("Metacat MN_Authentication Version 0.7");
+        mnAuthentication07.setVersion("0.7");
+        
+        Service mnAuthorization07 = new Service();
+        mnAuthorization07.setName("Metacat MN_Authorization Version 0.7");
+        mnAuthorization07.setVersion("0.7");
+        
+        Services ss = new Services();
+        ss.addService(mnCrud03);
+        ss.addService(mnCrud04);
+        ss.addService(mnCrud09);
+        ss.addService(mnReplication03);
+        ss.addService(mnHealth04);
+        ss.addService(mnHealth06);
+        ss.addService(mnAuthentication07);
+        ss.addService(mnAuthorization07);
+        nl.addNode(n);
+        response.setContentType("text/xml");
+        response.setStatus(200);
+        serializeServiceType(NodeList.class, nl, response.getOutputStream());
+    }
+    
+    /**
+     * MN_crud.describe()
+     * http://mule1.dataone.org/ArchitectureDocs/mn_api_crud.html#MN_crud.describe
+     * @param guid
+     */
+    private void describeObject(String guid)
+    {
+        Logger logMetacat = Logger.getLogger(D1ResourceHandler.class);
+        OutputStream out = null;
+        try
+        {
+            out = response.getOutputStream();
+        }
+        catch(Exception e)
+        {
+            logMetacat.error("Error getting output stream in D1ResourceHandler.describeObject: " + e.getClass() + ": " + e.getMessage());
+            return;
+        }
+        response.setStatus(200);
+        response.setContentType("text/xml");
+        Identifier id = new Identifier();
+        id.setValue(guid);
+        try
+        {
+            DescribeResponse dr = MNodeService.getInstance().describe(session, id);
+            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SZ");
+            response.addHeader("guid", guid);
+            response.addHeader("checksum", dr.getDataONE_Checksum().getValue());
+            response.addHeader("checksum_algorithm", dr.getDataONE_Checksum().getAlgorithm().name());
+            response.addHeader("content_length", dr.getContent_Length() + "");
+            response.addHeader("last_modified", dateFormat.format(dr.getLast_Modified()));
+            response.addHeader("format", dr.getDataONE_ObjectFormat().toString());
+        }
+        catch(InvalidRequest ir)
+        {
+            serializeException(ir, out);
+        }
+        catch(NotImplemented ni)
+        {
+            serializeException(ni, out);
+        }
+        catch(NotAuthorized na)
+        {
+            serializeException(na, out);
+        }
+        catch(ServiceFailure sf)
+        {
+            serializeException(sf, out);
+        }
+        catch(NotFound nf)
+        {
+            serializeException(nf, out);
+        }
+        catch(InvalidToken it)
+        {
+            serializeException(it, out);
+        }
+    }
+    
+    /**
+     * get the logs from the CrudService based on passed params.  Available 
+     * params are token, fromDate, toDate, event.  See 
+     * http://mule1.dataone.org/ArchitectureDocs/mn_api_crud.html#MN_crud.getLogRecords
+     * for more info
+     */
+    private void getLog()
+    {
+        OutputStream out = null;
+        try
+        {
+            out = response.getOutputStream();
+            response.setStatus(200);
+            response.setContentType("text/xml");
+            String fromDateS = params.get("fromDate")[0];
+            System.out.println("param fromDateS: " + fromDateS);
+            Date fromDate = null;
+            String toDateS = params.get("toDate")[0];
+            System.out.println("param toDateS: " + toDateS);
+            Date toDate = null;
+            String eventS = params.get("event")[0];
+            Event event = null;
+            if(fromDateS != null)
+            {
+                //fromDate = dateFormat.parse(fromDateS);
+                fromDate = parseDateAndConvertToGMT(fromDateS);
+            }
+            if(toDateS != null)
+            {
+                //toDate = dateFormat.parse(toDateS);
+                toDate = parseDateAndConvertToGMT(toDateS);
+            }
+            if(eventS != null)
+            {
+                event = Event.convert(eventS);
+            }
+            System.out.println("fromDate: " + fromDate + " toDate: " + toDate);
+            
+            Integer start = null;
+            Integer count = null;
+            try {
+            	start =  Integer.parseInt(params.get("start")[0]);
+            } catch (Exception e) {
+				logMetacat.warn("Could not parse start: " + e.getMessage());
+			}
+            try {
+            	count =  Integer.parseInt(params.get("count")[0]);
+            } catch (Exception e) {
+				logMetacat.warn("Could not count start: " + e.getMessage());
+			}
+            
+            System.out.println("calling crudservice.getLogRecords");
+            Log log = MNodeService.getInstance().getLogRecords(session, fromDate, toDate, event, start, count);
+            serializeServiceType(Log.class, log, out);
+        }
+        catch(Exception e)
+        {
+            String msg = "Could not get logs from CrudService: " + e.getClass() + ": " + e.getMessage();
+            response.setStatus(500);
+            ServiceFailure sf = new ServiceFailure("1490", msg);
+            logMetacat.error(msg);
+            e.printStackTrace();
+            serializeException(sf, out);
+        }
+    }
+    
+    /**
+     *  copies request parameters to a hashtable which is given as argument to native metacathandler functions  
+     */
+    protected void initParams() {
+
+        String name = null;
+        String[] value = null;
+        Enumeration paramlist = request.getParameterNames();
+        while (paramlist.hasMoreElements()) {
+            name = (String) paramlist.nextElement();
+            value = request.getParameterValues(name);
+            params.put(name, value);
+        }
+    }
+
+    /**
+     * 
+     * Load user details of metacat session from the request 
+     * 
+     */
+    private void loadSessionData()
+      throws Exception
+    {
+        SessionData sessionData = RequestUtil.getSessionData(request);
+        try
+        {
+            username = null;
+            password = null;
+            groupNames = null;
+            sessionId = null;
+            
+            boolean validSession = false;
+            SessionService ss = SessionService.getInstance();
+            System.out.println("sessionData: " + sessionData);
+            if(sessionData == null)
+            {
+                username = "public";
+                sessionId = "0";
+                System.out.println("sessiondata is null.  Creating a public session.");
+                return;
+            }
+            
+            System.out.println("username: " + sessionData.getUserName());
+            System.out.println("sessionid: " + sessionData.getId());
+            //validate the session
+            if(ss.isSessionRegistered(sessionData.getId()) && 
+               !(sessionData.getUserName().equals("public") || sessionData.getId().equals("0")))
+            {
+                validSession = true;
+            }
+            
+            if(validSession)
+            {
+                //if the session is valid, set these variables
+                username = sessionData.getUserName();
+                password = sessionData.getPassword();
+                groupNames = sessionData.getGroupNames();
+                sessionId = sessionData.getId();
+                System.out.println("setting sessionid to " + sessionId);
+                System.out.println("username: " + username);
+            }
+            
+            //if the session is not valid or the username is null, set
+            //username to public
+            if (username == null) 
+            {
+                System.out.println("setting username to public.");
+                username = "public";
+            }
+        }
+        catch(Exception e)
+        {
+            e.printStackTrace();
+            throw new Exception("Could not load the session data: " + e.getClass() + ": " + e.getMessage());
+        }
+    }
+
+    /**
+     *  Earthgrid API > Identifier Service > isRegistered Function : 
+     *  calls MetacatHandler > handleIdIsRegisteredAction
+     * @param guid
+     * @throws IOException
+     */
+    private void isRegistered(String guid) throws IOException
+    {
+        
+        // Look up the localId for this guid
+        IdentifierManager im = IdentifierManager.getInstance();
+        String localId = "";
+        try {
+            localId = im.getLocalId(guid);
+        } catch (McdbDocNotFoundException e) {
+            // TODO: Need to return the proper DataONE exception
+        }
+        
+        params.put("docid", new String[] { localId });
+        PrintWriter out = response.getWriter();
+        response.setStatus(200);
+        response.setContentType("text/xml");
+        handler.handleIdIsRegisteredAction(out, params, response);
+        out.close();
+    }
+
+    /**
+     * Earthgrid API > Identifier Service > getAllDocIds Function : 
+     * calls MetacatHandler > handleGetAllDocidsAction
+     * @throws IOException
+     */
+    private void getAllDocIds() throws IOException {
+        PrintWriter out = response.getWriter();
+        response.setStatus(200);
+        response.setContentType("text/xml");
+        handler.handleGetAllDocidsAction(out, params, response);
+        out.close();
+    }
+
+    /**
+     * Earthgrid API > Identifier Service > getNextRevision Function : 
+     * calls MetacatHandler > handleGetRevisionAndDocTypeAction
+     * @param guid
+     * @throws IOException
+     */
+    private void getNextRevision(String guid) throws IOException 
+    {
+        params.put("docid", new String[] { guid });
+        PrintWriter out = response.getWriter();
+        response.setStatus(200);
+        response.setContentType("text/xml");
+        //handler.handleGetRevisionAndDocTypeAction(out, params);
+
+        try {
+            // Make sure there is a docid
+            if (guid == null || guid.equals("")) {
+                throw new Exception("User didn't specify docid!");
+            }
+
+            // Look up the localId for this guid
+            IdentifierManager im = IdentifierManager.getInstance();
+            String localId = "";
+            try {
+                localId = im.getLocalId(guid);
+            } catch (McdbDocNotFoundException e) {
+                // TODO: Need to return the proper DataONE exception
+            }
+           
+            // Create a DBUtil object
+            DBUtil dbutil = new DBUtil();
+            // Get a rev and doctype
+            String revAndDocType = dbutil
+                    .getCurrentRevisionAndDocTypeForGivenDocument(localId);
+            int revision = Integer.parseInt(revAndDocType.split(";")[0]) + 1;
+
+            out.println("<?xml version=\"1.0\"?>");
+            out.print("<next-revision>");
+            out.print(revision);
+            out.print("</next-revision>");
+
+        } catch (Exception e) {
+            // Handle exception
+            response.setStatus(500);
+            out.println("<?xml version=\"1.0\"?>");
+            out.println("<error>");
+            out.println(e.getClass() + ": " + e.getMessage());
+            out.println("</error>");
+        }
+
+        out.close();
+    }
+
+    /**
+     * Earthgrid API > Identifier Service > getNextObject Function : 
+     * calls MetacatHandler > handleGetMaxDocidAction
+     * @throws IOException
+     */
+    private void getNextObject() throws IOException {
+        PrintWriter out = response.getWriter();
+        response.setStatus(200);
+        response.setContentType("text/xml");
+        handler.handleGetMaxDocidAction(out, params, response);
+        out.close();
+    }
+
+    /**
+     * Implements REST version of DataONE CRUD API --> get
+     * @param guid ID of data object to be read
+     */
+    protected void getObject(String guid) {
+        OutputStream out = null;
+        try {
+            out = response.getOutputStream();
+            response.setStatus(200);
+            
+            if(guid != null)
+            { //get a specific document                
+                Identifier id = new Identifier();
+                id.setValue(guid);
+                try
+                {
+                    
+                    SystemMetadata sm = MNodeService.getInstance().getSystemMetadata(session, id);
+                    
+                    //set the content type
+                    if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
+                    		ObjectFormatCache.getInstance().getFormat("text/csv").getFmtid().getValue()))
+                    {
+                        response.setContentType("text/csv");
+                        response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".csv");
+                    }
+                    else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
+                    		ObjectFormatCache.getInstance().getFormat("text/plain").getFmtid().getValue()))
+                    {
+                        response.setContentType("text/plain");
+                        response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".txt");
+                    } 
+                    else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
+                    		ObjectFormatCache.getInstance().getFormat("application/octet-stream").getFmtid().getValue()))
+                    {
+                        response.setContentType("application/octet-stream");
+                    }
+                    else
+                    {
+                        response.setContentType("text/xml");
+                        response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".xml");
+                    }
+                    
+                    InputStream data = MNodeService.getInstance().get(session, id);
+                    IOUtils.copyLarge(data, response.getOutputStream());
+                }
+                catch(InvalidToken it)
+                {
+                    response.setStatus(500);
+                    serializeException(it, out); 
+                }
+                catch(ServiceFailure sf)
+                {
+                    response.setStatus(500);
+                    serializeException(sf, out); 
+                }
+                catch(NotAuthorized na)
+                {
+                    response.setStatus(500);
+                    serializeException(na, out); 
+                }
+                catch(NotFound nf)
+                {
+                    response.setStatus(500);
+                    serializeException(nf, out); 
+                }
+                catch(NotImplemented ni)
+                {
+                    response.setStatus(500);
+                    serializeException(ni, out); 
+                }
+                catch(Exception e)
+                {
+                    response.setStatus(500);
+                    System.out.println("Error with Crud.get().  " +
+                            "If this is an 'Exception producing data' error, " +
+                            "go to CrudService.get() for better debugging.  " +
+                            "Here's the error: " + e.getClass() + ": " + e.getMessage());
+                    e.printStackTrace();
+                    ServiceFailure sf = new ServiceFailure("1030", 
+                            "IO Error in D1ResourceHandler.getObject: " + e.getClass() + ": " + e.getMessage());
+                    serializeException(sf, out); 
+                }
+            }
+            else
+            { //call listObjects with specified params
+                Date startTime = null;
+                Date endTime = null;
+                ObjectFormat objectFormat = null;
+                boolean replicaStatus = false;
+                int start = 0;
+                //TODO: make the max count into a const
+                int count = 1000;
+                Enumeration paramlist = request.getParameterNames();
+                while (paramlist.hasMoreElements()) 
+                { //parse the params and make the crud call
+                    String name = (String) paramlist.nextElement();
+                    String[] value = (String[])request.getParameterValues(name);
+                    /*for(int i=0; i<value.length; i++)
+                    {
+                        System.out.println("name: " + name + " value: " + value[i]);
+                    }*/
+                    if(name.equals("startTime") && value != null)
+                    {
+                        try
+                        {
+                          //startTime = dateFormat.parse(value[0]);
+                            startTime = parseDateAndConvertToGMT(value[0]);
+                        }
+                        catch(Exception e)
+                        {  //if we can't parse it, just don't use the startTime param
+                            System.out.println("Could not parse startTime: " + value[0]);
+                            startTime = null;
+                        }
+                    }
+                    else if(name.equals("endTime") && value != null)
+                    {
+                        try
+                        {
+                          //endTime = dateFormat.parse(value[0]);
+                            endTime = parseDateAndConvertToGMT(value[0]);
+                        }
+                        catch(Exception e)
+                        {  //if we can't parse it, just don't use the endTime param
+                            System.out.println("Could not parse endTime: " + value[0]);
+                            endTime = null;
+                        }
+                    }
+                    else if(name.equals("objectFormat") && value != null) 
+                    {
+                        objectFormat = ObjectFormatCache.getInstance().getFormat(value[0]);
+                    }
+                    else if(name.equals("replicaStatus") && value != null)
+                    {
+                        if(value != null && 
+                           value.length > 0 && 
+                           (value[0].equals("true") || value[0].equals("TRUE") || value[0].equals("YES")))
+                        {
+                            replicaStatus = true;
+                        }
+                    }
+                    else if(name.equals("start") && value != null)
+                    {
+                        start = new Integer(value[0]).intValue();
+                    }
+                    else if(name.equals("count") && value != null)
+                    {
+                        count = new Integer(value[0]).intValue();
+                    }
+                }
+                //make the crud call
+                System.out.println("session: " + session + " startTime: " + startTime +
+                        " endtime: " + endTime + " objectFormat: " + 
+                        objectFormat + " replicaStatus: " + replicaStatus + 
+                        " start: " + start + " count: " + count);
+               
+                ObjectList ol = MNodeService.getInstance().listObjects(session, startTime, endTime, 
+                        objectFormat, replicaStatus, start, count);
+                
+                StringReader sr = new StringReader(ol.toString());                
+                out = response.getOutputStream();  
+                response.setStatus(200);
+                response.setContentType("text/xml");
+                // Serialize and write it to the output stream
+                
+                try {
+                    serializeServiceType(ObjectList.class, ol, out);
+                } catch (JiBXException e) {
+                    throw new ServiceFailure("1190", "Failed to serialize ObjectList: " + e.getMessage());
+                }
+            }
+        } catch (BaseException e) {
+                response.setStatus(500);
+                serializeException(e, out);
+        } catch (IOException e) {
+            e.printStackTrace();
+            response.setStatus(500);
+            ServiceFailure sf = new ServiceFailure("1030", 
+                    "IO Error in D1ResourceHandler.getObject: " + e.getMessage());
+            serializeException(sf, out); 
+        } catch(NumberFormatException ne) {
+            response.setStatus(500);
+            InvalidRequest ir = new InvalidRequest("1030", "Invalid format for parameter: " + ne.getMessage());
+            serializeException(ir, out);
+        } catch (Exception e) {
+            e.printStackTrace();
+            response.setStatus(500);
+            ServiceFailure sf = new ServiceFailure("1030", 
+                    "Exception " + e.getClass().getName() + " raised while handling listObjects request: " + 
+                    e.getMessage());
+            serializeException(sf, out);
+        }
+    }
+    
+    /**
+     * parse a date and return it in GMT if it ends with a 'Z'
+     * @param date
+     * @return
+     * @throws ParseException
+     */
+    protected Date parseDateAndConvertToGMT(String date) throws ParseException
+    {
+        try
+        {   //the format we want
+            return dateFormat.parse(date);
+        }
+        catch(java.text.ParseException pe)
+        {   //try another legacy format
+            DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
+            dateFormat2.setTimeZone(TimeZone.getTimeZone("GMT-0"));
+            return dateFormat2.parse(date);
+        }    
+    }
+
+    /**
+     * Implements REST version of DataONE CRUD API --> getSystemMetadata
+     * @param guid ID of data object to be read
+     */
+    protected void getSystemMetadataObject(String guid) {
+        OutputStream out = null;
+        try {
+            response.setContentType("text/xml");
+            response.setStatus(200);
+            out = response.getOutputStream();
+            Identifier id = new Identifier();
+            id.setValue(guid);
+            SystemMetadata sysmeta = MNodeService.getInstance().getSystemMetadata(session, id);
+            
+            // Serialize and write it to the output stream
+            try {
+                //TODO: look at the efficiency of this method.  The system metadata
+                //is read from metacat (in CrudService) as xml, then serialized
+                //to a SystemMetadat object, then returned here, then serizlized
+                //back to XML to be sent to the response.
+                serializeServiceType(SystemMetadata.class, sysmeta, out);
+            } catch (JiBXException e) {
+                throw new ServiceFailure("1190", "Failed to serialize SystemMetadata: " + e.getMessage());
+            }
+        } catch (BaseException e) {
+            response.setStatus(500);
+                serializeException(e, out);
+        } catch (IOException e) {
+            response.setStatus(500);
+            ServiceFailure sf = new ServiceFailure("1030", 
+                    "IO Error in D1ResourceHandler.getSystemMetadataObject: " + e.getMessage());
+            serializeException(sf, out);
+        } finally {
+            IOUtils.closeQuietly(out);
+        }
+    }
+    
+    /**
+     * serialize an object of type to out
+     * @param type the class of the object to serialize (i.e. SystemMetadata.class)
+     * @param object the object to serialize
+     * @param out the stream to serialize it to
+     * @throws JiBXException
+     */
+    protected void serializeServiceType(Class type, Object object, OutputStream out)
+      throws JiBXException
+    {
+        ServiceTypeUtil.serializeServiceType(type, object, out);
+    }
+    
+    /**
+     * deserialize an object of type from is
+     * @param type the class of the object to serialize (i.e. SystemMetadata.class)
+     * @param is the stream to deserialize from
+     * @throws JiBXException
+     */
+    protected Object deserializeServiceType(Class type, InputStream is)
+      throws JiBXException
+    {
+        return ServiceTypeUtil.deserializeServiceType(type, is);
+    }
+    
+    /**
+     * Earthgrid API > Query Service > Query Function : translates ecogrid query document to metacat query 
+     * then calls DBQuery > createResultDocument function and then again translate resultset to ecogrid resultset
+     * 
+     * NOTE:
+     *      This is the only method that uses EcoGrid classes for its implementation.  
+     *      It does so because it takes an EcoGrid Query as input, and outputs an
+     *      EcoGrid ResultSet document.  These documents are parsed by the auto-generated
+     *      EcoGrid classes from axis, and so we link to them here rather than re-inventing them.
+     *      This creates a circular dependency, because the Metacat classes are needed
+     *      to build the EcoGrid implementation, and the EcoGrid jars are needed to build this query()
+     *      method.  This circularity could be resolved by moving the EcoGrid classes
+     *      to Metacat directly.  As we transition away from EcoGrid SOAP methods in
+     *      favor of these REST interfaces, this circular dependency can be eliminated.
+     *        
+     * @throws Exception
+     */
+    private void query() throws Exception {
+        /*  This block commented out because of the EcoGrid circular dependency.
+         *  For now, query will not be supported until the circularity can be
+         *  resolved, probably by moving the ecogrid query syntax transformers
+         *  directly into the Metacat codebase.  MBJ 2010-02-03
+         
+        try {
+            EcogridQueryParser parser = new EcogridQueryParser(request
+                    .getReader());
+            parser.parseXML();
+            QueryType queryType = parser.getEcogridQuery();
+            EcogridJavaToMetacatJavaQueryTransformer queryTransformer = 
+                new EcogridJavaToMetacatJavaQueryTransformer();
+            QuerySpecification metacatQuery = queryTransformer
+                    .transform(queryType);
+
+            DBQuery metacat = new DBQuery();
+
+            boolean useXMLIndex = (new Boolean(PropertyService
+                    .getProperty("database.usexmlindex"))).booleanValue();
+            String xmlquery = "query"; // we don't care the query in resultset,
+            // the query can be anything
+            PrintWriter out = null; // we don't want metacat result, so set out null
+
+            // parameter: queryspecification, user, group, usingIndexOrNot
+            StringBuffer result = metacat.createResultDocument(xmlquery,
+                    metacatQuery, out, username, groupNames, useXMLIndex);
+
+            // create result set transfer       
+            String saxparser = PropertyService.getProperty("xml.saxparser");
+            MetacatResultsetParser metacatResultsetParser = new MetacatResultsetParser(
+                    new StringReader(result.toString()), saxparser, queryType
+                            .getNamespace().get_value());
+            ResultsetType records = metacatResultsetParser.getEcogridResult();
+
+            System.out
+                    .println(EcogridResultsetTransformer.toXMLString(records));
+            response.setContentType("text/xml");
+            out = response.getWriter();
+            out.print(EcogridResultsetTransformer.toXMLString(records));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }*/
+        response.setContentType("text/xml");
+        response.setStatus(501);
+        PrintWriter out = response.getWriter();
+        out.print("<error>Query operation not yet supported by Metacat.</error>");
+        out.close();
+    }
+    
+    /**
+     * locate the boundary marker for an MMP
+     * @param is
+     * @return
+     * @throws IOException
+     */
+    protected static String[] findBoundaryString(InputStream is)
+        throws IOException
+    {
+        String[] endResult = new String[2];
+        String boundary = "";
+        String searchString = "boundary=";
+        boolean doneWithCurrentArray = false;
+        byte[] b = new byte[1024];
+        int numbytes = is.read(b, 0, 1024);
+
+        while(numbytes != -1)
+        {
+            String s = new String(b, 0, numbytes);
+            int searchStringIndex = s.indexOf(searchString);
+            
+            if(s.indexOf("\"", searchStringIndex + searchString.length() + 1) == -1)
+            { //the end of the boundary is in the next byte array
+                boundary = s.substring(searchStringIndex + searchString.length() + 1, s.length());
+            }
+            else if(!boundary.startsWith("--"))
+            { //we can read the whole boundary from this byte array
+                boundary = s.substring(searchStringIndex + searchString.length() + 1, 
+                    s.indexOf("\"", searchStringIndex + searchString.length() + 1));
+                boundary = "--" + boundary;
+                endResult[0] = boundary;
+                endResult[1] = s.substring(s.indexOf("\"", searchStringIndex + searchString.length() + 1) + 1,
+                        s.length());
+                break;
+            }
+            else
+            { //we're now reading the 2nd byte array to get the rest of the boundary
+                searchString = "\"";
+                searchStringIndex = s.indexOf(searchString);
+                boundary += s.substring(0, searchStringIndex);
+                boundary = "--" + boundary;
+                endResult[0] = boundary;
+                endResult[1] = s.substring(s.indexOf("\"", searchStringIndex + searchString.length() + 1) + 1,
+                        s.length());
+                break;
+            }
+        }
+        System.out.println("boundary is: '" + boundary + "'");
+        return endResult;
+    }
+    
+    /**
+     * return the directory where temp files are stored
+     * @return
+     */
+    protected static File getTempDirectory()
+    {
+        File tmpDir = null;
+        Logger logMetacat = Logger.getLogger(D1ResourceHandler.class);
+        try
+        {
+            tmpDir = new File(PropertyService.getProperty("application.tempDir"));
+        }
+        catch(PropertyNotFoundException pnfe)
+        {
+            logMetacat.error("D1ResourceHandler.writeMMPPartstoFiles: " +
+                    "application.tmpDir not found.  Using /tmp instead.");
+            tmpDir = new File("/tmp");
+        }
+        return tmpDir;
+    }
+    
+    /**
+     * return a tmp file with a given name
+     * @param name
+     * @return
+     */
+    private static File getTempFile(String name)
+    {
+        File tmpDir = getTempDirectory();
+        File f = new File(tmpDir, name);
+        return f;
+    }
+    
+    /**
+     * return a temp file with a default name
+     * @return
+     */
+    private static File getTempFile()
+    {
+        return getTempFile(new Date().getTime() + ".tmp");
+    }
+    
+    /**
+     * Earthgrid API > Put Service >Put Function : calls MetacatHandler > handleInsertOrUpdateAction 
+     * 
+     * @param guid - ID of data object to be inserted or updated.  If action is update, the pid
+     *               is the existing pid.  If insert, the pid is the new one
+     * @throws IOException
+     */
+    protected void putObject(String pid, String action) {
+        System.out.println("D1ResourceHandler: putObject with pid " + pid);
+        logMetacat.debug("Entering putObject: " + pid + "/" + action);
+        OutputStream out = null;
+        try {
+            out = response.getOutputStream();
+            response.setStatus(200);
+            response.setContentType("text/xml");
+        } catch (IOException e1) {
+            logMetacat.error("Could not get the output stream for writing in putObject");
+        }
+        try {
+            
+            // Read the incoming data from its Mime Multipart encoding
+            logMetacat.debug("Disassembling MIME multipart form");
+            InputStream object = null;
+            InputStream sysmeta = null;
+            Map<String, List<String>> multipartparams;
+            
+            try
+            {
+                //String req = IOUtils.toString(request.getInputStream());
+                //System.out.println("request: " + req);
+                //InputStream reqStr = IOUtils.toInputStream(req);
+                InputStream reqStr = request.getInputStream();
+                
+                //handle MMP inputs
+                File tmpDir = getTempDirectory();
+                File tmpSMFile = new File(tmpDir + 
+                        ".sysmeta." + new Date().getTime() + ".tmp");
+                System.out.println("temp dir: " + tmpDir.getAbsolutePath());
+                MultipartRequestResolver mrr = new MultipartRequestResolver(
+                        tmpDir.getAbsolutePath(), 1000000000, 0);
+                MultipartRequest mr = mrr.resolveMultipart(request);
+                System.out.println("resolved multipart request");
+                Map<String, File> files = mr.getMultipartFiles();
+                if(files == null)
+                {
+                    throw new ServiceFailure("1202", "create/update must have multipart files with names 'object' and 'sysmeta'");
+                }
+                System.out.println("got multipart files");
+                
+                if(files.keySet() == null)
+                {
+                    System.out.println("No file keys in MMP request.");
+                    throw new ServiceFailure("1202", "No file keys found in MMP.  " +
+                            "create/update must have multipart files with names 'object' and 'sysmeta'");
+                }
+
+		// for logging purposes, dump out the key-value pairs that constitute the request
+		// 3 types exist: request params, multipart params, and multipart files
+                Iterator it = files.keySet().iterator();
+                System.out.println("iterating through request parts: " + it);
+                while(it.hasNext())
+                {
+                    String key = (String)it.next();
+                    System.out.println("files key: " + key);
+                    System.out.println("files value: " + files.get(key));
+                }
+                
+                multipartparams = mr.getMultipartParameters();
+                it = multipartparams.keySet().iterator();
+                while(it.hasNext())
+                {
+                    String key = (String)it.next();
+                    System.out.println("multipartparams key: " + key);
+                    System.out.println("multipartparams value: " + multipartparams.get(key));
+                }
+                
+                it = params.keySet().iterator();
+                while(it.hasNext())
+                {
+                    String key = (String)it.next();
+                    System.out.println("param key: " + key);
+                    System.out.println("param value: " + params.get(key));
+                }
+		System.out.println("done iterating the request...");
+
+                File smFile = files.get("sysmeta");
+		if (smFile == null) 
+		    throw new InvalidRequest("1102", "Missing the required file-part 'sysmeta' from the multipart request.");
+                System.out.println("smFile: " + smFile.getAbsolutePath());
+                sysmeta = new FileInputStream(smFile);
+                File objFile = files.get("object");
+		if (objFile == null) 
+		    throw new InvalidRequest("1102", "Missing the required file-part 'object' from the multipart request.");
+
+                System.out.println("objectfile: " + objFile.getAbsolutePath());
+                object = new FileInputStream(objFile);
+                
+                /*String obj = IOUtils.toString(object);
+                String sm = IOUtils.toString(sysmeta);
+                System.out.println("object: " + obj);
+                System.out.println("sm: " + sm);
+                object = IOUtils.toInputStream(obj);
+                sysmeta = IOUtils.toInputStream(sm);*/
+                
+            }
+            catch(org.apache.commons.fileupload.FileUploadException fue)
+            {
+                throw new ServiceFailure("1202", "Could not upload MMP files: " + fue.getMessage());
+            }
+            catch(IOException ioe)
+            {
+                throw new ServiceFailure("1202", 
+                        "IOException when processing Mime Multipart: " + ioe.getMessage());
+            }
+            catch(Exception e)
+            {
+                throw new ServiceFailure("1202", "Error handling MMP upload: " + e.getClass() + ": " + e.getMessage());
+            }
+            
+            if ( action.equals(FUNCTION_NAME_INSERT)) { //handle inserts
+
+                // Check if the objectId exists
+                IdentifierManager im = IdentifierManager.getInstance();
+                if (im.identifierExists(pid)) {
+                    throw new IdentifierNotUnique("1000", "Identifier is already in use: " + pid);
+                }
+
+                logMetacat.debug("Commence creation...");
+                IBindingFactory bfact =
+                    BindingDirectory.getFactory(SystemMetadata.class);
+                IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
+                SystemMetadata smd = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null);
+
+                Identifier id = new Identifier();
+                id.setValue(pid);
+                System.out.println("creating object with pid " + id.getValue());
+                Identifier rId = MNodeService.getInstance().create(session, id, object, smd);
+                serializeServiceType(Identifier.class, rId, out);
+                
+            } else if (action.equals(FUNCTION_NAME_UPDATE)) { //handle updates
+
+            	// Check if the objectId exists
+                IdentifierManager im = IdentifierManager.getInstance();
+                if (!im.identifierExists(pid)) {
+                    throw new NotFound("1280", "The pid you are trying to update does not exist: " + pid);
+                }
+                // check that the newPid parameter was provided and it doesn't exist
+                if(multipartparams.get("newPid") == null)
+                    throw new InvalidRequest("1202", "'newPid' must be contained in the request parameters.");
+                String newPidString = multipartparams.get("newPid").get(0);
+                if (im.identifierExists(newPidString)) 
+                    throw new IdentifierNotUnique("1220", "Identifier is already in use: " + newPidString);
+               
+                
+                Identifier newPid = new Identifier();
+                Identifier obsoletedPid = new Identifier();
+                newPid.setValue(newPidString);
+                obsoletedPid.setValue(pid);
+               
+                logMetacat.debug("Commence update...");
+                
+                //get the systemmetadata
+                IBindingFactory bfact =
+                	BindingDirectory.getFactory(SystemMetadata.class);
+                IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
+                SystemMetadata smd = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null);
+
+                Identifier rId = MNodeService.getInstance().update(session, newPid, object, obsoletedPid, smd);
+                serializeServiceType(Identifier.class, rId, out);
+            } else {
+                throw new InvalidRequest("1000", "Operation must be create or update.");
+            }
+            
+            //clean up the MMP files
+            //parts.get("systemmetadata").delete();
+            //parts.get("object").delete();
+        } catch (NotAuthorized e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (InvalidToken e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (ServiceFailure e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (NotFound e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (IdentifierNotUnique e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (UnsupportedType e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (InsufficientResources e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (InvalidSystemMetadata e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (NotImplemented e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (InvalidRequest e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } /*catch (MessagingException e) {
+            ServiceFailure sf = new ServiceFailure("1000", e.getMessage());
+            serializeException(sf, out);
+        } catch (IOException e) {
+            response.setStatus(500);
+            ServiceFailure sf = new ServiceFailure("1000", e.getMessage());
+            serializeException(sf, out);
+        }*/ catch (JiBXException e) {
+            response.setStatus(500);
+            e.printStackTrace(System.out);
+            InvalidSystemMetadata ism = new InvalidSystemMetadata("1080", e.getMessage());
+            serializeException(ism, out);
+        }
+    }
+
+    /**
+     * Handle delete 
+     * @param guid ID of data object to be deleted
+     * @throws IOException
+     */
+    private void deleteObject(String guid) throws IOException 
+    {
+        // Look up the localId for this global identifier
+        System.out.println("!!!!!!!!!!!!!!!!!deleting object " + guid);
+        IdentifierManager im = IdentifierManager.getInstance();
+        String localId = "";
+        OutputStream out = response.getOutputStream();
+        response.setStatus(200);
+        try {
+            localId = im.getLocalId(guid);
+        } catch (McdbDocNotFoundException e) {
+            NotFound nf = new NotFound("1340", "Document with guid " + guid + " not found.");
+            response.setStatus(404);
+            serializeException(nf, out);
+        }
+       
+        
+        Identifier id = new Identifier();
+        id.setValue(guid);
+        try
+        {
+            System.out.println("Calling delete");
+            MNodeService.getInstance().delete(session, id);
+            serializeServiceType(Identifier.class, id, out);
+        } 
+        catch (NotAuthorized e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (InvalidToken e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (ServiceFailure e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (NotImplemented e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch (InvalidRequest e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch(NotFound e) {
+            response.setStatus(500);
+            serializeException(e, out);
+        } catch(JiBXException e) {
+            response.setStatus(500);
+            serializeException(new ServiceFailure("1350", "JiBXException: " + e.getMessage()), out);
+        }
+        out.close();
+    }
+    
+    /**
+     * set the access perms on a document
+     * @throws Exception
+     */
+    protected void setaccess() throws Exception
+    {
+        try
+        {
+            String guid = params.get("guid")[0];
+            Identifier id = new Identifier();
+            id.setValue(guid);
+            String accesspolicy = params.get("accesspolicy")[0];
+            AccessPolicy accessPolicy = (AccessPolicy) deserializeServiceType(AccessPolicy.class, new ByteArrayInputStream(accesspolicy.getBytes("UTF-8")));
+            MNodeService.getInstance().setAccessPolicy(session, id, accessPolicy);
+        }
+        catch(Exception e)
+        {
+            response.setStatus(500);
+            printError("Error setting access in D1ResourceHandler: " + e.getClass() + ": " + e.getMessage(), response);
+            throw e;
+        }
+    }
+
+    /**
+     * Earthgrid API > Authentication Service > Login Function : calls MetacatHandler > handleLoginAction
+     * 
+     * @throws IOException
+     */
+    private void login() throws IOException {
+        PrintWriter out = response.getWriter();
+        response.setStatus(200);
+        response.setContentType("text/xml");
+        handler.handleLoginAction(out, params, request, response);
+        out.close();
+    }
+
+    /**
+     * Earthgrid API > Authentication Service > Logout Function : calls MetacatHandler > handleLogoutAction
+     * 
+     * @throws IOException
+     */
+    private void logout() throws IOException {
+        PrintWriter out = response.getWriter();
+        response.setStatus(200);
+        response.setContentType("text/xml");
+        handler.handleLogoutAction(out, params, request, response);
+        out.close();
+    }
+
+    /**
+     * Prints xml response
+     * @param message Message to be displayed
+     * @param response Servlet response that xml message will be printed 
+     * */
+    protected void printError(String message, HttpServletResponse response) {
+        try {
+            logMetacat.error("D1ResourceHandler: Printing error to servlet response: " + message);
+            PrintWriter out = response.getWriter();
+            response.setContentType("text/xml");
+            out.println("<?xml version=\"1.0\"?>");
+            out.println("<error>");
+            out.println(message);
+            out.println("</error>");
+            out.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    
+    /**
+     * serialize a D1 exception using jibx
+     * @param e
+     * @param out
+     */
+    protected void serializeException(BaseException e, OutputStream out) {
+        // TODO: Use content negotiation to determine which return format to use
+        response.setContentType("text/xml");
+        response.setStatus(e.getCode());
+        
+        logMetacat.error("D1ResourceHandler: Serializing exception with code " + e.getCode() + ": " + e.getMessage());
+        e.printStackTrace();
+        
+        try {
+            IOUtils.write(e.serialize(BaseException.FMT_XML), out);
+        } catch (IOException e1) {
+            logMetacat.error("Error writing exception to stream. " 
+                    + e1.getMessage());
+        }
+    }
+
+
+    /**
+     * List the object formats registered with the system
+     */
+		private void listFormats() {
+      logMetacat.debug("Entering listFormats()");
+      // get the response output stream
+      OutputStream out = null;
+      
+      try {
+	      out = response.getOutputStream();
+	      response.setStatus(200);
+	      response.setContentType("text/xml");
+	      
+      } catch (IOException ioe) {
+      	logMetacat.error("Could not get the output stream for writing" +
+      	  "in D1ResourceHandler.listFormats()");
+      
+      }
+
+      // get the object format list
+      try {
+	      ObjectFormatList objectFormatList = CNodeService.getInstance().listFormats();
+	      serializeServiceType(ObjectFormatList.class, objectFormatList, out);
+      
+      } catch (InvalidRequest e) {
+      	response.setStatus(200);
+      	serializeException(e, out);
+      	
+      } catch (ServiceFailure e) {
+      	response.setStatus(501);
+      	serializeException(e, out);
+      
+      } catch (NotFound e) {
+      	response.setStatus(200);
+      	serializeException(e, out);
+      
+      } catch (InsufficientResources e) {
+      	response.setStatus(200);
+      	serializeException(e, out);
+      
+      } catch (NotImplemented e) {
+      	response.setStatus(200);
+      	serializeException(e, out);
+      
+      } catch (JiBXException jibxe) {
+      	response.setStatus(501);
+      	ServiceFailure e = 
+      		new ServiceFailure("4841", "Unexpected exception from the service - " + 
+        	                   jibxe.getClass() + ": " + jibxe.getMessage());
+      	serializeException(e, out);
+      	
+      }
+      
+    }
+
+		/**
+     * Return the requested object format
+     * 
+     * @param fmtidStr the requested format identifier as a string
+     */
+    private void getFormat(String fmtidStr) {
+      logMetacat.debug("Entering listFormats()");
+      
+      // get the response output stream
+      OutputStream out = null;
+      try {
+	      out = response.getOutputStream();
+	      response.setStatus(200);
+	      response.setContentType("text/xml");
+	      
+      } catch (IOException ioe) {
+      	logMetacat.error("Could not get the output stream for writing" +
+      	  "in D1ResourceHandler.listFormats()");
+      
+      }
+      
+      ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
+      fmtid.setValue(fmtidStr);
+      
+      try {
+      	// get the specified object format
+	      ObjectFormat objectFormat = CNodeService.getInstance().getFormat(fmtid);
+	      serializeServiceType(ObjectFormat.class, objectFormat, out);
+
+      } catch (InvalidRequest e) {
+      	response.setStatus(200);
+      	serializeException(e, out);
+      
+      } catch (ServiceFailure e) {
+      	response.setStatus(501);
+      	serializeException(e, out);
+      
+      } catch (NotFound e) {
+      	response.setStatus(200);
+      	serializeException(e, out);
+      
+      } catch (InsufficientResources e) {
+      	response.setStatus(200);
+      	serializeException(e, out);
+      
+      } catch (NotImplemented e) {
+      	response.setStatus(200);
+      	serializeException(e, out);
+      
+      } catch (JiBXException jibxe) {
+      	ServiceFailure e = 
+      		new ServiceFailure("4841", "Unexpected exception from the service - " + 
+        	                   jibxe.getClass() + ": " + jibxe.getMessage());
+      	serializeException(e, out);
+
+      }
+	    
+    }
+
+    /**
+     * Register System Metadata without data or metadata object
+     * @param pid identifier for System Metadata entry
+     */
+    protected void registerSystemMetadata(String pid) {
+		logMetacat.debug("Entering registerSystemMetadata: " + pid);
+		OutputStream out = null;
+		try {
+			out = response.getOutputStream();
+			response.setStatus(200);
+			response.setContentType("text/xml");
+		} catch (IOException e1) {
+			logMetacat.error("Could not get the output stream for writing in putObject");
+		}
+		try {
+
+			// Read the incoming data from its Mime Multipart encoding
+			logMetacat.debug("Disassembling MIME multipart form");
+			InputStream sysmeta = null;
+			Map<String, List<String>> multipartparams;
+
+			try {
+
+				// handle MMP inputs
+				File tmpDir = getTempDirectory();
+
+				logMetacat.debug("temp dir: " + tmpDir.getAbsolutePath());
+				MultipartRequestResolver mrr = new MultipartRequestResolver(
+						tmpDir.getAbsolutePath(), 1000000000, 0);
+				MultipartRequest mr = mrr.resolveMultipart(request);
+				logMetacat.debug("resolved multipart request");
+				Map<String, File> files = mr.getMultipartFiles();
+				if (files == null) {
+					throw new ServiceFailure("1202",
+							"register meta must have multipart file with name 'sysmeta'");
+				}
+				logMetacat.debug("got multipart files");
+
+				if (files.keySet() == null) {
+					logMetacat.error("No file keys in MMP request.");
+					throw new ServiceFailure(
+							"1202",
+							"No file keys found in MMP.  "
+									+ "register meta must have multipart file with name 'sysmeta'");
+				}
+
+				// for logging purposes, dump out the key-value pairs that
+				// constitute the request
+				// 3 types exist: request params, multipart params, and
+				// multipart files
+				Iterator it = files.keySet().iterator();
+				logMetacat.debug("iterating through request parts: " + it);
+				while (it.hasNext()) {
+					String key = (String) it.next();
+					logMetacat.debug("files key: " + key);
+					logMetacat.debug("files value: " + files.get(key));
+				}
+
+				multipartparams = mr.getMultipartParameters();
+				it = multipartparams.keySet().iterator();
+				while (it.hasNext()) {
+					String key = (String) it.next();
+					logMetacat.debug("multipartparams key: " + key);
+					logMetacat.debug("multipartparams value: "
+							+ multipartparams.get(key));
+				}
+
+				it = params.keySet().iterator();
+				while (it.hasNext()) {
+					String key = (String) it.next();
+					logMetacat.debug("param key: " + key);
+					logMetacat.debug("param value: " + params.get(key));
+				}
+				logMetacat.debug("done iterating the request...");
+
+				File smFile = files.get("sysmeta");
+				if (smFile == null) {
+					throw new InvalidRequest("1102",
+							"Missing the required file-part 'sysmeta' from the multipart request.");
+				}
+				logMetacat.debug("smFile: " + smFile.getAbsolutePath());
+				sysmeta = new FileInputStream(smFile);
+
+			} catch (org.apache.commons.fileupload.FileUploadException fue) {
+				throw new ServiceFailure("1202", "Could not upload MMP files: "
+						+ fue.getMessage());
+			} catch (IOException ioe) {
+				throw new ServiceFailure("1202",
+						"IOException when processing Mime Multipart: "
+								+ ioe.getMessage());
+			} catch (Exception e) {
+				throw new ServiceFailure("1202", "Error handling MMP upload: "
+						+ e.getClass() + ": " + e.getMessage());
+			}
+
+			// Check if the objectId exists
+			IdentifierManager im = IdentifierManager.getInstance();
+			if (im.identifierExists(pid)) {
+				throw new IdentifierNotUnique("1000",
+						"Identifier is already in use: " + pid);
+			}
+
+			logMetacat.debug("Commence creation...");
+			IBindingFactory bfact = BindingDirectory
+					.getFactory(SystemMetadata.class);
+			IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
+			SystemMetadata systemMetadata = (SystemMetadata) uctx
+					.unmarshalDocument(sysmeta, null);
+
+			Identifier guid = new Identifier();
+			guid.setValue(pid);
+			logMetacat.debug("registering system metadata with pid "
+					+ guid.getValue());
+			boolean result = CNodeService.getInstance().registerSystemMetadata(
+					session, guid, systemMetadata);
+			serializeServiceType(Boolean.class, result, out);
+
+		} catch (NotAuthorized e) {
+			response.setStatus(500);
+			serializeException(e, out);
+		} catch (ServiceFailure e) {
+			response.setStatus(500);
+			serializeException(e, out);
+		} catch (IdentifierNotUnique e) {
+			response.setStatus(500);
+			serializeException(e, out);
+		} catch (NotImplemented e) {
+			response.setStatus(500);
+			serializeException(e, out);
+		} catch (InvalidRequest e) {
+			response.setStatus(500);
+			serializeException(e, out);
+		} catch (JiBXException e) {
+			response.setStatus(500);
+			e.printStackTrace(System.out);
+			InvalidSystemMetadata ism = new InvalidSystemMetadata("1080", e
+					.getMessage());
+			serializeException(ism, out);
+		} catch (InvalidSystemMetadata e) {
+			serializeException(e, out);
+    }
+	}
+
+}

Property changes on: src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: src/edu/ucsb/nceas/metacat/restservice/MNRestServlet.java
===================================================================
--- src/edu/ucsb/nceas/metacat/restservice/MNRestServlet.java	(revision 6266)
+++ src/edu/ucsb/nceas/metacat/restservice/MNRestServlet.java	(revision 6267)
@@ -33,13 +33,13 @@
  * Routes MN REST service requests to the appropriate handler
  *  
  */
-public class MNRestServlet extends RestServlet {
+public class MNRestServlet extends D1RestServlet {
     
 	/**
-	 * Provide an MNResourceHandler subclass of ResourceHandler
+	 * Provide an MNResourceHandler subclass of D1ResourceHandler
 	 */
 	@Override
-    protected ResourceHandler createHandler(HttpServletRequest request, HttpServletResponse response) 
+    protected D1ResourceHandler createHandler(HttpServletRequest request, HttpServletResponse response) 
     	throws ServletException, IOException {
         return new MNResourceHandler(getServletContext(), request, response);
     }
