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


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveThriftServlet.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.hadoop.hive.metastore;
+
+import org.apache.thrift.TProcessor;
+import org.apache.thrift.protocol.TProtocolFactory;
+import org.apache.thrift.transport.TIOStreamTransport;
+import org.apache.thrift.transport.TTransport;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class HiveThriftServlet extends HttpServlet {
+  private final TProcessor processor;
+  private final TProtocolFactory inProtocolFactory;
+  private final TProtocolFactory outProtocolFactory;
+
+  public HiveThriftServlet(
+      TProcessor processor,
+      TProtocolFactory inProtocolFactory,
+      TProtocolFactory outProtocolFactory
+  ) {
+    this.processor = processor;
+    this.inProtocolFactory = inProtocolFactory;
+    this.outProtocolFactory = outProtocolFactory;
+  }
+
+  public HiveThriftServlet(TProcessor processor, TProtocolFactory 
protocolFactory) {
+    this(processor, protocolFactory, protocolFactory);
+  }
+
+  @Override
+  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+      throws ServletException {
+    try {
+      resp.setContentType("application/x-thrift");
+      InputStream in = req.getInputStream();
+      OutputStream out = resp.getOutputStream();
+      TTransport transport = new TIOStreamTransport(in, out);
+
+      processor.process(inProtocolFactory.getProtocol(transport), 
outProtocolFactory.getProtocol(transport));
+      out.flush();
+    } catch (Exception e) {
+      throw new ServletException(e);

Review Comment:
   ## SonarCloud / Exceptions should not be thrown from servlet methods
   
   <!--SONAR_ISSUE_KEY:AZ-p3UwAFDz-NFkrTas1-->Handle the "ServletException" 
thrown here in a "try/catch" block. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_hive&issues=AZ-p3UwAFDz-NFkrTas1&open=AZ-p3UwAFDz-NFkrTas1&pullRequest=6653";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/hive/security/code-scanning/455)



##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveThriftServlet.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.hadoop.hive.metastore;
+
+import org.apache.thrift.TProcessor;
+import org.apache.thrift.protocol.TProtocolFactory;
+import org.apache.thrift.transport.TIOStreamTransport;
+import org.apache.thrift.transport.TTransport;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class HiveThriftServlet extends HttpServlet {
+  private final TProcessor processor;
+  private final TProtocolFactory inProtocolFactory;
+  private final TProtocolFactory outProtocolFactory;
+
+  public HiveThriftServlet(
+      TProcessor processor,
+      TProtocolFactory inProtocolFactory,
+      TProtocolFactory outProtocolFactory
+  ) {
+    this.processor = processor;
+    this.inProtocolFactory = inProtocolFactory;
+    this.outProtocolFactory = outProtocolFactory;
+  }
+
+  public HiveThriftServlet(TProcessor processor, TProtocolFactory 
protocolFactory) {
+    this(processor, protocolFactory, protocolFactory);
+  }
+
+  @Override
+  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+      throws ServletException {
+    try {
+      resp.setContentType("application/x-thrift");
+      InputStream in = req.getInputStream();
+      OutputStream out = resp.getOutputStream();
+      TTransport transport = new TIOStreamTransport(in, out);
+
+      processor.process(inProtocolFactory.getProtocol(transport), 
outProtocolFactory.getProtocol(transport));
+      out.flush();
+    } catch (Exception e) {
+      throw new ServletException(e);
+    }
+  }
+
+  @Override
+  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+      throws ServletException, IOException {
+    doPost(req, resp);

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



##########
service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpServlet.java:
##########
@@ -269,7 +284,7 @@
         }
         LOG.info("Cookie added for clientUserName " + clientUserName);
       }
-      super.doPost(request, response);
+      processThriftRequest(request, response);

Review Comment:
   ## SonarCloud / Exceptions should not be thrown from servlet methods
   
   <!--SONAR_ISSUE_KEY:AZ-p3U4BFDz-NFkrTatS-->Handle the following exceptions 
that could be thrown by "processThriftRequest": ServletException, IOException. 
<p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_hive&issues=AZ-p3U4BFDz-NFkrTatS&open=AZ-p3U4BFDz-NFkrTatS&pullRequest=6653";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/hive/security/code-scanning/454)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to