adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069545652


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I'd written a huge amount of comments in my deleted self review for this 
point. Basically thinking out loud. So here you'll get the condensed version.
   
   Basically doing something like
   
   ```
   $ find . -name "*.java" -exec grep -H "httpClient" {} \;
   ```
   
   and all other possible httpclients I could think of, I found no example of 
an outbound HTTP connexion from guacamole. So as far as I can see we are free 
to implement this how we want. However it needs to
   
   - don’t introduce any new large dependencies to guacamole
   - treat both POST and GET requests
   - Be relatively clean
   
   java.net.httpUrlConnection is a bit old and ugly, but I couldn't find any 
apache commons I/O function that treated both POST and GET. Using Jackson to 
deserialize to an Object seemed also to be overkill as I only needed a couple 
of values. 
   
   The slightly more modern  java.net.http.httpClient will make the code 
cleaner. Don't see the point of using 
org.apache.http.impl.client.CloseableHttpClient as the http post/get operations 
are one off each time. Though using org.apache.http.impl.client.HttpClient is 
an option that might be attractive as it supplies functions to more cleanly 
treat the posted form data. 
   
   I've updated the code using java.net.http.httpClient and included 
asynchronous operation to release control back to the Tomcat Servlet so as not 
to impact the rest of guacamole if the operation takes some time.
   
   If you prefer a different http client, there is a plethora to choose from, 
then sure I'll change it. Now is the time to complain as this is the first 
outbound connection in guacamole, so getting it right before introducing code 
we might regret is the right thing to do. :-)
   



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

Reply via email to