Revision 6972
Added by ben leinfelder almost 13 years ago
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java | ||
---|---|---|
203 | 203 |
getObject(extra); |
204 | 204 |
status = true; |
205 | 205 |
} else if (httpVerb == POST) { |
206 |
putObject(extra, FUNCTION_NAME_INSERT); |
|
206 |
// part of the params, not the URL |
|
207 |
putObject(null, FUNCTION_NAME_INSERT); |
|
207 | 208 |
status = true; |
208 | 209 |
} else if (httpVerb == PUT) { |
209 | 210 |
putObject(extra, FUNCTION_NAME_UPDATE); |
... | ... | |
985 | 986 |
* @throws IllegalAccessException |
986 | 987 |
* @throws InstantiationException |
987 | 988 |
*/ |
988 |
protected void putObject(String pid, String action) throws ServiceFailure, InvalidRequest, JiBXException, InvalidToken, NotAuthorized, IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, NotFound, IOException, InstantiationException, IllegalAccessException { |
|
989 |
logMetacat.debug("putObject with pid " + pid); |
|
990 |
logMetacat.debug("Entering putObject: " + pid + "/" + action); |
|
991 |
|
|
992 |
response.setStatus(200); |
|
993 |
response.setContentType("text/xml"); |
|
994 |
OutputStream out = response.getOutputStream(); |
|
995 |
|
|
996 |
// Read the incoming data from its Mime Multipart encoding |
|
989 |
protected void putObject(String trailingPid, String action) throws ServiceFailure, InvalidRequest, JiBXException, InvalidToken, NotAuthorized, IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, NotFound, IOException, InstantiationException, IllegalAccessException { |
|
990 |
|
|
991 |
// Read the incoming data from its Mime Multipart encoding |
|
997 | 992 |
Map<String, File> files = collectMultipartFiles(); |
993 |
|
|
994 |
Identifier pid = null; |
|
995 |
if (trailingPid == null) { |
|
996 |
// get the encoded pid string from the body and make the object |
|
997 |
String pidContent = multipartparams.get("pid").get(0); |
|
998 |
pid = TypeMarshaller.unmarshalTypeFromStream(Identifier.class, IOUtils.toInputStream(pidContent, "UTF-8")); |
|
999 |
} else { |
|
1000 |
// use the pid included in the URL |
|
1001 |
pid = new Identifier(); |
|
1002 |
pid.setValue(trailingPid); |
|
1003 |
} |
|
1004 |
logMetacat.debug("putObject with pid " + pid.getValue()); |
|
1005 |
logMetacat.debug("Entering putObject: " + pid.getValue() + "/" + action); |
|
1006 |
|
|
998 | 1007 |
InputStream object = null; |
999 | 1008 |
InputStream sysmeta = null; |
1000 |
|
|
1001 | 1009 |
File smFile = files.get("sysmeta"); |
1002 | 1010 |
sysmeta = new FileInputStream(smFile); |
1003 | 1011 |
File objFile = files.get("object"); |
... | ... | |
1015 | 1023 |
|
1016 | 1024 |
} |
1017 | 1025 |
|
1026 |
response.setStatus(200); |
|
1027 |
response.setContentType("text/xml"); |
|
1028 |
OutputStream out = response.getOutputStream(); |
|
1029 |
|
|
1018 | 1030 |
if (action.equals(FUNCTION_NAME_INSERT)) { |
1019 | 1031 |
// handle inserts |
1020 | 1032 |
logMetacat.debug("Commence creation..."); |
1021 | 1033 |
SystemMetadata smd = TypeMarshaller.unmarshalTypeFromStream(SystemMetadata.class, sysmeta); |
1022 | 1034 |
|
1023 |
Identifier id = new Identifier(); |
|
1024 |
id.setValue(pid); |
|
1025 |
logMetacat.debug("creating object with pid " + pid); |
|
1026 |
Identifier rId = MNodeService.getInstance(request).create(session, id, object, smd); |
|
1035 |
logMetacat.debug("creating object with pid " + pid.getValue()); |
|
1036 |
Identifier rId = MNodeService.getInstance(request).create(session, pid, object, smd); |
|
1027 | 1037 |
TypeMarshaller.marshalTypeToOutputStream(rId, out); |
1028 | 1038 |
|
1029 | 1039 |
} else if (action.equals(FUNCTION_NAME_UPDATE)) { |
1030 | 1040 |
// handle updates |
1031 | 1041 |
|
1032 | 1042 |
// construct pids |
1033 |
Identifier newPid = new Identifier();
|
|
1043 |
Identifier newPid = null;
|
|
1034 | 1044 |
try { |
1035 | 1045 |
String newPidString = multipartparams.get("newPid").get(0); |
1036 |
newPid.setValue(newPidString);
|
|
1046 |
newPid = TypeMarshaller.unmarshalTypeFromStream(Identifier.class, IOUtils.toInputStream(newPidString, "UTF-8"));
|
|
1037 | 1047 |
} catch (Exception e) { |
1038 |
logMetacat.warn("newPid not given");
|
|
1048 |
logMetacat.error("Could not get newPid from request");
|
|
1039 | 1049 |
} |
1040 |
|
|
1041 |
Identifier obsoletedPid = new Identifier(); |
|
1042 |
obsoletedPid.setValue(pid); |
|
1043 |
|
|
1044 | 1050 |
logMetacat.debug("Commence update..."); |
1045 | 1051 |
|
1046 | 1052 |
// get the systemmetadata object |
1047 | 1053 |
SystemMetadata smd = TypeMarshaller.unmarshalTypeFromStream(SystemMetadata.class, sysmeta); |
1048 | 1054 |
|
1049 |
Identifier rId = MNodeService.getInstance(request).update(session, obsoletedPid, object, newPid, smd);
|
|
1055 |
Identifier rId = MNodeService.getInstance(request).update(session, pid, object, newPid, smd);
|
|
1050 | 1056 |
TypeMarshaller.marshalTypeToOutputStream(rId, out); |
1051 | 1057 |
} else { |
1052 | 1058 |
throw new InvalidRequest("1000", "Operation must be create or update."); |
1053 | 1059 |
} |
1054 |
|
|
1055 |
|
|
1060 |
|
|
1056 | 1061 |
} |
1057 | 1062 |
|
1058 | 1063 |
/** |
src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java | ||
---|---|---|
543 | 543 |
return systemMetadata; |
544 | 544 |
} |
545 | 545 |
|
546 |
/** |
|
547 |
* Process the MMP request that includes files for each param |
|
548 |
* @return map of param key and the tem pfile that contains the encoded information |
|
549 |
* @throws ServiceFailure |
|
550 |
* @throws InvalidRequest |
|
551 |
*/ |
|
546 | 552 |
protected Map<String, File> collectMultipartFiles() |
547 | 553 |
throws ServiceFailure, InvalidRequest { |
548 | 554 |
|
549 | 555 |
// Read the incoming data from its Mime Multipart encoding |
550 | 556 |
logMetacat.debug("Disassembling MIME multipart form"); |
551 |
InputStream object = null; |
|
552 |
InputStream sysmeta = null; |
|
553 | 557 |
|
554 |
|
|
555 | 558 |
// handle MMP inputs |
556 | 559 |
File tmpDir = getTempDirectory(); |
557 | 560 |
logMetacat.debug("temp dir: " + tmpDir.getAbsolutePath()); |
... | ... | |
567 | 570 |
logMetacat.debug("resolved multipart request"); |
568 | 571 |
Map<String, File> files = mr.getMultipartFiles(); |
569 | 572 |
if (files == null) { |
570 |
throw new ServiceFailure("1202", "create/update must have multipart files with names 'object' and 'sysmeta'");
|
|
573 |
throw new ServiceFailure("1202", "no multipart files found");
|
|
571 | 574 |
} |
572 | 575 |
logMetacat.debug("got multipart files"); |
573 | 576 |
|
574 | 577 |
if (files.keySet() == null) { |
575 | 578 |
logMetacat.error("No file keys in MMP request."); |
576 |
throw new ServiceFailure("1202", "No file keys found in MMP. " + |
|
577 |
"create/update must have multipart files with names 'object' and 'sysmeta'"); |
|
579 |
throw new ServiceFailure("1202", "No file keys found in MMP."); |
|
578 | 580 |
} |
579 | 581 |
|
580 | 582 |
// for logging purposes, dump out the key-value pairs that constitute the request |
581 | 583 |
// 3 types exist: request params, multipart params, and multipart files |
582 |
Iterator it = files.keySet().iterator(); |
|
583 |
logMetacat.debug("iterating through files"); |
|
584 |
while (it.hasNext()) { |
|
585 |
String key = (String)it.next(); |
|
586 |
logMetacat.debug("files key: " + key); |
|
587 |
logMetacat.debug("files value: " + files.get(key)); |
|
584 |
if (logMetacat.isDebugEnabled()) { |
|
585 |
Iterator<String> it = files.keySet().iterator(); |
|
586 |
logMetacat.debug("iterating through files"); |
|
587 |
while (it.hasNext()) { |
|
588 |
String key = it.next(); |
|
589 |
logMetacat.debug("files key: " + key); |
|
590 |
logMetacat.debug("files value: " + files.get(key)); |
|
591 |
} |
|
592 |
|
|
593 |
multipartparams = mr.getMultipartParameters(); |
|
594 |
it = multipartparams.keySet().iterator(); |
|
595 |
logMetacat.debug("iterating through multipartparams"); |
|
596 |
while (it.hasNext()) { |
|
597 |
String key = (String)it.next(); |
|
598 |
logMetacat.debug("multipartparams key: " + key); |
|
599 |
logMetacat.debug("multipartparams value: " + multipartparams.get(key)); |
|
600 |
} |
|
601 |
|
|
602 |
it = params.keySet().iterator(); |
|
603 |
logMetacat.debug("iterating through params"); |
|
604 |
while (it.hasNext()) { |
|
605 |
String key = (String)it.next(); |
|
606 |
logMetacat.debug("param key: " + key); |
|
607 |
logMetacat.debug("param value: " + params.get(key)); |
|
608 |
} |
|
609 |
logMetacat.debug("done iterating the request..."); |
|
588 | 610 |
} |
589 | 611 |
|
590 |
multipartparams = mr.getMultipartParameters(); |
|
591 |
it = multipartparams.keySet().iterator(); |
|
592 |
logMetacat.debug("iterating through multipartparams"); |
|
593 |
while (it.hasNext()) { |
|
594 |
String key = (String)it.next(); |
|
595 |
logMetacat.debug("multipartparams key: " + key); |
|
596 |
logMetacat.debug("multipartparams value: " + multipartparams.get(key)); |
|
597 |
} |
|
598 |
|
|
599 |
it = params.keySet().iterator(); |
|
600 |
logMetacat.debug("iterating through params"); |
|
601 |
while (it.hasNext()) { |
|
602 |
String key = (String)it.next(); |
|
603 |
logMetacat.debug("param key: " + key); |
|
604 |
logMetacat.debug("param value: " + params.get(key)); |
|
605 |
} |
|
606 |
logMetacat.debug("done iterating the request..."); |
|
607 |
|
|
608 |
File smFile = files.get("sysmeta"); |
|
609 |
if (smFile == null) { |
|
610 |
throw new InvalidRequest("1102", "Missing the required file-part 'sysmeta' from the multipart request."); |
|
611 |
} |
|
612 |
logMetacat.debug("smFile: " + smFile.getAbsolutePath()); |
|
613 |
File objFile = files.get("object"); |
|
614 |
if (objFile == null) { |
|
615 |
throw new InvalidRequest("1102", "Missing the required file-part 'object' from the multipart request."); |
|
616 |
} |
|
617 |
logMetacat.debug("objectfile: " + objFile.getAbsolutePath()); |
|
618 |
|
|
619 | 612 |
return files; |
620 | 613 |
} |
621 | 614 |
|
Also available in: Unified diff
remove {pid} from POST URL on MN.create()
https://redmine.dataone.org/issues/2284