Ticket #362: Super basic REST endpoint exposed with Guice and Jersey.

This commit is contained in:
James Muehlner
2013-09-02 19:20:30 -07:00
parent e4b90703be
commit 4df635e407
4 changed files with 118 additions and 0 deletions

View File

@@ -110,6 +110,34 @@
<version>1.6.1</version> <version>1.6.1</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<!-- Guice - Dependency Injection -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
<!-- Guice Servlet -->
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>3.0</version>
</dependency>
<!-- Jersey - JAX-RS Implementation -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.7</version>
</dependency>
<!-- Jersey - Guice extension -->
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-guice</artifactId>
<version>1.7</version>
</dependency>
<!-- Guacamole Java API --> <!-- Guacamole Java API -->
<dependency> <dependency>

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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) {}
}

View File

@@ -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";
}
}

View File

@@ -241,6 +241,20 @@
<servlet-name>Tunnel</servlet-name> <servlet-name>Tunnel</servlet-name>
<url-pattern>/tunnel</url-pattern> <url-pattern>/tunnel</url-pattern>
</servlet-mapping> </servlet-mapping>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/api/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.glyptodon.guacamole.net.basic.rest.RESTServletContextListener</listener-class>
</listener>
<mime-mapping> <mime-mapping>
<extension>mp3</extension> <extension>mp3</extension>