diff --git common/src/java/org/apache/hive/http/HttpServer.java common/src/java/org/apache/hive/http/HttpServer.java index 42d2959..f99f18a 100644 --- common/src/java/org/apache/hive/http/HttpServer.java +++ common/src/java/org/apache/hive/http/HttpServer.java @@ -120,6 +120,7 @@ private HttpServer(final Builder b) throws IOException { private String spnegoKeytab; private boolean useSPNEGO; private boolean useSSL; + private String contextRootRewriteTarget = "/index.html"; private final List>> servlets = new LinkedList>>(); @@ -197,6 +198,11 @@ public Builder setContextAttribute(String name, Object value) { return this; } + public Builder setContextRootRewriteTarget(String contextRootRewriteTarget) { + this.contextRootRewriteTarget = contextRootRewriteTarget; + return this; + } + public Builder addServlet(String endpoint, Class servlet) { servlets.add(new Pair>(endpoint, servlet)); return this; @@ -394,7 +400,7 @@ void initializeWebServer(Builder b) { RewriteRegexRule rootRule = new RewriteRegexRule(); rootRule.setRegex("^/$"); - rootRule.setReplacement("/hiveserver2.jsp"); + rootRule.setReplacement(b.contextRootRewriteTarget); rootRule.setTerminating(true); rwHandler.addRule(rootRule); diff --git llap-server/src/test/org/apache/hadoop/hive/llap/daemon/services/impl/TestLlapWebServices.java llap-server/src/test/org/apache/hadoop/hive/llap/daemon/services/impl/TestLlapWebServices.java new file mode 100644 index 0000000..833a8f5 --- /dev/null +++ llap-server/src/test/org/apache/hadoop/hive/llap/daemon/services/impl/TestLlapWebServices.java @@ -0,0 +1,69 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.llap.daemon.services.impl; + +import org.apache.commons.io.IOUtils; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.metastore.MetaStoreUtils; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; +import java.io.StringWriter; +import java.net.HttpURLConnection; +import java.net.URL; + +public class TestLlapWebServices { + + private static LlapWebServices llapWS = null; + private static int llapWSPort; + + @BeforeClass + public static void beforeTests() throws Exception { + llapWSPort = MetaStoreUtils.findFreePortExcepting( + Integer.valueOf(HiveConf.ConfVars.LLAP_DAEMON_WEB_PORT.getDefaultValue())); + llapWS = new LlapWebServices(llapWSPort, null, null); + llapWS.init(new HiveConf()); + llapWS.start(); + Thread.sleep(5000); + } + + @Test + public void testContextRootUrlRewrite() throws Exception { + String contextRootURL = "http://localhost:" + llapWSPort + "/"; + String contextRootContent = getURLResponseAsString(contextRootURL); + + String indexHtmlUrl = "http://localhost:" + llapWSPort + "/index.html"; + String indexHtmlContent = getURLResponseAsString(indexHtmlUrl); + + Assert.assertEquals(contextRootContent, indexHtmlContent); + } + + private String getURLResponseAsString(String baseURL) throws IOException { + 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"); + return writer.toString(); + } + + @AfterClass + public static void afterTests() throws Exception { + llapWS.stop(); + } +} diff --git service/src/java/org/apache/hive/service/server/HiveServer2.java service/src/java/org/apache/hive/service/server/HiveServer2.java index 9c94611..70cb126 100644 --- service/src/java/org/apache/hive/service/server/HiveServer2.java +++ service/src/java/org/apache/hive/service/server/HiveServer2.java @@ -204,6 +204,7 @@ public void run() { builder.setUseSPNEGO(true); } builder.addServlet("llap", LlapServlet.class); + builder.setContextRootRewriteTarget("/hiveserver2.jsp"); webServer = builder.build(); webServer.addServlet("query_page", "/query_page", QueryProfileServlet.class); } diff --git service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java index d918c64..351cfc1 100644 --- service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java +++ service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java @@ -19,6 +19,7 @@ package org.apache.hive.service.server; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import java.io.StringWriter; import java.net.HttpURLConnection; @@ -90,20 +91,10 @@ public void testStackServlet() throws Exception { @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 contextRootContent = getURLResponseAsString(baseURL); 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(); + String jspContent = getURLResponseAsString(jspUrl); Assert.assertEquals(contextRootContent, jspContent); } @@ -145,6 +136,15 @@ public void testConfStrippedFromWebUI() throws Exception { assertNull(pwdValFound); } + private String getURLResponseAsString(String baseURL) throws IOException { + 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"); + return writer.toString(); + } + @AfterClass public static void afterTests() throws Exception {