978 |
978 |
return bais;
|
979 |
979 |
}
|
980 |
980 |
|
|
981 |
/**
|
|
982 |
* process a mime multipart message
|
|
983 |
* @param is
|
|
984 |
* @return
|
|
985 |
*/
|
|
986 |
private Hashtable processMMP(InputStream is)
|
|
987 |
throws IOException
|
|
988 |
{
|
|
989 |
//SORTAHACK: Since mmp seems to have a bug where large object parts get truncated,
|
|
990 |
//parse the stream here. This has the disavantage of putting the
|
|
991 |
//stream into memory.
|
|
992 |
InputStream object = null;
|
|
993 |
InputStream sysmeta = null;
|
|
994 |
String s = streamToString(is);
|
|
995 |
//System.out.println("s: " + s);
|
|
996 |
//figure out what the boundary marker is
|
|
997 |
String searchString = "boundary=";
|
|
998 |
int searchStringIndex = s.indexOf(searchString);
|
|
999 |
String boundary = s.substring(searchStringIndex + searchString.length() + 1,
|
|
1000 |
s.indexOf("\"", searchStringIndex + searchString.length() + 1));
|
|
1001 |
boundary = "--" + boundary;
|
|
1002 |
//System.out.println("boundary is " + boundary);
|
|
1003 |
|
|
1004 |
//find the system metadata
|
|
1005 |
searchString = "Content-Disposition: attachment; filename=systemmetadata";
|
|
1006 |
searchStringIndex = s.indexOf(searchString);
|
|
1007 |
sysmeta = new ByteArrayInputStream(
|
|
1008 |
s.substring(searchStringIndex +
|
|
1009 |
searchString.length(),
|
|
1010 |
s.indexOf(boundary, searchStringIndex)).trim().getBytes());
|
|
1011 |
|
|
1012 |
//find the object
|
|
1013 |
searchString = "Content-Disposition: attachment; filename=object";
|
|
1014 |
searchStringIndex = s.indexOf(searchString);
|
|
1015 |
object = new ByteArrayInputStream(
|
|
1016 |
s.substring(searchStringIndex +
|
|
1017 |
searchString.length(),
|
|
1018 |
s.indexOf(boundary, searchStringIndex)).trim().getBytes());
|
|
1019 |
|
|
1020 |
Hashtable h = new Hashtable();
|
|
1021 |
h.put("object", object);
|
|
1022 |
h.put("systemmetadata", sysmeta);
|
|
1023 |
return h;
|
|
1024 |
}
|
981 |
1025 |
|
|
1026 |
|
982 |
1027 |
/**
|
983 |
1028 |
* Earthgrid API > Put Service >Put Function : calls MetacatHandler > handleInsertOrUpdateAction
|
984 |
1029 |
*
|
... | ... | |
1001 |
1046 |
InputStream object = null;
|
1002 |
1047 |
InputStream sysmeta = null;
|
1003 |
1048 |
|
1004 |
|
//HACK: Since mmp seems to have a bug where large object parts get truncated,
|
1005 |
|
//parse the stream here. This has the disavantage of putting the
|
1006 |
|
//stream into memory.
|
1007 |
|
String s = streamToString(request.getInputStream());
|
1008 |
|
System.out.println("s: " + s);
|
1009 |
|
String searchString = "Content-Disposition: attachment; filename=systemmetadata";
|
1010 |
|
String endString = "------=_Part";
|
1011 |
|
int searchStringIndex = s.indexOf(searchString);
|
1012 |
|
sysmeta = new ByteArrayInputStream(
|
1013 |
|
s.substring(searchStringIndex +
|
1014 |
|
searchString.length(),
|
1015 |
|
s.indexOf(endString, searchStringIndex)).trim().getBytes());
|
|
1049 |
Hashtable parts = processMMP(request.getInputStream());
|
|
1050 |
object = (InputStream)parts.get("object");
|
|
1051 |
sysmeta = (InputStream)parts.get("systemmetadata");
|
1016 |
1052 |
|
1017 |
|
searchString = "Content-Disposition: attachment; filename=object";
|
1018 |
|
searchStringIndex = s.indexOf(searchString);
|
1019 |
|
object = new ByteArrayInputStream(
|
1020 |
|
s.substring(searchStringIndex +
|
1021 |
|
searchString.length(),
|
1022 |
|
s.indexOf(endString, searchStringIndex)).trim().getBytes());
|
1023 |
|
|
1024 |
|
/*
|
1025 |
|
//This code should work, however there seems to be a bug in part.getInputStream()
|
1026 |
|
//where it does not return the entire stream. Only about the first 6kB
|
1027 |
|
//are actually returned.
|
1028 |
|
MimeMultipart mmp = new MimeMultipart(new InputStreamDataSource("message", request.getInputStream()));
|
1029 |
|
logMetacat.debug("MMP created.");
|
1030 |
|
|
1031 |
|
//mmp.writeTo(System.out);
|
1032 |
|
for (int i = 0; i < mmp.getCount(); i++) {
|
1033 |
|
BodyPart part = mmp.getBodyPart(i);
|
1034 |
|
String name = part.getFileName();
|
1035 |
|
logMetacat.debug("Part name is: " + name);
|
1036 |
|
logMetacat.debug("Part has class name: " + part.getClass().getName());
|
1037 |
|
|
1038 |
|
if (name.equals("object")) {
|
1039 |
|
object = part.getInputStream();
|
1040 |
|
try
|
1041 |
|
{
|
1042 |
|
String s = streamToString(object);
|
1043 |
|
System.out.println("doc text: " + s);
|
1044 |
|
System.out.println("size of doc text is: " + s.getBytes().length);
|
1045 |
|
object = stringToStream(s);
|
1046 |
|
}
|
1047 |
|
catch(Exception e)
|
1048 |
|
{}
|
1049 |
|
System.out.println("Found object part, size is: " + part.getSize());
|
1050 |
|
} else if (name.equals("systemmetadata")) {
|
1051 |
|
sysmeta = part.getInputStream();
|
1052 |
|
try
|
1053 |
|
{
|
1054 |
|
String s = streamToString(sysmeta);
|
1055 |
|
System.out.println("system metadata part: " + s);
|
1056 |
|
sysmeta = stringToStream(s);
|
1057 |
|
}
|
1058 |
|
catch(Exception e){}
|
1059 |
|
System.out.println("system metadata part, size is " + part.getSize());
|
1060 |
|
logMetacat.debug("Found sysmeta part, size is: " + part.getSize());
|
1061 |
|
} else {
|
1062 |
|
throw new InvalidRequest("1000", "Request had malformed MIME part with name: " + name);
|
1063 |
|
}
|
1064 |
|
}*/
|
1065 |
|
|
1066 |
1053 |
if ( action.equals(FUNCTION_NAME_INSERT)) { //handle inserts
|
1067 |
1054 |
|
1068 |
1055 |
// Check if the objectId exists
|
fixed mime multipart problems so that roger can try to use the d1client