Revision 6472
Added by ben leinfelder about 13 years ago
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java | ||
---|---|---|
39 | 39 |
import javax.servlet.ServletContext; |
40 | 40 |
import javax.servlet.http.HttpServletRequest; |
41 | 41 |
import javax.servlet.http.HttpServletResponse; |
42 |
import javax.xml.parsers.ParserConfigurationException; |
|
42 | 43 |
|
43 | 44 |
import org.apache.commons.fileupload.FileUploadException; |
44 | 45 |
import org.apache.commons.io.IOUtils; |
45 | 46 |
import org.apache.log4j.Logger; |
46 | 47 |
import org.dataone.client.ObjectFormatCache; |
48 |
import org.dataone.mimemultipart.MultipartRequest; |
|
49 |
import org.dataone.mimemultipart.MultipartRequestResolver; |
|
47 | 50 |
import org.dataone.service.exceptions.BaseException; |
48 | 51 |
import org.dataone.service.exceptions.IdentifierNotUnique; |
49 | 52 |
import org.dataone.service.exceptions.InsufficientResources; |
... | ... | |
73 | 76 |
import org.dataone.service.types.v1.Subject; |
74 | 77 |
import org.dataone.service.types.v1.SystemMetadata; |
75 | 78 |
import org.dataone.service.util.DateTimeMarshaller; |
79 |
import org.dataone.service.util.ExceptionHandler; |
|
76 | 80 |
import org.dataone.service.util.TypeMarshaller; |
77 | 81 |
import org.jibx.runtime.JiBXException; |
82 |
import org.xml.sax.SAXException; |
|
78 | 83 |
|
79 | 84 |
import edu.ucsb.nceas.metacat.dataone.MNodeService; |
80 | 85 |
|
... | ... | |
315 | 320 |
*/ |
316 | 321 |
private void syncError() throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, JiBXException, IOException, InstantiationException, IllegalAccessException { |
317 | 322 |
SynchronizationFailed syncFailed = null; |
318 |
if (params.containsKey("message")) { |
|
319 |
String message = params.get("message")[0]; |
|
320 |
syncFailed = TypeMarshaller.unmarshalTypeFromStream(SynchronizationFailed.class, new ByteArrayInputStream(message.getBytes("UTF-8"))); |
|
321 |
} |
|
323 |
try { |
|
324 |
syncFailed = collectSynchronizationFailed(); |
|
325 |
} catch (ParserConfigurationException e) { |
|
326 |
throw new ServiceFailure("2161", e.getMessage()); |
|
327 |
} catch (SAXException e) { |
|
328 |
throw new ServiceFailure("2161", e.getMessage()); |
|
329 |
} |
|
330 |
|
|
322 | 331 |
MNodeService.getInstance().synchronizationFailed(session, syncFailed); |
323 | 332 |
} |
324 | 333 |
|
334 |
protected SynchronizationFailed collectSynchronizationFailed() throws IOException, ServiceFailure, InvalidRequest, JiBXException, InstantiationException, IllegalAccessException, ParserConfigurationException, SAXException { |
|
335 |
|
|
336 |
// Read the incoming data from its Mime Multipart encoding |
|
337 |
logMetacat.debug("Disassembling MIME multipart form"); |
|
338 |
InputStream sf = null; |
|
339 |
|
|
340 |
// handle MMP inputs |
|
341 |
File tmpDir = getTempDirectory(); |
|
342 |
logMetacat.debug("temp dir: " + tmpDir.getAbsolutePath()); |
|
343 |
MultipartRequestResolver mrr = |
|
344 |
new MultipartRequestResolver(tmpDir.getAbsolutePath(), 1000000000, 0); |
|
345 |
MultipartRequest mr = null; |
|
346 |
try { |
|
347 |
mr = mrr.resolveMultipart(request); |
|
348 |
} catch (Exception e) { |
|
349 |
throw new ServiceFailure("2161", |
|
350 |
"Could not resolve multipart: " + e.getMessage()); |
|
351 |
} |
|
352 |
logMetacat.debug("resolved multipart request"); |
|
353 |
Map<String, File> files = mr.getMultipartFiles(); |
|
354 |
if (files == null || files.keySet() == null) { |
|
355 |
throw new InvalidRequest("2163", |
|
356 |
"must have multipart file with name 'message'"); |
|
357 |
} |
|
358 |
logMetacat.debug("got multipart files"); |
|
359 |
|
|
360 |
multipartparams = mr.getMultipartParameters(); |
|
361 |
|
|
362 |
File sfFile = files.get("message"); |
|
363 |
if (sfFile == null) { |
|
364 |
throw new InvalidRequest("2163", |
|
365 |
"Missing the required file-part 'message' from the multipart request."); |
|
366 |
} |
|
367 |
logMetacat.debug("sfFile: " + sfFile.getAbsolutePath()); |
|
368 |
sf = new FileInputStream(sfFile); |
|
369 |
|
|
370 |
SynchronizationFailed syncFailed = (SynchronizationFailed) ExceptionHandler.deserializeXml(sf, "Error deserializing exception"); |
|
371 |
return syncFailed; |
|
372 |
} |
|
373 |
|
|
325 | 374 |
/** |
326 | 375 |
* Handles the monitoring resources |
327 | 376 |
* @return |
Also available in: Unified diff
collect "message" param from multipart request for MN.synchronizationFailed method