Retire FileUploader and subtypes (#1154)

This commit is contained in:
Andrzej Cichocki
2017-08-04 15:57:11 +01:00
committed by GitHub
parent 3fbc5fe555
commit 42e29d3b22
8 changed files with 16 additions and 77 deletions

View File

@ -17,7 +17,6 @@ class DataUploadServlet : HttpServlet() {
@Throws(IOException::class)
override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) {
@Suppress("DEPRECATION") // Bogus warning due to superclass static method being deprecated.
val isMultipart = ServletFileUpload.isMultipartContent(req)
val rpc = servletContext.getAttribute("rpc") as CordaRPCOps
@ -34,20 +33,25 @@ class DataUploadServlet : HttpServlet() {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Got an upload request with no files")
return
}
fun reportError(message: String) {
println(message) // Show in webserver window.
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message)
}
while (iterator.hasNext()) {
val item = iterator.next()
log.info("Receiving ${item.name}")
try {
val dataType = req.pathInfo.substring(1).substringBefore('/')
@Suppress("DEPRECATION") // TODO: Replace the use of uploadFile
messages += rpc.uploadFile(dataType, item.name, item.openStream())
log.info("${item.name} successfully accepted: ${messages.last()}")
} catch(e: RuntimeException) {
println(e)
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Got a file upload request for an unknown data type")
val dataType = req.pathInfo.substring(1).substringBefore('/')
if (dataType != "attachment") {
reportError("Got a file upload request for an unknown data type $dataType")
continue
}
try {
messages += rpc.uploadAttachment(item.openStream()).toString()
} catch (e: RuntimeException) {
reportError(e.toString())
continue
}
log.info("${item.name} successfully accepted: ${messages.last()}")
}
// Send back the hashes as a convenience for the user.