Skip to content

Commit

Permalink
Allow JAVA console to work over http
Browse files Browse the repository at this point in the history
  • Loading branch information
santoshj committed May 10, 2013
1 parent 39c8d42 commit 6c75890
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
26 changes: 9 additions & 17 deletions java/com/citrix/xenserver/console/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public Main(String[] args, ConnectionListener listener,

if ("true".equals(args[2])) {
usessl = true;
port = 443;
} else {
usessl = false;
port = Integer.parseInt(args[3]);
Expand All @@ -78,23 +79,14 @@ public Main(String[] args, ConnectionListener listener,

public void connect() {
try {
if (usessl) {
stream_.disconnect();
URL uri = new URL(path);
String uuid = auth;
RawHTTP http = new RawHTTP("CONNECT", uri.getHost(), 443, uri
.getPath().concat("?").concat(uri.getQuery()), uuid,
"https".equals(uri.getProtocol()), _listener, _console);
http.connect();
stream_.connect(http, new char[0]);
} else {
stream_.disconnect();
String password = auth;
int n = password.length();
char[] c = new char[n];
password.getChars(0, n, c, 0);
stream_.connectSocket(new Socket(path, port), c);
}
stream_.disconnect();
URL uri = new URL(path);
String uuid = auth;
RawHTTP http = new RawHTTP("CONNECT", uri.getHost(), port,
uri.getPath().concat("?").concat(uri.getQuery()), uuid,
"https".equals(uri.getProtocol()), _listener, _console);
http.connect();
stream_.connect(http, new char[0]);
} catch (final Throwable t) {
if (_listener != null) {
SwingUtilities.invokeLater(new Runnable() {
Expand Down
25 changes: 19 additions & 6 deletions java/com/citrix/xenserver/console/examples/Standalone.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void valueChanged(ListSelectionEvent arg0) {
return scroll;
}

private void showVmConsole(int firstIndex) throws BadServerResponse, XenAPIException, XmlRpcException {
private void showVmConsole(int firstIndex) throws BadServerResponse, XenAPIException, XmlRpcException, Exception {

// Get the console ID for the VM
VMEntry vm = (VMEntry) model.getElementAt(firstIndex);
Expand All @@ -172,13 +172,26 @@ private void showVmConsole(int firstIndex) throws BadServerResponse, XenAPIExcep

System.out.println("Session reference: "+conn.getSessionReference());
String location = c.getLocation(conn);
System.out.println("Setting up terminal connection to "+location+" for VM "+vm);

// location = server_url.getText()+"/"+location.substring(location.indexOf("console?"));
// System.out.println("Setting up terminal connection to "+location+" for VM "+vm);

URL consoleURL = new URL(location);
URL connURL = new URL(server_url.getText());
if ("".equals(consoleURL.getHost())) {
// If console URL is missing the host, HMN may be disabled.
// Use http and host from the original connection in this case
location = "http://" + connURL.getHost() + consoleURL.getFile();
System.out.println("HMN appears disabled. Fixing location to " + location);
consoleURL = new URL(location);
}
System.out.println("Setting up terminal connection to "+location+" for VM "+vm);

String usessl = "false";
String port = "80";
if ("https".equals(consoleURL.getProtocol())) {
usessl = "true";
port = "443";
}
JavaInitialize ji = new JavaInitialize();
ji.init(new String[] {location, conn.getSessionReference(), "true"});
ji.init(new String[] {location, conn.getSessionReference(), usessl, port});
ji.start();
ji.setSize(800,600);
ji.setVisible(true);
Expand Down

0 comments on commit 6c75890

Please sign in to comment.