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


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+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 {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = 
LoggerFactory.getLogger(JsonUrlReader.class);
+
+    /**
+     * Class to GET and POST to a URL and read the returned JSON. This class 
should
+     * not be instantiated.
+     */
+    private JsonUrlReader() {}
+
+    /**
+     * Method to POST or GET to a URL and recover the JSON in the form of a Map
+     *
+     * @param String method
+     *      The htpp method to use. Should be "GET", "POST" or "PATCH".
+     *
+     * @param URI uri
+     *      A URI value giving the address where to recover the JSON
+     *
+     * @param String body
+     *      A pre-encoded body string to be sent to the address if the method 
is
+     *      "POST" or "PATCH". Ignored if the method is "GET".
+     *
+     * @return
+     *      A Map<String,Object> containing the decoded json values.
+     */
+    public static Map<String, Object> fetch(String method, URI uri, String 
body) throws IOException {
+        if (uri == null || uri.toString().isEmpty()) {
+            throw new IOException("JsonUrlReader: Missing URL");
+        }
+
+        try {
+            HttpClient client = HttpClient.newHttpClient();
+            HttpRequest request = HttpRequest.newBuilder()
+                    .uri(uri)
+                    .header("Content-Type", 
"application/x-www-form-urlencoded; charset=UTF-8")
+                    .method(method,

Review Comment:
   On my machine using "GET" here doesn't crash here with an 
IllegalArgumentException though the documentation makes me think it should. 
Should I protect this in a if/else block ?
   
   ```
   .method(method, (method == "GET" ? HttpRequest.BodPublishers.NoBody() :  
HttpRequest.BodyPublishers.ofString(body == null ? "" : body, 
StandardCharsets.UTF_8)))
   ```



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