You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by mj...@apache.org on 2016/03/20 03:22:13 UTC
[33/50] incubator-guacamole-client git commit: GUAC-1378: Serve HTML
patch resources from /api/patches.
GUAC-1378: Serve HTML patch resources from /api/patches.
Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/4881e5c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/4881e5c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/4881e5c7
Branch: refs/heads/master
Commit: 4881e5c778537413a56ffdde619eb2c7693ef939
Parents: ec4f370
Author: Michael Jumper <mi...@guac-dev.org>
Authored: Fri Feb 19 00:21:42 2016 -0800
Committer: Michael Jumper <mi...@guac-dev.org>
Committed: Fri Feb 19 00:21:42 2016 -0800
----------------------------------------------------------------------
.../net/basic/rest/RESTServiceModule.java | 2 +
.../net/basic/rest/patch/PatchRESTService.java | 124 +++++++++++++++++++
.../net/basic/rest/patch/package-info.java | 27 ++++
3 files changed, 153 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/4881e5c7/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServiceModule.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServiceModule.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServiceModule.java
index 40ee2d3..72842ba 100644
--- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServiceModule.java
+++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServiceModule.java
@@ -38,6 +38,7 @@ import org.glyptodon.guacamole.net.basic.rest.auth.SecureRandomAuthTokenGenerato
import org.glyptodon.guacamole.net.basic.rest.auth.TokenSessionMap;
import org.glyptodon.guacamole.net.basic.rest.history.HistoryRESTService;
import org.glyptodon.guacamole.net.basic.rest.language.LanguageRESTService;
+import org.glyptodon.guacamole.net.basic.rest.patch.PatchRESTService;
import org.glyptodon.guacamole.net.basic.rest.schema.SchemaRESTService;
import org.glyptodon.guacamole.net.basic.rest.user.UserRESTService;
@@ -91,6 +92,7 @@ public class RESTServiceModule extends ServletModule {
bind(ConnectionRESTService.class);
bind(HistoryRESTService.class);
bind(LanguageRESTService.class);
+ bind(PatchRESTService.class);
bind(SchemaRESTService.class);
bind(TokenRESTService.class);
bind(UserRESTService.class);
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/4881e5c7/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/patch/PatchRESTService.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/patch/PatchRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/patch/PatchRESTService.java
new file mode 100644
index 0000000..f0de9b6
--- /dev/null
+++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/patch/PatchRESTService.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2016 Glyptodon LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.glyptodon.guacamole.net.basic.rest.patch;
+
+import com.google.inject.Inject;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.glyptodon.guacamole.GuacamoleException;
+import org.glyptodon.guacamole.GuacamoleServerException;
+import org.glyptodon.guacamole.net.basic.extension.PatchResourceService;
+import org.glyptodon.guacamole.net.basic.resource.Resource;
+
+/**
+ * A REST Service for handling the listing of HTML patches.
+ *
+ * @author Michael Jumper
+ */
+@Path("/patches")
+@Produces(MediaType.APPLICATION_JSON)
+public class PatchRESTService {
+
+ /**
+ * Service for retrieving information regarding available HTML patch
+ * resources.
+ */
+ @Inject
+ private PatchResourceService patchResourceService;
+
+ /**
+ * Reads the entire contents of the given resource as a String. The
+ * resource is assumed to be encoded in UTF-8.
+ *
+ * @param resource
+ * The resource to read as a new String.
+ *
+ * @return
+ * A new String containing the contents of the given resource.
+ *
+ * @throws IOException
+ * If an I/O error prevents reading the resource.
+ */
+ private String readResourceAsString(Resource resource) throws IOException {
+
+ StringBuilder contents = new StringBuilder();
+
+ char buffer[] = new char[8192];
+ int length;
+
+ // Read entire resource into StringBuilder one chunk at a time
+ Reader reader = new InputStreamReader(resource.asStream(), "UTF-8");
+ while ((length = reader.read(buffer)) != -1) {
+ contents.append(buffer, 0, length);
+ }
+
+ return contents.toString();
+
+ }
+
+ /**
+ * Returns a list of all available HTML patches, in the order they should
+ * be applied. Each patch is raw HTML containing additional meta tags
+ * describing how and where the patch should be applied.
+ *
+ * @return
+ * A list of all HTML patches defined in the system, in the order they
+ * should be applied.
+ *
+ * @throws GuacamoleException
+ * If an error occurs preventing any HTML patch from being read.
+ */
+ @GET
+ public List<String> getPatches() throws GuacamoleException {
+
+ try {
+
+ // Allocate a list of equal size to the total number of patches
+ List<Resource> resources = patchResourceService.getPatchResources();
+ List<String> patches = new ArrayList<String>(resources.size());
+
+ // Convert each patch resource to a string
+ for (Resource resource : resources) {
+ patches.add(readResourceAsString(resource));
+ }
+
+ // Return all patches in string form
+ return patches;
+
+ }
+
+ // Bail out entirely on error
+ catch (IOException e) {
+ throw new GuacamoleServerException("Unable to read HTML patches.", e);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/4881e5c7/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/patch/package-info.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/patch/package-info.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/patch/package-info.java
new file mode 100644
index 0000000..49a9793
--- /dev/null
+++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/patch/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2016 Glyptodon LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * Classes related to the HTML patch retrieval aspect of the Guacamole REST API.
+ */
+package org.glyptodon.guacamole.net.basic.rest.patch;
+