Bug 581599 - Add HTTPS implementation

Change-Id: Ic45ceb2e53ae0e0692d6c481cb6ddb9e1e7ca10f
diff --git a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/AcceptThread.java b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/AcceptThread.java
index 55c1c12..79c5632 100644
--- a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/AcceptThread.java
+++ b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/AcceptThread.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2011 IBM Corporation and others.
+ * Copyright (c) 2003, 2023 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
  * which accompanies this distribution, and is available at
@@ -29,8 +29,11 @@
 	protected Thread thread;
 
 	class ServerThread extends Thread {
-		public ServerThread() {
+		private ProtocolAdapter protocolAdapter;
+
+		public ServerThread(ProtocolAdapter protocolAdapter) {
 			super("TCP/IP Monitor");
+			this.protocolAdapter = protocolAdapter;
 		}
 
 		/**
@@ -64,7 +67,7 @@
 
 					try {
 						// connect to the remote server
-						Socket remoteSocket = new Socket();
+						Socket remoteSocket = protocolAdapter.createRemoteSocket();
 						if (timeout != 0)
 							remoteSocket.setSoTimeout(timeout);
 
@@ -109,7 +112,8 @@
 	public void startServer() {
 		if (thread != null)
 			return;
-		thread = new ServerThread();
+		ProtocolAdapter protocolAdapter = getProtocolAdapter();
+		thread = new ServerThread(protocolAdapter);
 		thread.setDaemon(true);
 		thread.setPriority(Thread.NORM_PRIORITY + 1);
 		thread.start();
@@ -146,8 +150,7 @@
 			alive = false;
 			thread = null;
 
-			String protocolId = monitor.getProtocol();
-		   ProtocolAdapter adapter = MonitorPlugin.getInstance().getProtocolAdapter(protocolId);
+			ProtocolAdapter adapter = getProtocolAdapter();
 			adapter.disconnect(monitor);
 			if (serverSocket != null)
 				serverSocket.close();
@@ -184,4 +187,11 @@
 
 		return false;
 	}
+
+
+	private ProtocolAdapter getProtocolAdapter() {
+		String protocolId = monitor.getProtocol();
+		ProtocolAdapter adapter = MonitorPlugin.getInstance().getProtocolAdapter(protocolId);
+		return adapter;
+	}
 }
diff --git a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/ProtocolAdapter.java b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/ProtocolAdapter.java
index b793a1b..5b743d2 100644
--- a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/ProtocolAdapter.java
+++ b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/ProtocolAdapter.java
@@ -14,6 +14,7 @@
 
 import java.io.IOException;
 import java.net.Socket;
+
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitor;
 /**
@@ -76,4 +77,8 @@
 	public void disconnect(IMonitor monitor) throws IOException {
 		getDelegate().disconnect(monitor);
 	}
+
+	public Socket createRemoteSocket() throws IOException {
+		return getDelegate().createRemoteSocket();
+	}
 }
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/ProtocolAdapterDelegate.java b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/ProtocolAdapterDelegate.java
index 284f38c..f805623 100644
--- a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/ProtocolAdapterDelegate.java
+++ b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/ProtocolAdapterDelegate.java
@@ -14,6 +14,7 @@
 
 import java.io.IOException;
 import java.net.Socket;
+
 import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitor;
 /**
  * Abstract base class for protocol adapter delegates, which provide the
@@ -85,4 +86,8 @@
 	 * @throws IOException
 	 */
 	public abstract void disconnect(IMonitor monitor) throws IOException;
+
+	public Socket createRemoteSocket() throws IOException {
+		return new Socket();
+	}
 }
diff --git a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPSProtocolAdapter.java b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPSProtocolAdapter.java
new file mode 100644
index 0000000..7b5f75a
--- /dev/null
+++ b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPSProtocolAdapter.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2023 Erik Brangs and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ *    Erik Brangs - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.internet.monitor.core.internal.http;
+
+import java.io.IOException;
+import java.net.Socket;
+
+import javax.net.ssl.SSLSocketFactory;
+public class HTTPSProtocolAdapter extends HTTPProtocolAdapter {
+
+	public Socket createRemoteSocket() throws IOException {
+		return SSLSocketFactory.getDefault().createSocket();
+	}
+
+}
diff --git a/plugins/org.eclipse.wst.internet.monitor.core/plugin.properties b/plugins/org.eclipse.wst.internet.monitor.core/plugin.properties
index 56a6434..40995bf 100644
--- a/plugins/org.eclipse.wst.internet.monitor.core/plugin.properties
+++ b/plugins/org.eclipse.wst.internet.monitor.core/plugin.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2004, 2005 IBM Corporation and others.
+# Copyright (c) 2004, 2023 IBM Corporation and others.
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License 2.0
 # which accompanies this distribution, and is available at
@@ -18,4 +18,5 @@
 extensionPointStartup=Startup
 
 HTTP=HTTP
-TCPIP=TCP/IP
\ No newline at end of file
+TCPIP=TCP/IP
+HTTPS=HTTPS
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.internet.monitor.core/plugin.xml b/plugins/org.eclipse.wst.internet.monitor.core/plugin.xml
index 5a825fa..a129fb7 100644
--- a/plugins/org.eclipse.wst.internet.monitor.core/plugin.xml
+++ b/plugins/org.eclipse.wst.internet.monitor.core/plugin.xml
@@ -16,6 +16,10 @@
     id="HTTP"
     class="org.eclipse.wst.internet.monitor.core.internal.http.HTTPProtocolAdapter"
     name="%HTTP"/>
+  <protocolAdapter
+    id="HTTPS"
+    class="org.eclipse.wst.internet.monitor.core.internal.http.HTTPSProtocolAdapter"
+    name="%HTTPS"/>
 </extension>
 
 </plugin>
\ No newline at end of file