Index: src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java	(revision 5352)
+++ src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java	(revision 5353)
@@ -50,6 +50,7 @@
 import org.dataone.service.exceptions.NotImplemented;
 import org.dataone.service.exceptions.ServiceFailure;
 import org.dataone.service.exceptions.UnsupportedType;
+import org.dataone.service.exceptions.NotFound;
 import org.dataone.service.types.AuthToken;
 import org.dataone.service.types.Identifier;
 import org.dataone.service.types.SystemMetadata;
@@ -240,6 +241,7 @@
         while (paramlist.hasMoreElements()) {
             name = (String) paramlist.nextElement();
             value = request.getParameterValues(name);
+            System.out.println("adding param: " + name + " = " + value);
             params.put(name, value);
         }
 
@@ -609,6 +611,7 @@
      */
     private void putObject(String guid, String action) {
         logMetacat.debug("Entering putObject: " + guid + "/" + action);
+        System.out.println("entering putObject.  Action is " + action);
         
         // TODO: This function lacks proper handling of authz and authn, so it
         // seems that anyone can insert or update; interacts with 
@@ -623,8 +626,33 @@
             logMetacat.error("Could not get the output stream for writing in putObject");
         }
         try {
-            if (action.equals(FUNCTION_NAME_UPDATE)
-                    || action.equals(FUNCTION_NAME_INSERT)) {
+            
+            // Read the incoming data from its Mime Multipart encoding
+            logMetacat.debug("Disassembling MIME multipart form");
+            InputStream object = null;
+            InputStream sysmeta = null;
+            MimeMultipart mmp = new MimeMultipart(new InputStreamDataSource("message", request.getInputStream()));
+            logMetacat.debug("MMP created.");
+            mmp.writeTo(System.out);
+            for (int i = 0; i < mmp.getCount(); i++) {
+                logMetacat.debug("Looping over MMP parts: " + i);
+                BodyPart part = mmp.getBodyPart(i);
+                String name = part.getFileName();
+                logMetacat.debug("Part name is: " + name);
+                System.out.println("part name: " + name);
+                logMetacat.debug("Part has class name: " + part.getClass().getName());
+                if (name.equals("object")) {
+                    object = part.getInputStream();
+                    logMetacat.debug("Found object part, size is: " + part.getSize());
+                } else if (name.equals("systemmetadata")) {
+                    sysmeta = part.getInputStream();
+                    logMetacat.debug("Found sysmeta part, size is: " + part.getSize());
+                } else {
+                    throw new InvalidRequest(1000, "Request had malformed MIME part with name: " + name);
+                }
+            }
+            
+            if ( action.equals(FUNCTION_NAME_INSERT)) { //handle inserts
 
                 // Check if the objectId exists
                 IdentifierManager im = IdentifierManager.getInstance();
@@ -632,32 +660,6 @@
                     throw new IdentifierNotUnique(1000, "Identifier is already in use: " + guid);
                 }
 
-                // TODO: For updates, need to check if the old id exists, and if not throw an exception
-
-                // Read the incoming data from its Mime Multipart encoding
-                logMetacat.debug("Disassembling MIME multipart form");
-                InputStream object = null;
-                InputStream sysmeta = null;
-                MimeMultipart mmp = new MimeMultipart(new InputStreamDataSource("message", request.getInputStream()));
-                logMetacat.debug("MMP created.");
-                mmp.writeTo(System.out);
-                for (int i = 0; i < mmp.getCount(); i++) {
-                    logMetacat.debug("Looping over MMP parts: " + i);
-                    BodyPart part = mmp.getBodyPart(i);
-                    String name = part.getFileName();
-                    logMetacat.debug("Part name is: " + name);
-                    logMetacat.debug("Part has class name: " + part.getClass().getName());
-                    if (name.equals("object")) {
-                        object = part.getInputStream();
-                        logMetacat.debug("Found object part, size is: " + part.getSize());
-                    } else if (name.equals("systemmetadata")) {
-                        sysmeta = part.getInputStream();
-                        logMetacat.debug("Found sysmeta part, size is: " + part.getSize());
-                    } else {
-                        throw new InvalidRequest(1000, "Request had malformed MIME part with name: " + name);
-                    }
-                }
-
                 // TODO: access control -- should be in CrudService et al. I think
                 //if (username != null && !username.equals("public")) {
                 if (username != null) {
@@ -679,6 +681,49 @@
                     logMetacat.debug("Unauthorized to create.");
                     throw new NotAuthorized(1000, "Permission denied for user " + username);
                 }
+            } else if (action.equals(FUNCTION_NAME_UPDATE)) { //handle updates
+                IdentifierManager im = IdentifierManager.getInstance();
+                CrudService cs = CrudService.getInstance();
+                Identifier obsoletedGuid = new Identifier();
+                Identifier id = new Identifier();
+                id.setValue(guid);
+                AuthToken token = null;
+                
+                //do some checks
+                if(params.get("obsoletedGuid") == null)
+                {
+                    throw new InvalidRequest(1202, "obsoletedGuid must be contained in the request parameters.");
+                }
+                //get the obsoletedGuid
+                String[] obsGuidS = params.get("obsoletedGuid");
+                obsoletedGuid.setValue(obsGuidS[0]);
+                
+                if (!im.identifierExists(obsoletedGuid.getValue())) 
+                {
+                    throw new InvalidRequest(1202, "The guid you are trying to update does not exist.");
+                }
+                
+                
+                logMetacat.debug("Commence update...");
+                
+                //get the systemmetadata
+                IBindingFactory bfact =
+                        BindingDirectory.getFactory(SystemMetadata.class);
+                    IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
+                    SystemMetadata m = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null);
+                
+                //do the update
+                try
+                {
+                    cs.setParamsFromRequest(request);
+                    Identifier rId = cs.update(token, id, object, obsoletedGuid, m);
+                    System.out.println("id returned from update " + rId.getValue());
+                }
+                catch(NotFound e)
+                {
+                    throw new InvalidRequest(1202, "The guid you are trying to update does not exist.");
+                }
+                
             } else {
                 throw new InvalidRequest(1000, "Operation must be create or update.");
             }
