github-advanced-security[bot] commented on code in PR #5145:
URL: https://github.com/apache/hive/pull/5145#discussion_r1536832767


##########
hms-catalog/src/main/java/org/apache/iceberg/rest/HMSCatalogServlet.java:
##########
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.iceberg.rest;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UncheckedIOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.hadoop.hive.metastore.SecureServletCaller;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.io.CharStreams;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.iceberg.rest.HMSCatalogAdapter.HTTPMethod;
+import org.apache.iceberg.rest.HMSCatalogAdapter.Route;
+import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.apache.iceberg.util.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Original @ 
https://github.com/apache/iceberg/blob/main/core/src/test/java/org/apache/iceberg/rest/RESTCatalogServlet.java
+ * The RESTCatalogServlet provides a servlet implementation used in 
combination with a
+ * RESTCatalogAdaptor to proxy the REST Spec to any Catalog implementation.
+ */
+public class HMSCatalogServlet extends HttpServlet {
+  private static final Logger LOG = 
LoggerFactory.getLogger(HMSCatalogServlet.class);
+  /**
+   * The security.
+   */
+  private final SecureServletCaller security;
+
+  private final HMSCatalogAdapter restCatalogAdapter;
+  private final Map<String, String> responseHeaders =
+      ImmutableMap.of(HttpHeaders.CONTENT_TYPE, 
ContentType.APPLICATION_JSON.getMimeType());
+
+  public HMSCatalogServlet(SecureServletCaller security, HMSCatalogAdapter 
restCatalogAdapter) {
+    this.security = security;
+    this.restCatalogAdapter = restCatalogAdapter;
+  }
+
+  @Override
+  public void init() throws ServletException {
+    super.init();
+    security.init();
+  }
+  @Override
+  protected void service(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
+    String method = req.getMethod();
+    if (!"PATCH".equals(method)) {
+      super.service(req, resp);
+    } else {
+      this.doPatch(req, resp);
+    }
+  }
+
+  protected void doPatch(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+    security.execute(request, response, this::execute);

Review Comment:
   ## Exceptions should not be thrown from servlet methods
   
   <!--SONAR_ISSUE_KEY:AY5unbPEwUK3TfzYEmqz-->Handle the following exception 
that could be thrown by "execute": IOException. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_hive&issues=AY5unbPEwUK3TfzYEmqz&open=AY5unbPEwUK3TfzYEmqz&pullRequest=5145";>SonarCloud</a></p>
   
   [Show more 
details](https://github.com/apache/hive/security/code-scanning/116)



##########
hms-catalog/src/main/java/org/apache/iceberg/rest/HMSCatalogServlet.java:
##########
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.iceberg.rest;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UncheckedIOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.hadoop.hive.metastore.SecureServletCaller;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.io.CharStreams;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.iceberg.rest.HMSCatalogAdapter.HTTPMethod;
+import org.apache.iceberg.rest.HMSCatalogAdapter.Route;
+import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.apache.iceberg.util.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Original @ 
https://github.com/apache/iceberg/blob/main/core/src/test/java/org/apache/iceberg/rest/RESTCatalogServlet.java
+ * The RESTCatalogServlet provides a servlet implementation used in 
combination with a
+ * RESTCatalogAdaptor to proxy the REST Spec to any Catalog implementation.
+ */
+public class HMSCatalogServlet extends HttpServlet {
+  private static final Logger LOG = 
LoggerFactory.getLogger(HMSCatalogServlet.class);
+  /**
+   * The security.
+   */
+  private final SecureServletCaller security;
+
+  private final HMSCatalogAdapter restCatalogAdapter;
+  private final Map<String, String> responseHeaders =
+      ImmutableMap.of(HttpHeaders.CONTENT_TYPE, 
ContentType.APPLICATION_JSON.getMimeType());
+
+  public HMSCatalogServlet(SecureServletCaller security, HMSCatalogAdapter 
restCatalogAdapter) {
+    this.security = security;
+    this.restCatalogAdapter = restCatalogAdapter;
+  }
+
+  @Override
+  public void init() throws ServletException {
+    super.init();
+    security.init();
+  }
+  @Override
+  protected void service(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
+    String method = req.getMethod();
+    if (!"PATCH".equals(method)) {
+      super.service(req, resp);
+    } else {
+      this.doPatch(req, resp);
+    }
+  }
+
+  protected void doPatch(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
+    security.execute(request, response, this::execute);

Review Comment:
   ## Exceptions should not be thrown from servlet methods
   
   <!--SONAR_ISSUE_KEY:AY5unbPEwUK3TfzYEmq0-->Handle the following exception 
that could be thrown by "execute": IOException. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_hive&issues=AY5unbPEwUK3TfzYEmq0&open=AY5unbPEwUK3TfzYEmq0&pullRequest=5145";>SonarCloud</a></p>
   
   [Show more 
details](https://github.com/apache/hive/security/code-scanning/111)



##########
hms-catalog/src/main/java/org/apache/iceberg/rest/HMSCatalogServlet.java:
##########
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.iceberg.rest;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UncheckedIOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.hadoop.hive.metastore.SecureServletCaller;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.io.CharStreams;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.iceberg.rest.HMSCatalogAdapter.HTTPMethod;
+import org.apache.iceberg.rest.HMSCatalogAdapter.Route;
+import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.apache.iceberg.util.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Original @ 
https://github.com/apache/iceberg/blob/main/core/src/test/java/org/apache/iceberg/rest/RESTCatalogServlet.java
+ * The RESTCatalogServlet provides a servlet implementation used in 
combination with a
+ * RESTCatalogAdaptor to proxy the REST Spec to any Catalog implementation.
+ */
+public class HMSCatalogServlet extends HttpServlet {
+  private static final Logger LOG = 
LoggerFactory.getLogger(HMSCatalogServlet.class);
+  /**
+   * The security.
+   */
+  private final SecureServletCaller security;
+
+  private final HMSCatalogAdapter restCatalogAdapter;
+  private final Map<String, String> responseHeaders =
+      ImmutableMap.of(HttpHeaders.CONTENT_TYPE, 
ContentType.APPLICATION_JSON.getMimeType());
+
+  public HMSCatalogServlet(SecureServletCaller security, HMSCatalogAdapter 
restCatalogAdapter) {
+    this.security = security;
+    this.restCatalogAdapter = restCatalogAdapter;
+  }
+
+  @Override
+  public void init() throws ServletException {
+    super.init();
+    security.init();
+  }
+  @Override
+  protected void service(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
+    String method = req.getMethod();
+    if (!"PATCH".equals(method)) {
+      super.service(req, resp);
+    } else {
+      this.doPatch(req, resp);
+    }
+  }
+
+  protected void doPatch(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doPut(HttpServletRequest request,
+                       HttpServletResponse response) throws IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doHead(HttpServletRequest request, HttpServletResponse 
response)
+      throws IOException {
+    security.execute(request, response, this::execute);

Review Comment:
   ## Exceptions should not be thrown from servlet methods
   
   <!--SONAR_ISSUE_KEY:AY5unbPEwUK3TfzYEmq2-->Handle the following exception 
that could be thrown by "execute": IOException. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_hive&issues=AY5unbPEwUK3TfzYEmq2&open=AY5unbPEwUK3TfzYEmq2&pullRequest=5145";>SonarCloud</a></p>
   
   [Show more 
details](https://github.com/apache/hive/security/code-scanning/113)



##########
hms-catalog/src/main/java/org/apache/iceberg/rest/HMSCatalogServlet.java:
##########
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.iceberg.rest;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UncheckedIOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.hadoop.hive.metastore.SecureServletCaller;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.io.CharStreams;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.iceberg.rest.HMSCatalogAdapter.HTTPMethod;
+import org.apache.iceberg.rest.HMSCatalogAdapter.Route;
+import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.apache.iceberg.util.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Original @ 
https://github.com/apache/iceberg/blob/main/core/src/test/java/org/apache/iceberg/rest/RESTCatalogServlet.java
+ * The RESTCatalogServlet provides a servlet implementation used in 
combination with a
+ * RESTCatalogAdaptor to proxy the REST Spec to any Catalog implementation.
+ */
+public class HMSCatalogServlet extends HttpServlet {
+  private static final Logger LOG = 
LoggerFactory.getLogger(HMSCatalogServlet.class);
+  /**
+   * The security.
+   */
+  private final SecureServletCaller security;
+
+  private final HMSCatalogAdapter restCatalogAdapter;
+  private final Map<String, String> responseHeaders =
+      ImmutableMap.of(HttpHeaders.CONTENT_TYPE, 
ContentType.APPLICATION_JSON.getMimeType());
+
+  public HMSCatalogServlet(SecureServletCaller security, HMSCatalogAdapter 
restCatalogAdapter) {
+    this.security = security;
+    this.restCatalogAdapter = restCatalogAdapter;
+  }
+
+  @Override
+  public void init() throws ServletException {
+    super.init();
+    security.init();
+  }
+  @Override
+  protected void service(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
+    String method = req.getMethod();
+    if (!"PATCH".equals(method)) {
+      super.service(req, resp);
+    } else {
+      this.doPatch(req, resp);
+    }
+  }
+
+  protected void doPatch(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doPut(HttpServletRequest request,
+                       HttpServletResponse response) throws IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doHead(HttpServletRequest request, HttpServletResponse 
response)
+      throws IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doPost(HttpServletRequest request, HttpServletResponse 
response)
+      throws IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doDelete(HttpServletRequest request, HttpServletResponse 
response)
+      throws IOException {
+    security.execute(request, response, this::execute);

Review Comment:
   ## Exceptions should not be thrown from servlet methods
   
   <!--SONAR_ISSUE_KEY:AY5unbPEwUK3TfzYEmq4-->Handle the following exception 
that could be thrown by "execute": IOException. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_hive&issues=AY5unbPEwUK3TfzYEmq4&open=AY5unbPEwUK3TfzYEmq4&pullRequest=5145";>SonarCloud</a></p>
   
   [Show more 
details](https://github.com/apache/hive/security/code-scanning/115)



##########
hms-catalog/src/main/java/org/apache/iceberg/rest/HMSCatalogServlet.java:
##########
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.iceberg.rest;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UncheckedIOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.hadoop.hive.metastore.SecureServletCaller;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.io.CharStreams;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.iceberg.rest.HMSCatalogAdapter.HTTPMethod;
+import org.apache.iceberg.rest.HMSCatalogAdapter.Route;
+import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.apache.iceberg.util.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Original @ 
https://github.com/apache/iceberg/blob/main/core/src/test/java/org/apache/iceberg/rest/RESTCatalogServlet.java
+ * The RESTCatalogServlet provides a servlet implementation used in 
combination with a
+ * RESTCatalogAdaptor to proxy the REST Spec to any Catalog implementation.
+ */
+public class HMSCatalogServlet extends HttpServlet {
+  private static final Logger LOG = 
LoggerFactory.getLogger(HMSCatalogServlet.class);
+  /**
+   * The security.
+   */
+  private final SecureServletCaller security;
+
+  private final HMSCatalogAdapter restCatalogAdapter;
+  private final Map<String, String> responseHeaders =
+      ImmutableMap.of(HttpHeaders.CONTENT_TYPE, 
ContentType.APPLICATION_JSON.getMimeType());
+
+  public HMSCatalogServlet(SecureServletCaller security, HMSCatalogAdapter 
restCatalogAdapter) {
+    this.security = security;
+    this.restCatalogAdapter = restCatalogAdapter;
+  }
+
+  @Override
+  public void init() throws ServletException {
+    super.init();
+    security.init();
+  }
+  @Override
+  protected void service(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
+    String method = req.getMethod();
+    if (!"PATCH".equals(method)) {
+      super.service(req, resp);
+    } else {
+      this.doPatch(req, resp);
+    }
+  }
+
+  protected void doPatch(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doPut(HttpServletRequest request,
+                       HttpServletResponse response) throws IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doHead(HttpServletRequest request, HttpServletResponse 
response)
+      throws IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doPost(HttpServletRequest request, HttpServletResponse 
response)
+      throws IOException {
+    security.execute(request, response, this::execute);

Review Comment:
   ## Exceptions should not be thrown from servlet methods
   
   <!--SONAR_ISSUE_KEY:AY5unbPEwUK3TfzYEmq3-->Handle the following exception 
that could be thrown by "execute": IOException. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_hive&issues=AY5unbPEwUK3TfzYEmq3&open=AY5unbPEwUK3TfzYEmq3&pullRequest=5145";>SonarCloud</a></p>
   
   [Show more 
details](https://github.com/apache/hive/security/code-scanning/114)



##########
hms-catalog/src/main/java/org/apache/iceberg/rest/HMSCatalogServlet.java:
##########
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.iceberg.rest;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UncheckedIOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.hadoop.hive.metastore.SecureServletCaller;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.io.CharStreams;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.iceberg.rest.HMSCatalogAdapter.HTTPMethod;
+import org.apache.iceberg.rest.HMSCatalogAdapter.Route;
+import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.apache.iceberg.util.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Original @ 
https://github.com/apache/iceberg/blob/main/core/src/test/java/org/apache/iceberg/rest/RESTCatalogServlet.java
+ * The RESTCatalogServlet provides a servlet implementation used in 
combination with a
+ * RESTCatalogAdaptor to proxy the REST Spec to any Catalog implementation.
+ */
+public class HMSCatalogServlet extends HttpServlet {
+  private static final Logger LOG = 
LoggerFactory.getLogger(HMSCatalogServlet.class);
+  /**
+   * The security.
+   */
+  private final SecureServletCaller security;
+
+  private final HMSCatalogAdapter restCatalogAdapter;
+  private final Map<String, String> responseHeaders =
+      ImmutableMap.of(HttpHeaders.CONTENT_TYPE, 
ContentType.APPLICATION_JSON.getMimeType());
+
+  public HMSCatalogServlet(SecureServletCaller security, HMSCatalogAdapter 
restCatalogAdapter) {
+    this.security = security;
+    this.restCatalogAdapter = restCatalogAdapter;
+  }
+
+  @Override
+  public void init() throws ServletException {
+    super.init();
+    security.init();
+  }
+  @Override
+  protected void service(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
+    String method = req.getMethod();
+    if (!"PATCH".equals(method)) {
+      super.service(req, resp);
+    } else {
+      this.doPatch(req, resp);
+    }
+  }
+
+  protected void doPatch(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
+    security.execute(request, response, this::execute);
+  }
+
+  @Override
+  protected void doPut(HttpServletRequest request,
+                       HttpServletResponse response) throws IOException {
+    security.execute(request, response, this::execute);

Review Comment:
   ## Exceptions should not be thrown from servlet methods
   
   <!--SONAR_ISSUE_KEY:AY5unbPEwUK3TfzYEmq1-->Handle the following exception 
that could be thrown by "execute": IOException. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_hive&issues=AY5unbPEwUK3TfzYEmq1&open=AY5unbPEwUK3TfzYEmq1&pullRequest=5145";>SonarCloud</a></p>
   
   [Show more 
details](https://github.com/apache/hive/security/code-scanning/112)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to