Project

General

Profile

« Previous | Next » 

Revision 5651

Added by berkley about 14 years ago

implemented describeObject

View differences:

src/edu/ucsb/nceas/metacat/restservice/RestServlet.java
88 88
        handler.handle(ResourceHandler.PUT);
89 89
    }
90 90

  
91
    /** Handle "PUT" method requests from HTTP clients */
92
    @Override
93
    protected void doHead(HttpServletRequest request,
94
            HttpServletResponse response) throws ServletException, IOException {
95
        System.out.println("HTTP Verb: HEAD");
96
        handler = new ResourceHandler(getServletContext(), request, response);
97
        handler.handle(ResourceHandler.HEAD);
98
    }
91 99
}
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
194 194
    public static final byte PUT = 3;
195 195
    /**HTTP Verb DELETE*/
196 196
    public static final byte DELETE = 4;
197
    /**HTTP Verb HEAD*/
198
    public static final byte HEAD = 5;
197 199

  
198 200
    /*
199 201
     * API Resources
......
332 334
            		} else if (httpVerb == DELETE) {
333 335
            			deleteObject(objectId);
334 336
            			status = true;
337
            		} else if (httpVerb == HEAD) {
338
            		    describeObject(objectId);
339
            		    status = true;
335 340
            		}
341
            		
336 342

  
337 343
            	} else if (resource.equals(RESOURCE_IDENTIFIER)) {
338 344

  
......
445 451
            	            it.setDetail_code("1430");
446 452
            	            serializeException(it, response.getOutputStream());
447 453
            	        }
454
            	        status = true;
448 455
            	    }
449 456
            	}
450 457
            	    
......
464 471
    }
465 472
    
466 473
    /**
474
     * MN_crud.describe()
475
     * http://mule1.dataone.org/ArchitectureDocs/mn_api_crud.html#MN_crud.describe
476
     * @param guid
477
     */
478
    private void describeObject(String guid)
479
    {
480
        Logger logMetacat = Logger.getLogger(ResourceHandler.class);
481
        OutputStream out = null;
482
        try
483
        {
484
            out = response.getOutputStream();
485
        }
486
        catch(Exception e)
487
        {
488
            logMetacat.error("Error getting output stream in ResourceHandler.describeObject: " + e.getMessage());
489
            return;
490
        }
491
        response.setStatus(200);
492
        response.setContentType("text/xml");
493
        AuthToken token = new AuthToken(sessionId);
494
        CrudService cs = CrudService.getInstance();
495
        Identifier id = new Identifier();
496
        id.setValue(guid);
497
        try
498
        {
499
            DescribeResponse dr = cs.describe(token, id);
500
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SZ");
501
            response.addHeader("guid", guid);
502
            response.addHeader("checksum", dr.getDataONE_Checksum().getValue());
503
            response.addHeader("content_length", dr.getContent_Length() + "");
504
            response.addHeader("last_modified", dateFormat.format(dr.getLast_Modified()));
505
            response.addHeader("format", dr.getDataONE_ObjectFormat().toString());
506
        }
507
        catch(InvalidRequest ir)
508
        {
509
            serializeException(ir, out);
510
        }
511
        catch(NotImplemented ni)
512
        {
513
            serializeException(ni, out);
514
        }
515
        catch(NotAuthorized na)
516
        {
517
            serializeException(na, out);
518
        }
519
        catch(ServiceFailure sf)
520
        {
521
            serializeException(sf, out);
522
        }
523
        catch(NotFound nf)
524
        {
525
            serializeException(nf, out);
526
        }
527
        catch(InvalidToken it)
528
        {
529
            serializeException(it, out);
530
        }
531
    }
532
    
533
    /**
467 534
     * get the logs from the CrudService based on passed params.  Available 
468 535
     * params are token, fromDate, toDate, event.  See 
469 536
     * http://mule1.dataone.org/ArchitectureDocs/mn_api_crud.html#MN_crud.getLogRecords

Also available in: Unified diff