Skip to content

Instantly share code, notes, and snippets.

@reyman
Created February 23, 2013 22:46
Show Gist options
  • Save reyman/5021694 to your computer and use it in GitHub Desktop.
Save reyman/5021694 to your computer and use it in GitHub Desktop.
package org.openmole.web
import _root_.akka.actor.{ Props, ActorSystem }
import org.scalatra._
import org.scalatra.servlet._
import scalate.ScalateSupport
import servlet._
import java.io._
import java.security.MessageDigest
import concurrent.{ Await, ExecutionContext, Future }
import scala.util.matching.Regex
import concurrent.Future
import concurrent.duration._
import org.openmole.ide.core.implementation.execution._
import org.openmole.ide.core.implementation.serializer._
import org.openmole.core.serializer.SerializerService
import com.thoughtworks.xstream.mapper.CannotResolveClassException
import javax.servlet.{ MultipartConfigElement, ServletException }
import scala.collection.JavaConversions._
class MyRepoServlet(val system: ActorSystem) extends ScalatraServlet with ScalateSupport with FileUploadSupport with FutureSupport {
configureMultipartHandling(MultipartConfig(maxFileSize = Some(3 * 1024 * 1024), fileSizeThreshold = Some(1024 * 1024 * 1024)))
protected implicit def executor: ExecutionContext = system.dispatcher
get("/uploadMole") {
contentType = "text/html"
new AsyncResult() {
val is = Future {
ssp("/uploadMole", "body" -> "Please upload an om file below!")
}
}
}
post("/uploadMole") {
contentType = "text/html"
implicit def timeout = Duration(10, SECONDS)
val x = new AsyncResult() {
val is = Future {
val document = fileParams("document")
try {
val tempFile = File.createTempFile("scalatra-test-", document.name)
document.write(tempFile)
"file size: " + tempFile.length
} catch {
case e: IOException ⇒ println("Error " + e)
}
}
}
println(x.timeout)
x
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment