FrankChen021 commented on code in PR #17937:
URL: https://github.com/apache/druid/pull/17937#discussion_r2069913184


##########
sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java:
##########
@@ -200,4 +211,94 @@ public SqlQuery withQueryContext(Map<String, Object> 
newContext)
   {
     return new SqlQuery(query, resultFormat, header, typesHeader, 
sqlTypesHeader, newContext, parameters);
   }
+
+  /**
+   * Extract SQL query object or SQL text from an HTTP Request
+   */
+  @FunctionalInterface
+  interface ISqlQueryExtractor<T>
+  {
+    T extract() throws IOException;
+  }
+
+  /**
+   * For BROKERs to use.
+   * <p>
+   * Brokers use com.sun.jersey upon Jetty for RESTful API, however jersey 
internally has special handling for x-www-form-urlencoded,
+   * it's not able to get the data from the stream of HttpServletRequest for 
such content type.
+   * So we use HttpContext to get the request entity/string instead of using 
HttpServletRequest.
+   *
+   * @throws HttpException if the content type is not supported
+   * @throws BadRequestException if the SQL query is malformed or fail to read 
from the request
+   */
+  public static SqlQuery from(HttpContext httpContext)
+  {
+    MediaType mediaType = httpContext.getRequest().getMediaType();
+    if (mediaType == null) {
+      throw new HttpException(
+          Response.Status.UNSUPPORTED_MEDIA_TYPE,
+          "Unsupported Content-Type: null"
+      );
+    }
+
+    try {

Review Comment:
   good catch. 
   
   The reason that the two public static `from` method has different throws 
specification is that, the router and broker has different exception handling 
approaches. Current change keeps minimal change to the exception handling of 
router, to make it elegant, as suggested by u, we have to make changes to the 
exception handling router. 
   
   But indeed, I have to say, one `from` throws IOException while another does 
not really makes it a little bit weried.
   
   Let me update it.
   



-- 
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