Skip to content

Commit

Permalink
HIVE-14984: Hive-WebUI access results in Request is a replay (34) att…
Browse files Browse the repository at this point in the history
…ack (Barna Zsombor Klara, reviewed by Aihua Xu)
  • Loading branch information
Aihua Xu committed Nov 8, 2016
1 parent 36ea683 commit f420211
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
16 changes: 15 additions & 1 deletion common/src/java/org/apache/hive/http/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender;
import org.apache.logging.log4j.core.appender.FileManager;
import org.apache.logging.log4j.core.appender.OutputStreamManager;
import org.eclipse.jetty.rewrite.handler.RewriteHandler;
import org.eclipse.jetty.rewrite.handler.RewriteRegexRule;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler.Context;
Expand Down Expand Up @@ -386,9 +388,21 @@ void initializeWebServer(Builder b) {
connector.setPort(b.port);
webServer.addConnector(connector);

RewriteHandler rwHandler = new RewriteHandler();
rwHandler.setRewriteRequestURI(true);
rwHandler.setRewritePathInfo(false);

RewriteRegexRule rootRule = new RewriteRegexRule();
rootRule.setRegex("^/$");
rootRule.setReplacement("/hiveserver2.jsp");
rootRule.setTerminating(true);

rwHandler.addRule(rootRule);
rwHandler.setHandler(webAppContext);

// Configure web application contexts for the web server
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.addHandler(webAppContext);
contexts.addHandler(rwHandler);
webServer.setHandler(contexts);

addServlet("jmx", "/jmx", JMXJsonServlet.class);
Expand Down
20 changes: 0 additions & 20 deletions service/src/resources/hive-webapps/hiveserver2/index.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.commons.io.IOUtils;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
import org.apache.hadoop.hive.metastore.MetaStoreUtils;
Expand Down Expand Up @@ -85,6 +87,27 @@ public void testStackServlet() throws Exception {
Assert.assertTrue(contents);
}

@Test
public void testContextRootUrlRewrite() throws Exception {
String baseURL = "http://localhost:" + webUIPort + "/";
URL url = new URL(baseURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
StringWriter writer = new StringWriter();
IOUtils.copy(conn.getInputStream(), writer, "UTF-8");
String contextRootContent = writer.toString();

String jspUrl = "http://localhost:" + webUIPort + "/hiveserver2.jsp";
url = new URL(jspUrl);
conn = (HttpURLConnection) url.openConnection();
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
writer = new StringWriter();
IOUtils.copy(conn.getInputStream(), writer, "UTF-8");
String jspContent = writer.toString();

Assert.assertEquals(contextRootContent, jspContent);
}

@Test
public void testConfStrippedFromWebUI() throws Exception {

Expand Down

0 comments on commit f420211

Please sign in to comment.