From 4df635e4074f1fb8b8e4c5b37025dabf11f380db Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Mon, 2 Sep 2013 19:20:30 -0700 Subject: [PATCH] Ticket #362: Super basic REST endpoint exposed with Guice and Jersey. --- guacamole/pom.xml | 28 ++++++++++ .../rest/RESTServletContextListener.java | 52 +++++++++++++++++++ .../rest/connection/ConnectionService.java | 24 +++++++++ guacamole/src/main/webapp/WEB-INF/web.xml | 14 +++++ 4 files changed, 118 insertions(+) create mode 100644 guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletContextListener.java create mode 100644 guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionService.java diff --git a/guacamole/pom.xml b/guacamole/pom.xml index df7115cbd..1fba0a374 100644 --- a/guacamole/pom.xml +++ b/guacamole/pom.xml @@ -110,6 +110,34 @@ 1.6.1 runtime + + + + com.google.inject + guice + 3.0 + + + + + com.google.inject.extensions + guice-servlet + 3.0 + + + + + com.sun.jersey + jersey-server + 1.7 + + + + + com.sun.jersey.contribs + jersey-guice + 1.7 + diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletContextListener.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletContextListener.java new file mode 100644 index 000000000..ea59621ca --- /dev/null +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletContextListener.java @@ -0,0 +1,52 @@ +package org.glyptodon.guacamole.net.basic.rest; + +/* + * Guacamole - Clientless Remote Desktop + * Copyright (C) 2010 Michael Jumper + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import com.google.inject.Guice; +import com.google.inject.servlet.ServletModule; +import com.sun.jersey.guice.spi.container.servlet.GuiceContainer; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import org.glyptodon.guacamole.net.basic.rest.connection.ConnectionService; + +/** + * A ServletContextListenr to listen for initialization of the servlet context + * in order to set up the REST services. + * + * @author James Muehlner + */ +public class RESTServletContextListener implements ServletContextListener { + + @Override + public void contextInitialized(ServletContextEvent sce) { + Guice.createInjector(new ServletModule() { + @Override + protected void configureServlets() { + + bind(ConnectionService.class); + + serve("*").with(GuiceContainer.class); + } + }); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) {} + +} diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionService.java new file mode 100644 index 000000000..f784113d0 --- /dev/null +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionService.java @@ -0,0 +1,24 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.glyptodon.guacamole.net.basic.rest.connection; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * A REST Service for handling connection CRUD operations. + * + * @author James Muehlner + */ +@Path("/api/connection") +public class ConnectionService { + + @Path("/") + @GET + public String getConnections() { + return "goo"; + } + +} diff --git a/guacamole/src/main/webapp/WEB-INF/web.xml b/guacamole/src/main/webapp/WEB-INF/web.xml index 728d5e699..b02dc535d 100644 --- a/guacamole/src/main/webapp/WEB-INF/web.xml +++ b/guacamole/src/main/webapp/WEB-INF/web.xml @@ -241,6 +241,20 @@ Tunnel /tunnel + + + guiceFilter + com.google.inject.servlet.GuiceFilter + + + + guiceFilter + /api/* + + + + org.glyptodon.guacamole.net.basic.rest.RESTServletContextListener + mp3