Project

General

Profile

« Previous | Next » 

Revision 5644

Added by berkley over 13 years ago

adding getChecksum method

View differences:

lib/web.xml.tomcat5
389 389
        <servlet-name>RestServlet</servlet-name>
390 390
        <url-pattern>/log/*</url-pattern>
391 391
    </servlet-mapping>
392
    
393
    <servlet-mapping>
394
        <servlet-name>RestServlet</servlet-name>
395
        <url-pattern>/checksum/*</url-pattern>
396
    </servlet-mapping>
392 397

  
393 398

  
394 399
 <!-- uncomment this if you want the admin servlet -->
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
203 203
    private static final String RESOURCE_SESSION = "session";
204 204
    private static final String RESOURCE_IDENTIFIER = "identifier";
205 205
    private static final String RESOURCE_LOG = "log";
206
    private static final String RESOURCE_CHECKSUM = "checksum";
206 207

  
207 208
    /*
208 209
     * API Functions used as URL parameters
......
380 381
            			status = true;
381 382
            		}
382 383

  
384
            	} else if(resource.equals(RESOURCE_CHECKSUM)) {
385
            	    //handle checksum requests
386
            	    System.out.println("Handling getChecksum request");
387
            	    if(httpVerb == GET)
388
            	    {
389
            	        String guid = null;
390
            	        String checksumAlgorithm = "MD5";
391
            	    
392
            	        try
393
            	        {
394
            	           guid = params.get("id")[0];
395
            	        }
396
            	        catch(Exception e)
397
            	        {
398
            	            throw new InvalidRequest("1402", "Incorrect parameters passed to getChecksum");
399
            	        }
400
            	        
401
            	        Identifier guidid = new Identifier();
402
            	        guidid.setValue(guid);
403
            	        AuthToken token = new AuthToken(sessionId);
404
            	        try
405
            	        {
406
            	            checksumAlgorithm = params.get("checksumAlgorithm")[0];
407
            	        }
408
            	        catch(Exception e)
409
            	        {
410
            	            //do nothing.  default to MD5
411
            	        }
412
            	        System.out.println("getting checksum for object " + guid +
413
            	                " with algorithm " + checksumAlgorithm);
414
            	        try
415
            	        {
416
            	            Checksum c = CrudService.getInstance().getChecksum(token, guidid, checksumAlgorithm);
417
            	            System.out.println("got checksum " + c.getValue());
418
            	            response.setStatus(200);
419
            	            System.out.println("serializing response");
420
            	            serializeServiceType(Checksum.class, c, response.getOutputStream());
421
            	            System.out.println("done serializing response.");
422
            	        }
423
            	        catch(NotAuthorized na)
424
            	        {
425
            	            na.setDetail_code("1400");
426
            	            serializeException(na, response.getOutputStream());
427
            	        }
428
            	        catch(NotFound nf)
429
            	        {
430
            	            nf.setDetail_code("1420");
431
            	            serializeException(nf, response.getOutputStream());
432
            	        }
433
            	        catch(InvalidRequest ir)
434
            	        {
435
            	            ir.setDetail_code("1402");
436
            	            serializeException(ir, response.getOutputStream());
437
            	        }
438
            	        catch(ServiceFailure sf)
439
            	        {
440
            	            sf.setDetail_code("1410");
441
            	            serializeException(sf, response.getOutputStream());
442
            	        }
443
            	        catch(InvalidToken it)
444
            	        {
445
            	            it.setDetail_code("1430");
446
            	            serializeException(it, response.getOutputStream());
447
            	        }
448
            	    }
383 449
            	}
384

  
450
            	    
385 451
            	if (!status)
386 452
            	{
387 453
            	    response.setStatus(400);
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
1019 1019
            NotAuthorized, NotFound, InvalidRequest, NotImplemented 
1020 1020
    {
1021 1021
        logCrud.info("getChecksum");
1022
        if(checksumAlgorithm == null)
1023
        {
1024
            checksumAlgorithm = "MD5";
1025
        }
1022 1026
        InputStream docStream = get(token, guid);
1023 1027
        String checksum;
1024 1028
        try

Also available in: Unified diff