Revision 6514
Added by ben leinfelder almost 13 years ago
D1ResourceHandler.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
import java.io.File; |
26 | 26 |
import java.io.FileInputStream; |
27 |
import java.io.FileNotFoundException; |
|
28 | 27 |
import java.io.IOException; |
29 | 28 |
import java.io.InputStream; |
30 | 29 |
import java.io.OutputStream; |
31 | 30 |
import java.io.PrintWriter; |
32 |
import java.text.DateFormat; |
|
33 |
import java.text.ParseException; |
|
34 |
import java.text.SimpleDateFormat; |
|
35 |
import java.util.Date; |
|
36 | 31 |
import java.util.Enumeration; |
37 | 32 |
import java.util.Hashtable; |
38 | 33 |
import java.util.Iterator; |
39 | 34 |
import java.util.List; |
40 | 35 |
import java.util.Map; |
41 |
import java.util.TimeZone; |
|
42 | 36 |
import java.util.Timer; |
43 | 37 |
|
44 | 38 |
import javax.servlet.ServletContext; |
45 | 39 |
import javax.servlet.http.HttpServletRequest; |
46 | 40 |
import javax.servlet.http.HttpServletResponse; |
41 |
import javax.xml.parsers.ParserConfigurationException; |
|
47 | 42 |
|
48 | 43 |
import org.apache.commons.fileupload.FileUploadException; |
49 | 44 |
import org.apache.commons.io.IOUtils; |
... | ... | |
54 | 49 |
import org.dataone.service.exceptions.BaseException; |
55 | 50 |
import org.dataone.service.exceptions.InvalidRequest; |
56 | 51 |
import org.dataone.service.exceptions.ServiceFailure; |
52 |
import org.dataone.service.types.v1.AccessPolicy; |
|
57 | 53 |
import org.dataone.service.types.v1.Session; |
58 | 54 |
import org.dataone.service.types.v1.SystemMetadata; |
59 | 55 |
import org.dataone.service.util.TypeMarshaller; |
60 | 56 |
import org.jibx.runtime.JiBXException; |
57 |
import org.xml.sax.SAXException; |
|
61 | 58 |
|
62 | 59 |
import edu.ucsb.nceas.metacat.MetacatHandler; |
63 | 60 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
... | ... | |
148 | 145 |
} |
149 | 146 |
} |
150 | 147 |
|
148 |
protected String parseTrailing(String resource, String token) { |
|
149 |
// get the rest |
|
150 |
String extra = null; |
|
151 |
if (resource.indexOf(token) != -1) { |
|
152 |
// what comes after the token? |
|
153 |
extra = resource.substring(resource.indexOf(token) + token.length()); |
|
154 |
// remove the slash |
|
155 |
if (extra.startsWith("/")) { |
|
156 |
extra = extra.substring(1); |
|
157 |
} |
|
158 |
// is there anything left? |
|
159 |
if (extra.length() == 0) { |
|
160 |
extra = null; |
|
161 |
} |
|
162 |
} |
|
163 |
return extra; |
|
164 |
} |
|
165 |
|
|
166 |
protected AccessPolicy collectAccessPolicy() throws IOException, ServiceFailure, InvalidRequest, JiBXException, InstantiationException, IllegalAccessException, ParserConfigurationException, SAXException { |
|
167 |
|
|
168 |
// Read the incoming data from its Mime Multipart encoding |
|
169 |
logMetacat.debug("Disassembling MIME multipart form"); |
|
170 |
InputStream ap = null; |
|
171 |
|
|
172 |
// handle MMP inputs |
|
173 |
File tmpDir = getTempDirectory(); |
|
174 |
logMetacat.debug("temp dir: " + tmpDir.getAbsolutePath()); |
|
175 |
MultipartRequestResolver mrr = |
|
176 |
new MultipartRequestResolver(tmpDir.getAbsolutePath(), 1000000000, 0); |
|
177 |
MultipartRequest mr = null; |
|
178 |
try { |
|
179 |
mr = mrr.resolveMultipart(request); |
|
180 |
} catch (Exception e) { |
|
181 |
throw new ServiceFailure("2161", |
|
182 |
"Could not resolve multipart: " + e.getMessage()); |
|
183 |
} |
|
184 |
logMetacat.debug("resolved multipart request"); |
|
185 |
Map<String, File> files = mr.getMultipartFiles(); |
|
186 |
if (files == null || files.keySet() == null) { |
|
187 |
throw new InvalidRequest("2163", |
|
188 |
"must have multipart file with name 'accessPolicy'"); |
|
189 |
} |
|
190 |
logMetacat.debug("got multipart files"); |
|
191 |
|
|
192 |
multipartparams = mr.getMultipartParameters(); |
|
193 |
|
|
194 |
File apFile = files.get("accessPolicy"); |
|
195 |
if (apFile == null) { |
|
196 |
throw new InvalidRequest("2163", |
|
197 |
"Missing the required file-part 'accessPolicy' from the multipart request."); |
|
198 |
} |
|
199 |
logMetacat.debug("apFile: " + apFile.getAbsolutePath()); |
|
200 |
ap = new FileInputStream(apFile); |
|
201 |
|
|
202 |
AccessPolicy accessPolicy = TypeMarshaller.unmarshalTypeFromStream(AccessPolicy.class, ap); |
|
203 |
return accessPolicy; |
|
204 |
} |
|
205 |
|
|
151 | 206 |
protected SystemMetadata collectSystemMetadata() throws IOException, FileUploadException, ServiceFailure, InvalidRequest, JiBXException, InstantiationException, IllegalAccessException { |
152 | 207 |
|
153 | 208 |
// Read the incoming data from its Mime Multipart encoding |
Also available in: Unified diff
correctly handle incoming "accessPolicy" parameters for the setAccess() method