Project

General

Profile

« Previous | Next » 

Revision 6280

allow service implementation method to throw exception when guid parameter is null

View differences:

src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
428 428
     */
429 429
    protected void getObject(String guid) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, InvalidRequest, NotImplemented, IOException {
430 430

  
431
        Identifier id = new Identifier();
432
        id.setValue(guid);
433
            
434
        SystemMetadata sm = CNodeService.getInstance().getSystemMetadata(session, id);
431 435
        
432
        if (guid != null) { //get a specific document                
433
            Identifier id = new Identifier();
434
            id.setValue(guid);
435
                
436
            SystemMetadata sm = CNodeService.getInstance().getSystemMetadata(session, id);
437
            
438
            //set the content type
439
            if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
440
            		ObjectFormatCache.getInstance().getFormat("text/csv").getFmtid().getValue()))
441
            {
442
                response.setContentType("text/csv");
443
                response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".csv");
444
            }
445
            else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
446
            		ObjectFormatCache.getInstance().getFormat("text/plain").getFmtid().getValue()))
447
            {
448
                response.setContentType("text/plain");
449
                response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".txt");
450
            } 
451
            else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
452
            		ObjectFormatCache.getInstance().getFormat("application/octet-stream").getFmtid().getValue()))
453
            {
454
                response.setContentType("application/octet-stream");
455
            }
456
            else
457
            {
458
                response.setContentType("text/xml");
459
                response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".xml");
460
            }
461
            
462
            InputStream data = CNodeService.getInstance().get(session, id);
463
            
464
            OutputStream out = response.getOutputStream();
465
            response.setStatus(200);
466
            IOUtils.copyLarge(data, out);
467

  
436
        //set the content type
437
        if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
438
        		ObjectFormatCache.getInstance().getFormat("text/csv").getFmtid().getValue()))
439
        {
440
            response.setContentType("text/csv");
441
            response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".csv");
468 442
        }
443
        else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
444
        		ObjectFormatCache.getInstance().getFormat("text/plain").getFmtid().getValue()))
445
        {
446
            response.setContentType("text/plain");
447
            response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".txt");
448
        } 
449
        else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
450
        		ObjectFormatCache.getInstance().getFormat("application/octet-stream").getFmtid().getValue()))
451
        {
452
            response.setContentType("application/octet-stream");
453
        }
454
        else
455
        {
456
            response.setContentType("text/xml");
457
            response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".xml");
458
        }
459
        
460
        InputStream data = CNodeService.getInstance().get(session, id);
461
        
462
        OutputStream out = response.getOutputStream();
463
        response.setStatus(200);
464
        IOUtils.copyLarge(data, out);
469 465
            
470 466
    }
471 467
    

Also available in: Unified diff