206 |
206 |
private static final String RESOURCE_IDENTIFIER = "identifier";
|
207 |
207 |
private static final String RESOURCE_LOG = "log";
|
208 |
208 |
private static final String RESOURCE_CHECKSUM = "checksum";
|
|
209 |
private static final String RESOURCE_BASE_URL = "d1";
|
209 |
210 |
|
210 |
211 |
/*
|
211 |
212 |
* API Functions used as URL parameters
|
... | ... | |
253 |
254 |
logMetacat = Logger.getLogger(ResourceHandler.class);
|
254 |
255 |
try {
|
255 |
256 |
String resource = request.getServletPath();
|
256 |
|
//substring off the /d1/
|
257 |
|
resource = resource.substring(resource.indexOf("d1/") + 3, resource.length());
|
258 |
|
resource = resource.trim();
|
|
257 |
if(resource.endsWith("d1/") || resource.endsWith("d1"))
|
|
258 |
{
|
|
259 |
resource = RESOURCE_BASE_URL;
|
|
260 |
}
|
|
261 |
else
|
|
262 |
{
|
|
263 |
//substring off the /d1/
|
|
264 |
resource = resource.substring(resource.indexOf("d1/") + 3, resource.length());
|
|
265 |
resource = resource.trim();
|
|
266 |
}
|
|
267 |
|
259 |
268 |
String verb = "";
|
260 |
269 |
|
261 |
270 |
System.out.println("handling verb " + httpVerb + " request with resource '" + resource + "'");
|
... | ... | |
271 |
280 |
Timer timer = new Timer();
|
272 |
281 |
handler = new MetacatHandler(timer);
|
273 |
282 |
|
274 |
|
if (resource.equals(RESOURCE_SESSION) &&
|
|
283 |
if(resource.equals(RESOURCE_BASE_URL)) {
|
|
284 |
//node registry response
|
|
285 |
System.out.println("Using resource 'd1' (node registry response)");
|
|
286 |
createNodeResponse();
|
|
287 |
status = true;
|
|
288 |
|
|
289 |
} else if (resource.equals(RESOURCE_SESSION) &&
|
275 |
290 |
httpVerb == POST &&
|
276 |
291 |
params.get(FUNCTION_KEYWORD) != null) {
|
277 |
292 |
System.out.println("Using resource 'session'");
|
... | ... | |
478 |
493 |
}
|
479 |
494 |
|
480 |
495 |
/**
|
|
496 |
* create the root node registry response.
|
|
497 |
* @throws JiBXException
|
|
498 |
* @throws IOException
|
|
499 |
*/
|
|
500 |
private void createNodeResponse()
|
|
501 |
throws JiBXException, IOException
|
|
502 |
{
|
|
503 |
NodeList nl = new NodeList();
|
|
504 |
Node n = new Node();
|
|
505 |
NodeReference nr = new NodeReference();
|
|
506 |
nr.setValue(request.getRequestURL().toString());
|
|
507 |
n.setIdentifier(nr);
|
|
508 |
n.setBaseURL(request.getRequestURL().toString());
|
|
509 |
n.setDescription("Metacat DataONE Node");
|
|
510 |
n.setName("Metacat");
|
|
511 |
n.setType(NodeType.convert("mn"));
|
|
512 |
|
|
513 |
//create the services
|
|
514 |
Service mnCrud03 = new Service();
|
|
515 |
mnCrud03.setName("Metacat MN_Crud Services Version 0.3");
|
|
516 |
mnCrud03.setVersion("0.3");
|
|
517 |
|
|
518 |
Service mnCrud04 = new Service();
|
|
519 |
mnCrud04.setName("Metacat MN_Crud Services Version 0.4");
|
|
520 |
mnCrud04.setVersion("0.4");
|
|
521 |
|
|
522 |
Service mnCrud09 = new Service();
|
|
523 |
mnCrud09.setName("Metacat MN_Crud Services Version 0.9");
|
|
524 |
mnCrud09.setVersion("0.9");
|
|
525 |
|
|
526 |
Service mnReplication03 = new Service();
|
|
527 |
mnReplication03.setName("Metcat MN_Replication Version 0.3");
|
|
528 |
mnReplication03.setVersion("0.3");
|
|
529 |
|
|
530 |
Service mnHealth04 = new Service();
|
|
531 |
mnHealth04.setName("Metacat MN_Health Version 0.4");
|
|
532 |
mnHealth04.setVersion("0.4");
|
|
533 |
|
|
534 |
Service mnHealth06 = new Service();
|
|
535 |
mnHealth06.setName("Metacat MN_Health Version 0.6");
|
|
536 |
mnHealth06.setVersion("0.6");
|
|
537 |
|
|
538 |
Service mnAuthentication07 = new Service();
|
|
539 |
mnAuthentication07.setName("Metacat MN_Authentication Version 0.7");
|
|
540 |
mnAuthentication07.setVersion("0.7");
|
|
541 |
|
|
542 |
Service mnAuthorization07 = new Service();
|
|
543 |
mnAuthorization07.setName("Metacat MN_Authorization Version 0.7");
|
|
544 |
mnAuthorization07.setVersion("0.7");
|
|
545 |
|
|
546 |
//name, rest, implemented
|
|
547 |
mnCrud03.addMethod(getServiceMethod("MN_crud.get()", "/object/<guid>", true));
|
|
548 |
mnCrud03.addMethod(getServiceMethod("MN_crud.getSystemMetadata()", "/meta/<guid>", true));
|
|
549 |
mnCrud04.addMethod(getServiceMethod("MN_crud.create()", "/object/<guid>", true));
|
|
550 |
mnCrud04.addMethod(getServiceMethod("MN_crud.update()", "/object/<guid>", true));
|
|
551 |
mnCrud09.addMethod(getServiceMethod("MN_crud.delete()", "/object/<guid>", true));
|
|
552 |
mnCrud03.addMethod(getServiceMethod("MN_crud.describe()", "/object/<guid>", true));
|
|
553 |
mnCrud03.addMethod(getServiceMethod("MN_crud.getChecksum()", "/checksum/<guid>", true));
|
|
554 |
mnCrud03.addMethod(getServiceMethod("MN_crud.getLogRecords()", "/log", true));
|
|
555 |
mnReplication03.addMethod(getServiceMethod("MN_replication.listObjects()", "/object", true));
|
|
556 |
mnHealth04.addMethod(getServiceMethod("MN_health.ping()", "/health/ping", false));
|
|
557 |
mnHealth04.addMethod(getServiceMethod("MN_health.getObjectStatistics()", "/monitor/object/<guid>", false));
|
|
558 |
mnHealth06.addMethod(getServiceMethod("MN_health.getStatus()", "/health/status", false));
|
|
559 |
mnAuthentication07.addMethod(getServiceMethod("MN_authentication.login()", "/account/login", false));
|
|
560 |
mnAuthentication07.addMethod(getServiceMethod("MN_authentication.logout()", "/account/logout", false));
|
|
561 |
mnAuthorization07.addMethod(getServiceMethod("MN_authorization.isAuthorized()", "/isAuthorized/<guid>", false));
|
|
562 |
|
|
563 |
Services ss = new Services();
|
|
564 |
ss.addService(mnCrud03);
|
|
565 |
ss.addService(mnCrud04);
|
|
566 |
ss.addService(mnCrud09);
|
|
567 |
ss.addService(mnReplication03);
|
|
568 |
ss.addService(mnHealth04);
|
|
569 |
ss.addService(mnHealth06);
|
|
570 |
ss.addService(mnAuthentication07);
|
|
571 |
ss.addService(mnAuthorization07);
|
|
572 |
n.setServices(ss);
|
|
573 |
nl.addNode(n);
|
|
574 |
serializeServiceType(NodeList.class, nl, response.getOutputStream());
|
|
575 |
}
|
|
576 |
|
|
577 |
/**
|
481 |
578 |
* MN_crud.describe()
|
482 |
579 |
* http://mule1.dataone.org/ArchitectureDocs/mn_api_crud.html#MN_crud.describe
|
483 |
580 |
* @param guid
|
... | ... | |
1720 |
1817 |
}
|
1721 |
1818 |
}
|
1722 |
1819 |
|
|
1820 |
/**
|
|
1821 |
* serialize a D1 exception using jibx
|
|
1822 |
* @param e
|
|
1823 |
* @param out
|
|
1824 |
*/
|
1723 |
1825 |
private void serializeException(BaseException e, OutputStream out) {
|
1724 |
1826 |
// TODO: Use content negotiation to determine which return format to use
|
1725 |
1827 |
response.setContentType("text/xml");
|
... | ... | |
1735 |
1837 |
+ e1.getMessage());
|
1736 |
1838 |
}
|
1737 |
1839 |
}
|
|
1840 |
|
|
1841 |
/**
|
|
1842 |
* create a new ServiceMethod declaration
|
|
1843 |
* @param name
|
|
1844 |
* @param rest
|
|
1845 |
* @param implemented
|
|
1846 |
* @return
|
|
1847 |
*/
|
|
1848 |
private ServiceMethod getServiceMethod(String name, String rest, boolean implemented)
|
|
1849 |
{
|
|
1850 |
ServiceMethod sm = new ServiceMethod();
|
|
1851 |
sm.setImplemented(implemented);
|
|
1852 |
sm.setName(name);
|
|
1853 |
sm.setRest(rest);
|
|
1854 |
return sm;
|
|
1855 |
}
|
1738 |
1856 |
|
1739 |
1857 |
}
|
added the root registry node response