Index: src/edu/ucsb/nceas/metacat/dataone/CrudService.java
===================================================================
--- src/edu/ucsb/nceas/metacat/dataone/CrudService.java	(revision 5352)
+++ src/edu/ucsb/nceas/metacat/dataone/CrudService.java	(revision 5353)
@@ -232,6 +232,52 @@
         logMetacat.debug("Returning from CrudService.create()");
         return guid;
     }
+    
+    /**
+     * update an existing object with a new object.  Change the system metadata
+     * to reflect the changes and update it as well.
+     */
+    public Identifier update(AuthToken token, Identifier guid, 
+            InputStream object, Identifier obsoletedGuid, SystemMetadata sysmeta) 
+            throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, 
+            UnsupportedType, InsufficientResources, NotFound, InvalidSystemMetadata, 
+            NotImplemented {
+        try
+        {
+            SessionData sessionData = getSessionData(token);
+            
+            //find the old systemmetadata (sm.old) document id (the one linked to obsoletedGuid)
+            SystemMetadata sm = getSystemMetadata(token, obsoletedGuid);
+            //change sm.old's obsoletedBy field 
+            List l = sm.getObsoletedByList();
+            l.add(guid);
+            sm.setObsoletedByList(l);
+            //update sm.old
+            updateSystemMetadata(sm, sessionData);
+            
+            //change the obsoletes field of the new systemMetadata (sm.new) to point to the id of the old one
+            sysmeta.addObsolete(obsoletedGuid);
+            //insert sm.new
+            insertSystemMetadata(sysmeta, sessionData);
+            
+            boolean isScienceMetadata = isScienceMetadata(sysmeta);
+            if(isScienceMetadata)
+            {
+                //update the doc
+                updateDocument(object, obsoletedGuid, guid, sessionData);
+            }
+            else
+            {
+                //update a data file, not xml
+                insertDataObject(object, guid, sessionData);
+            }
+            return guid;
+        }
+        catch(Exception e)
+        {
+            throw new ServiceFailure(1030, "Error updating document in CrudService: " + e.getMessage());
+        }
+    }
 
     public Identifier delete(AuthToken token, Identifier guid)
             throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
@@ -370,43 +416,6 @@
         }                
     }
 
-    /**
-     * update an existing object with a new object.  Change the system metadata
-     * to reflect the changes and update it as well.
-     */
-    public Identifier update(AuthToken token, Identifier guid, 
-            InputStream object, Identifier obsoletedGuid, SystemMetadata sysmeta) 
-            throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, 
-            UnsupportedType, InsufficientResources, NotFound, InvalidSystemMetadata, 
-            NotImplemented {
-        try
-        {
-            SessionData sessionData = getSessionData(token);
-            
-            //find the old systemmetadata (sm.old) document id (the one linked to obsoletedGuid)
-            SystemMetadata sm = getSystemMetadata(token, obsoletedGuid);
-            //change sm.old's obsoletedBy field 
-            List l = sm.getObsoletedByList();
-            l.add(guid);
-            sm.setObsoletedByList(l);
-            //update sm.old
-            updateSystemMetadata(sm, sessionData);
-            
-            //change the obsoletes field of the new systemMetadata (sm.new) to point to the id of the old one
-            sysmeta.addObsolete(obsoletedGuid);
-            //insert sm.new
-            insertSystemMetadata(sysmeta, sessionData);
-            
-            //update the doc
-            updateDocument(object, obsoletedGuid, guid, sessionData);
-            return guid;
-        }
-        catch(Exception e)
-        {
-            throw new ServiceFailure(1030, "Error updating document in CrudService: " + e.getMessage());
-        }
-    }
-
     /*
      * Look up the information on the session using the token provided in
      * the AuthToken.  The Session should have all relevant user information.
@@ -488,6 +497,7 @@
                     // if the localId is not acceptable or other untoward things happen
                     try {
                         logMetacat.debug("Registering document...");
+                        System.out.println("inserting data object: localId: " + localId);
                         DocumentImpl.registerDocument(localId, "BIN", localId,
                                 username, groups);
                         logMetacat.debug("Registration step completed.");
