mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
#268: Implement connection creation.
This commit is contained in:
@@ -19,11 +19,16 @@ package net.sourceforge.guacamole.net.basic.crud.connections;
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.net.auth.Connection;
|
||||
import net.sourceforge.guacamole.net.auth.Directory;
|
||||
import net.sourceforge.guacamole.net.auth.UserContext;
|
||||
import net.sourceforge.guacamole.net.basic.AuthenticatingHttpServlet;
|
||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||
|
||||
/**
|
||||
* Simple HttpServlet which handles connection creation.
|
||||
@@ -32,13 +37,58 @@ import net.sourceforge.guacamole.net.basic.AuthenticatingHttpServlet;
|
||||
*/
|
||||
public class Create extends AuthenticatingHttpServlet {
|
||||
|
||||
/**
|
||||
* Prefix given to a parameter name when that parameter is a protocol-
|
||||
* specific parameter meant for the configuration.
|
||||
*/
|
||||
public static final String PARAMETER_PREFIX = "_";
|
||||
|
||||
@Override
|
||||
protected void authenticatedService(
|
||||
UserContext context,
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
|
||||
/* FIXME: STUB */
|
||||
// Get ID and protocol
|
||||
String identifier = request.getParameter("id");
|
||||
String protocol = request.getParameter("protocol");
|
||||
|
||||
try {
|
||||
|
||||
// Attempt to get connection directory
|
||||
Directory<String, Connection> directory =
|
||||
context.getConnectionDirectory();
|
||||
|
||||
// Create config
|
||||
GuacamoleConfiguration config = new GuacamoleConfiguration();
|
||||
config.setProtocol(protocol);
|
||||
|
||||
// Load parameters into config
|
||||
Enumeration<String> params = request.getParameterNames();
|
||||
while (params.hasMoreElements()) {
|
||||
|
||||
// If parameter starts with prefix, load corresponding parameter
|
||||
// value into config
|
||||
String param = params.nextElement();
|
||||
if (param.startsWith(PARAMETER_PREFIX))
|
||||
config.setParameter(
|
||||
param.substring(PARAMETER_PREFIX.length()),
|
||||
request.getParameter(param));
|
||||
|
||||
}
|
||||
|
||||
// Create connection skeleton
|
||||
Connection connection = new DummyConnection();
|
||||
connection.setIdentifier(identifier);
|
||||
connection.setConfiguration(config);
|
||||
|
||||
// Add connection
|
||||
directory.add(connection);
|
||||
|
||||
}
|
||||
catch (GuacamoleException e) {
|
||||
throw new ServletException("Unable to create connection.", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user