|
@@ -18,6 +18,7 @@
|
|
|
|
|
|
package com.cloudera.livy.server
|
|
|
|
|
|
+import java.io.{BufferedInputStream, InputStream}
|
|
|
import java.util.concurrent._
|
|
|
import java.util.EnumSet
|
|
|
import javax.servlet._
|
|
@@ -28,9 +29,9 @@ import scala.concurrent.Future
|
|
|
import org.apache.hadoop.security.{SecurityUtil, UserGroupInformation}
|
|
|
import org.apache.hadoop.security.authentication.server._
|
|
|
import org.eclipse.jetty.servlet.FilterHolder
|
|
|
+import org.scalatra.{NotFound, ScalatraServlet}
|
|
|
import org.scalatra.metrics.MetricsBootstrap
|
|
|
import org.scalatra.metrics.MetricsSupportExtensions._
|
|
|
-import org.scalatra.ScalatraServlet
|
|
|
import org.scalatra.servlet.{MultipartConfig, ServletApiImplicits}
|
|
|
|
|
|
import com.cloudera.livy._
|
|
@@ -146,9 +147,20 @@ class LivyServer extends Logging {
|
|
|
|
|
|
// Servlet for hosting static files such as html, css, and js
|
|
|
// Necessary since Jetty cannot set it's resource base inside a jar
|
|
|
+ // Returns 404 if the file does not exist
|
|
|
val staticResourceServlet = new ScalatraServlet {
|
|
|
get("/*") {
|
|
|
- getClass.getResourceAsStream("ui/static/" + params("splat"))
|
|
|
+ val fileName = params("splat")
|
|
|
+ val notFoundMsg = "File not found"
|
|
|
+
|
|
|
+ if (!fileName.isEmpty) {
|
|
|
+ getClass.getResourceAsStream(s"ui/static/$fileName") match {
|
|
|
+ case is: InputStream => new BufferedInputStream(is)
|
|
|
+ case null => NotFound(notFoundMsg)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ NotFound(notFoundMsg)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|