Project

General

Profile

« Previous | Next » 

Revision 6045

Added by rnahf about 13 years ago

improved multipart handling (improved logging messages, code, and error checking). Added exception classname to error output when the generic Exception is thrown. Added error check for cases of null value for file parts 'sysmeta' and 'object.'

View differences:

src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
600 600
                printError("Incorrect resource!", response);
601 601
            }
602 602
        } catch (Exception e) {
603
            logMetacat.error(e.getMessage());
604
            System.out.println("Error in ResourceHandler.handle(): " + e.getMessage());
603
            logMetacat.error(e.getClass() + ": " + e.getMessage());
604
            System.out.println("Error in ResourceHandler.handle(): " + e.getClass() + ": " + e.getMessage());
605 605
            e.printStackTrace();
606 606
        }
607 607
    }
......
846 846
        }
847 847
        catch(Exception e)
848 848
        {
849
            logMetacat.error("Error getting output stream in ResourceHandler.describeObject: " + e.getMessage());
849
            logMetacat.error("Error getting output stream in ResourceHandler.describeObject: " + e.getClass() + ": " + e.getMessage());
850 850
            return;
851 851
        }
852 852
        response.setStatus(200);
......
937 937
        }
938 938
        catch(Exception e)
939 939
        {
940
            String msg = "Could not get logs from CrudService: " + e.getMessage();
940
            String msg = "Could not get logs from CrudService: " + e.getClass() + ": " + e.getMessage();
941 941
            response.setStatus(500);
942 942
            ServiceFailure sf = new ServiceFailure("1490", msg);
943 943
            logMetacat.error(msg);
......
1019 1019
        catch(Exception e)
1020 1020
        {
1021 1021
            e.printStackTrace();
1022
            throw new Exception("Could not load the session data: " + e.getMessage());
1022
            throw new Exception("Could not load the session data: " + e.getClass() + ": " + e.getMessage());
1023 1023
        }
1024 1024
    }
1025 1025
    
......
1120 1120
            response.setStatus(500);
1121 1121
            out.println("<?xml version=\"1.0\"?>");
1122 1122
            out.println("<error>");
1123
            out.println(e.getMessage());
1123
            out.println(e.getClass() + ": " + e.getMessage());
1124 1124
            out.println("</error>");
1125 1125
        }
1126 1126

  
......
1220 1220
                    System.out.println("Error with Crud.get().  " +
1221 1221
                            "If this is an 'Exception producing data' error, " +
1222 1222
                            "go to CrudService.get() for better debugging.  " +
1223
                            "Here's the error: " + e.getMessage());
1223
                            "Here's the error: " + e.getClass() + ": " + e.getMessage());
1224 1224
                    e.printStackTrace();
1225 1225
                    ServiceFailure sf = new ServiceFailure("1030", 
1226
                            "IO Error in ResourceHandler.getObject: " + e.getMessage());
1226
                            "IO Error in ResourceHandler.getObject: " + e.getClass() + ": " + e.getMessage());
1227 1227
                    serializeException(sf, out); 
1228 1228
                }
1229 1229
            }
......
1390 1390
        } catch (IOException e) {
1391 1391
            response.setStatus(500);
1392 1392
            ServiceFailure sf = new ServiceFailure("1030", 
1393
                    "Error in ResourceHandler.getSystemMetadataObject: " + e.getMessage());
1393
                    "IO Error in ResourceHandler.getSystemMetadataObject: " + e.getMessage());
1394 1394
            serializeException(sf, out);
1395 1395
        } finally {
1396 1396
            IOUtils.closeQuietly(out);
......
1619 1619
            logMetacat.debug("Disassembling MIME multipart form");
1620 1620
            InputStream object = null;
1621 1621
            InputStream sysmeta = null;
1622
            Map<String, List<String>> mutlipartparams;
1622
            Map<String, List<String>> multipartparams;
1623 1623
            
1624 1624
            try
1625 1625
            {
......
1650 1650
                    throw new ServiceFailure("1202", "No file keys found in MMP.  " +
1651 1651
                            "create/update must have multipart files with names 'object' and 'sysmeta'");
1652 1652
                }
1653
                Iterator multipartkeys = files.keySet().iterator();
1654
                System.out.println("iterating through multipart files: " + multipartkeys);
1655
                while(multipartkeys.hasNext())
1653

  
1654
		// for logging purposes, dump out the key-value pairs that constitute the request
1655
		// 3 types exist: request params, multipart params, and multipart files
1656
                Iterator it = files.keySet().iterator();
1657
                System.out.println("iterating through request parts: " + it);
1658
                while(it.hasNext())
1656 1659
                {
1657
                    String key = (String)multipartkeys.next();
1660
                    String key = (String)it.next();
1658 1661
                    System.out.println("files key: " + key);
1659 1662
                    System.out.println("files value: " + files.get(key));
1660 1663
                }
1661 1664
                
1662
                mutlipartparams = mr.getMultipartParameters();
1663
                multipartkeys = mutlipartparams.keySet().iterator();
1664
                while(multipartkeys.hasNext())
1665
                multipartparams = mr.getMultipartParameters();
1666
                it = multipartparams.keySet().iterator();
1667
                while(it.hasNext())
1665 1668
                {
1666
                    String key = (String)multipartkeys.next();
1667
                    System.out.println("mutlipartparams key: " + key);
1668
                    System.out.println("mutlipartparams value: " + mutlipartparams.get(key));
1669
                    String key = (String)it.next();
1670
                    System.out.println("multipartparams key: " + key);
1671
                    System.out.println("multipartparams value: " + multipartparams.get(key));
1669 1672
                }
1670 1673
                
1671
                Iterator keys = params.keySet().iterator();
1672
                while(keys.hasNext())
1674
                it = params.keySet().iterator();
1675
                while(it.hasNext())
1673 1676
                {
1674
                    String key = (String)keys.next();
1677
                    String key = (String)it.next();
1675 1678
                    System.out.println("param key: " + key);
1676 1679
                    System.out.println("param value: " + params.get(key));
1677 1680
                }
1678
                
1681
		System.out.println("done iterating the request...");
1682

  
1679 1683
                File smFile = files.get("sysmeta");
1684
		if (smFile == null) 
1685
		    throw new InvalidRequest("1102", "Missing the required file-part 'sysmeta' from the multipart request.");
1680 1686
                System.out.println("smFile: " + smFile.getAbsolutePath());
1681 1687
                sysmeta = new FileInputStream(smFile);
1682 1688
                File objFile = files.get("object");
1689
		if (objFile == null) 
1690
		    throw new InvalidRequest("1102", "Missing the required file-part 'object' from the multipart request.");
1691

  
1683 1692
                System.out.println("objectfile: " + objFile.getAbsolutePath());
1684 1693
                object = new FileInputStream(objFile);
1685 1694
                
......
1702 1711
            }
1703 1712
            catch(Exception e)
1704 1713
            {
1705
                throw new ServiceFailure("1202", "Error handling MMP upload: " + e.getMessage());
1714
                throw new ServiceFailure("1202", "Error handling MMP upload: " + e.getClass() + ": " + e.getMessage());
1706 1715
            }
1707 1716
            
1708 1717
            if ( action.equals(FUNCTION_NAME_INSERT)) { //handle inserts
......
1737 1746
                AuthToken token = new AuthToken(sessionId);
1738 1747
                
1739 1748
                //do some checks
1740
                if(mutlipartparams.get("obsoletedGuid") == null)
1749
                if(multipartparams.get("obsoletedGuid") == null)
1741 1750
                {
1742 1751
                    throw new InvalidRequest("1202", "obsoletedGuid must be contained in the request parameters.");
1743 1752
                }
1744 1753
                //get the obsoletedGuid
1745
                String obsGuidS = mutlipartparams.get("obsoletedGuid").get(0);
1754
                String obsGuidS = multipartparams.get("obsoletedGuid").get(0);
1746 1755
                obsoletedGuid.setValue(obsGuidS);
1747 1756
                
1748 1757
                if (!im.identifierExists(obsoletedGuid.getValue())) 
......
1906 1915
        catch(Exception e)
1907 1916
        {
1908 1917
            response.setStatus(500);
1909
            printError("Error setting access in ResourceHandler: " + e.getMessage(), response);
1918
            printError("Error setting access in ResourceHandler: " + e.getClass() + ": " + e.getMessage(), response);
1910 1919
            throw e;
1911 1920
        }
1912 1921
    }

Also available in: Unified diff