Skip to content

Commit 6c75890

Browse files
committed
Allow JAVA console to work over http
1 parent 39c8d42 commit 6c75890

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

java/com/citrix/xenserver/console/Main.java

+9-17
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public Main(String[] args, ConnectionListener listener,
6363

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

7980
public void connect() {
8081
try {
81-
if (usessl) {
82-
stream_.disconnect();
83-
URL uri = new URL(path);
84-
String uuid = auth;
85-
RawHTTP http = new RawHTTP("CONNECT", uri.getHost(), 443, uri
86-
.getPath().concat("?").concat(uri.getQuery()), uuid,
87-
"https".equals(uri.getProtocol()), _listener, _console);
88-
http.connect();
89-
stream_.connect(http, new char[0]);
90-
} else {
91-
stream_.disconnect();
92-
String password = auth;
93-
int n = password.length();
94-
char[] c = new char[n];
95-
password.getChars(0, n, c, 0);
96-
stream_.connectSocket(new Socket(path, port), c);
97-
}
82+
stream_.disconnect();
83+
URL uri = new URL(path);
84+
String uuid = auth;
85+
RawHTTP http = new RawHTTP("CONNECT", uri.getHost(), port,
86+
uri.getPath().concat("?").concat(uri.getQuery()), uuid,
87+
"https".equals(uri.getProtocol()), _listener, _console);
88+
http.connect();
89+
stream_.connect(http, new char[0]);
9890
} catch (final Throwable t) {
9991
if (_listener != null) {
10092
SwingUtilities.invokeLater(new Runnable() {

java/com/citrix/xenserver/console/examples/Standalone.java

+19-6
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void valueChanged(ListSelectionEvent arg0) {
159159
return scroll;
160160
}
161161

162-
private void showVmConsole(int firstIndex) throws BadServerResponse, XenAPIException, XmlRpcException {
162+
private void showVmConsole(int firstIndex) throws BadServerResponse, XenAPIException, XmlRpcException, Exception {
163163

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

173173
System.out.println("Session reference: "+conn.getSessionReference());
174174
String location = c.getLocation(conn);
175-
System.out.println("Setting up terminal connection to "+location+" for VM "+vm);
176-
177-
// location = server_url.getText()+"/"+location.substring(location.indexOf("console?"));
178-
// System.out.println("Setting up terminal connection to "+location+" for VM "+vm);
179175

176+
URL consoleURL = new URL(location);
177+
URL connURL = new URL(server_url.getText());
178+
if ("".equals(consoleURL.getHost())) {
179+
// If console URL is missing the host, HMN may be disabled.
180+
// Use http and host from the original connection in this case
181+
location = "http://" + connURL.getHost() + consoleURL.getFile();
182+
System.out.println("HMN appears disabled. Fixing location to " + location);
183+
consoleURL = new URL(location);
184+
}
185+
System.out.println("Setting up terminal connection to "+location+" for VM "+vm);
186+
187+
String usessl = "false";
188+
String port = "80";
189+
if ("https".equals(consoleURL.getProtocol())) {
190+
usessl = "true";
191+
port = "443";
192+
}
180193
JavaInitialize ji = new JavaInitialize();
181-
ji.init(new String[] {location, conn.getSessionReference(), "true"});
194+
ji.init(new String[] {location, conn.getSessionReference(), usessl, port});
182195
ji.start();
183196
ji.setSize(800,600);
184197
ji.setVisible(true);

0 commit comments

Comments
 (0)