Skip to content

Commit 4cc5915

Browse files
ajbozarthpraveen-kanamarlapudi
authored andcommitted
LIVY-357. Web UI: Updated staticResourceServlet to return 404s and not throw WARNs
PR moved from old repo cloudera/livy#339 [LIVY-357](https://issues.cloudera.org/browse/LIVY-357) Since cloudera/livy#319 added the UI whenever a static resource is accessed a `MimeException` is thrown as a `WARN`. This was caused because a `InputStream` must be wrapped in a `BufferedInputStream` for a full implementation. I updated `staticResourceServlet` with the wrapper as well as adding a `404 File not found` return when a file does not exist (currently an empty file is returned in such a case) Tested manually Author: Alex Bozarth <ajbozart@us.ibm.com> Closes apache#2 from ajbozarth/ui-error.
1 parent eaca02e commit 4cc5915

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

server/src/main/scala/com/cloudera/livy/server/LivyServer.scala

+14-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package com.cloudera.livy.server
2020

21+
import java.io.{BufferedInputStream, InputStream}
2122
import java.util.concurrent._
2223
import java.util.EnumSet
2324
import javax.servlet._
@@ -28,9 +29,9 @@ import scala.concurrent.Future
2829
import org.apache.hadoop.security.{SecurityUtil, UserGroupInformation}
2930
import org.apache.hadoop.security.authentication.server._
3031
import org.eclipse.jetty.servlet.FilterHolder
32+
import org.scalatra.{NotFound, ScalatraServlet}
3133
import org.scalatra.metrics.MetricsBootstrap
3234
import org.scalatra.metrics.MetricsSupportExtensions._
33-
import org.scalatra.ScalatraServlet
3435
import org.scalatra.servlet.{MultipartConfig, ServletApiImplicits}
3536

3637
import com.cloudera.livy._
@@ -146,9 +147,20 @@ class LivyServer extends Logging {
146147

147148
// Servlet for hosting static files such as html, css, and js
148149
// Necessary since Jetty cannot set it's resource base inside a jar
150+
// Returns 404 if the file does not exist
149151
val staticResourceServlet = new ScalatraServlet {
150152
get("/*") {
151-
getClass.getResourceAsStream("ui/static/" + params("splat"))
153+
val fileName = params("splat")
154+
val notFoundMsg = "File not found"
155+
156+
if (!fileName.isEmpty) {
157+
getClass.getResourceAsStream(s"ui/static/$fileName") match {
158+
case is: InputStream => new BufferedInputStream(is)
159+
case null => NotFound(notFoundMsg)
160+
}
161+
} else {
162+
NotFound(notFoundMsg)
163+
}
152164
}
153165
}
154166

0 commit comments

Comments
 (0)