You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@livy.apache.org by js...@apache.org on 2017/06/30 07:27:18 UTC
incubator-livy git commit: LIVY-357. Web UI: Updated
staticResourceServlet to return 404s and not throw WARNs
Repository: incubator-livy
Updated Branches:
refs/heads/master 92de371cf -> 257ccdfd6
LIVY-357. Web UI: Updated staticResourceServlet to return 404s and not throw WARNs
PR moved from old repo https://github.com/cloudera/livy/pull/339
[LIVY-357](https://issues.cloudera.org/browse/LIVY-357)
Since https://github.com/cloudera/livy/pull/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 <aj...@us.ibm.com>
Closes #2 from ajbozarth/ui-error.
Project: http://git-wip-us.apache.org/repos/asf/incubator-livy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-livy/commit/257ccdfd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-livy/tree/257ccdfd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-livy/diff/257ccdfd
Branch: refs/heads/master
Commit: 257ccdfd693beaf4a415bf29b98119e066cbb762
Parents: 92de371
Author: Alex Bozarth <aj...@us.ibm.com>
Authored: Fri Jun 30 15:27:06 2017 +0800
Committer: jerryshao <ss...@hortonworks.com>
Committed: Fri Jun 30 15:27:06 2017 +0800
----------------------------------------------------------------------
.../scala/com/cloudera/livy/server/LivyServer.scala | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/257ccdfd/server/src/main/scala/com/cloudera/livy/server/LivyServer.scala
----------------------------------------------------------------------
diff --git a/server/src/main/scala/com/cloudera/livy/server/LivyServer.scala b/server/src/main/scala/com/cloudera/livy/server/LivyServer.scala
index 7bfe9ce..c19c9cc 100644
--- a/server/src/main/scala/com/cloudera/livy/server/LivyServer.scala
+++ b/server/src/main/scala/com/cloudera/livy/server/LivyServer.scala
@@ -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)
+ }
}
}