Project

General

Profile

« Previous | Next » 

Revision 5638

Added by berkley over 13 years ago

working on integrating streaming mmp into resourceHandler

View differences:

test/edu/ucsb/nceas/metacat/restservice/ResourceHandlerTest.java
66 66
            File f = new File("test/testMimeInput.txt");
67 67
            FileInputStream fis = new FileInputStream(f);
68 68
            ResourceHandler rh = new ResourceHandler(null, null, null);
69
            //Hashtable h = rh.processMMP(fis);
70
            Vector<File> v = rh.processMMP(fis);
71
            FileInputStream smFis = new FileInputStream(v.elementAt(0));
72
            FileInputStream objFis = new FileInputStream(v.elementAt(1));
69
            Hashtable<String, File> h = rh.processMMP(fis);
70
            FileInputStream smFis = new FileInputStream(h.get("sysmeta"));
71
            FileInputStream objFis = new FileInputStream(h.get("object"));
73 72
            String sm = IOUtils.toString(smFis);
74 73
            String obj = IOUtils.toString(objFis);
75 74
            System.out.println("sm: " + sm);
76 75
            System.out.println("obj: " + obj);
76
            assertTrue(obj.indexOf("<test>") != -1);
77
            assertTrue(sm.indexOf("<d1:systemMetadata") != -1);
78
            assertTrue(sm.indexOf("</d1:systemMetadata>") != -1);
79
            assertTrue(obj.indexOf("</test>") != -1);
77 80
        }
78 81
        catch(Exception e)
79 82
        {
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
1066 1066
     * write the parts of an MMP to files.  The first file in the vector is
1067 1067
     * a system metadata file, the 2nd is the object.
1068 1068
     */
1069
    private static Vector<File> writeMMPPartsToFiles(InputStream is)
1069
    private static Hashtable<String, File> writeMMPPartsToFiles(InputStream is)
1070 1070
        throws IOException
1071 1071
    {
1072 1072
        System.out.println("producing data");
......
1116 1116
            String searchString;
1117 1117
            if(!searchForBoundary)
1118 1118
            {
1119
                if(ssi == searchStrings.length)
1119
                if(ssi >= searchStrings.length)
1120 1120
                {
1121 1121
                    break;
1122 1122
                }
......
1141 1141
            
1142 1142
            int[] result = StreamUtil.lookForMatch(searchString, s);
1143 1143
            System.out.println("got result from StreamUtil: " + result[0] + ", " + result[1]);
1144
            if(result[0] != -1 && result[1] == searchString.length())
1144
            if(result[0] == -1 && result[1] == -1)
1145
            { //same as else statement
1146
                if(searchForBoundary)
1147
                {
1148
                    //we're in between the start and end of a section 
1149
                    //so just write this to the stream
1150
                    System.out.println("XXXX 4 writing string: " + s + "\nXXXX");
1151
                    //dataSink.write(s.getBytes());
1152
                    if(writeSM)
1153
                    {
1154
                        smFos.write(s.getBytes());
1155
                    }
1156
                    else
1157
                    {
1158
                        objFos.write(s.getBytes());
1159
                    }
1160
                }
1161
            }
1162
            else if(result[0] != -1 && result[1] == searchString.length())
1145 1163
            { //we have the whole search string in this group of bytes
1146 1164
                System.out.println("1");
1147 1165
                if(searchForBoundary)
......
1284 1302
            }
1285 1303
        }
1286 1304
        
1287
        Vector<File> v = new Vector<File>();
1305
        Hashtable<String, File> h = new Hashtable<String, File>();
1288 1306
        objFos.flush();
1289 1307
        smFos.flush();
1290
        v.add(smFile);
1291
        v.add(objFile);
1292
        return v;
1308
        h.put("sysmeta", smFile);
1309
        h.put("object", objFile);
1310
        return h;
1293 1311
    }
1294 1312
    
1295 1313
    /**
1296 1314
     * return a vector where the first element is a string that represents the system
1297 1315
     * metadata and the 2nd element is an InputStream that is the object
1298 1316
     */
1299
    protected Vector<File> processMMP(final InputStream is)
1317
    protected Hashtable<String, File> processMMP(final InputStream is)
1300 1318
      throws IOException
1301 1319
    {
1302
     /*   final InputStreamFromOutputStream<String> objectStream = 
1303
            new InputStreamFromOutputStream<String>() 
1304
        {
1305
            @Override
1306
            public String produce(final OutputStream dataSink) throws Exception 
1307
            {
1308
                
1309
                return produceInputStream(dataSink, is);
1310
            }
1311
        };
1312
        
1313
        return objectStream;*/
1314 1320
        return writeMMPPartsToFiles(is);
1315 1321
    }
1316 1322
    
......
1336 1342
            logMetacat.debug("Disassembling MIME multipart form");
1337 1343
            InputStream object = null;
1338 1344
            InputStream sysmeta = null;
1345
            Hashtable<String, File> parts;
1339 1346
            
1340
            Hashtable parts/* = processMMP(request.getInputStream());*/ = new Hashtable();
1341
            object = (InputStream)parts.get("object");
1347
            try
1348
            {
1349
                parts = processMMP(request.getInputStream());
1350
                object = new FileInputStream(parts.get("object"));
1351
                sysmeta = new FileInputStream(parts.get("sysmeta"));
1352
            }
1353
            catch(IOException ioe)
1354
            {
1355
                throw new ServiceFailure("1202", 
1356
                        "IOException when processing Mime Multipart: " + ioe.getMessage());
1357
            }
1342 1358
            
1343
            sysmeta = (InputStream)parts.get("systemmetadata");
1344
            
1345 1359
            if ( action.equals(FUNCTION_NAME_INSERT)) { //handle inserts
1346 1360

  
1347 1361
                // Check if the objectId exists
......
1408 1422
            } else {
1409 1423
                throw new InvalidRequest("1000", "Operation must be create or update.");
1410 1424
            }
1425
            
1426
            //clean up the MMP files
1427
            //parts.get("sysmeta").delete();
1428
            //parts.get("object").delete();
1411 1429
        } catch (NotAuthorized e) {
1412 1430
            response.setStatus(500);
1413 1431
            serializeException(e, out);

Also available in: Unified diff