Reverting local HTTP gateway back from HTTPS to HTTP; there was a change regarding...
[iot2.git] / iotjava / iotruntime / stub / IoTRemoteCall.java
index 0b261ffb1a1d8d01e39cc96ff5eea1a59057dda5..359b8754c01a6e6ef3ddfb7b3b639b706f2fdd67 100644 (file)
@@ -4,23 +4,13 @@ package iotruntime.stub;
 import com.sun.net.httpserver.HttpExchange;
 import com.sun.net.httpserver.HttpHandler;
 import com.sun.net.httpserver.HttpServer;
-import com.sun.net.httpserver.HttpsServer;
-import com.sun.net.httpserver.HttpsConfigurator;
-import com.sun.net.httpserver.HttpsParameters;
 
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 
 import java.net.InetSocketAddress;
-import java.security.KeyStore;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.SSLParameters;
-import javax.net.ssl.TrustManagerFactory;
 
 import java.lang.Class;
 import java.lang.reflect.*;
@@ -51,77 +41,33 @@ public class IoTRemoteCall {
        final private Class _interface;
        final private Object _callback;
        final private int iPort;
-       final private String strAddress;
        private static final Logger logger = Logger.getLogger(IoTRemoteCall.class.getName());
 
        /**
         * IoTRemoteCall class constants
         */
        private final String USER_AGENT = "Mozilla/5.0";
-       private final String PASSWORD = "password";
-       private final String KEYEXT = ".jks";
-       private final String KEYTYPE = "SunX509";
-       private final String KEYINSTANCE = "JKS";
 
        /**
         * Constructor
         */
-       public IoTRemoteCall(Class _interface, Object _callback, int _iPort, String _strAddress) {
+       public IoTRemoteCall(Class _interface, Object _callback, int iPort) {
 
-               this._interface = _interface;
-               this._callback = _callback;
-               this.iPort = _iPort;
-               this.strAddress = _strAddress;
-               startHttpsServer();
+               this._interface=_interface;
+               this._callback=_callback;
+               this.iPort=iPort;
+               startHttpServer();
        }
 
        /**
         * Get Objects from a HTTP request
         */
-       private void startHttpsServer() {
+       private void startHttpServer() {
                // Run a separate thread as the HTTP server
                IncomingMessageHandler imh=new IncomingMessageHandler(_interface, _callback);
     
                try {
-                       HttpsServer server = HttpsServer.create(new InetSocketAddress(iPort), 0);
-                       SSLContext sslContext = SSLContext.getInstance("TLS");
-
-            // initialise the keystore
-            char[] password = PASSWORD.toCharArray();
-            KeyStore ks = KeyStore.getInstance(KEYINSTANCE);
-            FileInputStream fis = new FileInputStream(strAddress + KEYEXT);
-            ks.load(fis, password);
-
-            // setup the key manager factory
-            KeyManagerFactory kmf = KeyManagerFactory.getInstance(KEYTYPE);
-            kmf.init(ks, password);
-
-            // setup the trust manager factory
-            TrustManagerFactory tmf = TrustManagerFactory.getInstance(KEYTYPE);
-            tmf.init(ks);
-
-            // setup the HTTPS context and parameters
-            sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
-            server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
-                public void configure(HttpsParameters params) {
-                    try {
-                        // initialise the SSL context
-                        SSLContext c = SSLContext.getDefault();
-                        SSLEngine engine = c.createSSLEngine();
-                        params.setNeedClientAuth(false);
-                        params.setCipherSuites(engine.getEnabledCipherSuites());
-                        params.setProtocols(engine.getEnabledProtocols());
-
-                        // get the default parameters
-                        SSLParameters defaultSSLParameters = c.getDefaultSSLParameters();
-                        params.setSSLParameters(defaultSSLParameters);
-
-                    } catch (Exception ex) {
-                        ex.printStackTrace();
-                    }
-                }
-            });
-
+                       HttpServer server = HttpServer.create(new InetSocketAddress(iPort), 0);
                        // Context name is according to method name, e.g. getRingStatus
                        Class<?> inter=_interface;
                        for (Method m:inter.getDeclaredMethods()) {
@@ -129,7 +75,7 @@ public class IoTRemoteCall {
                        }
                        server.setExecutor(null); // creates a default executor
                        server.start();
-               } catch (Exception ex) {
+               } catch (IOException ex) {
                        ex.printStackTrace();
                }
        }
@@ -169,7 +115,6 @@ public class IoTRemoteCall {
                System.out.println(uri);
                        try {
                                String strJSONString = sbResponse.toString();
-                               System.out.println(strJSONString);
                                Class[][] cr = new Class[1][];
                                Object[] params = decodeJSONArray(strJSONString,cr);
 
@@ -457,13 +402,14 @@ public class IoTRemoteCall {
 
   
   
+       /* TODO: Uncomment this if we want to do HTTP gateway test
        public static void main(String[] args) throws Exception {
 
        Fooimpl fooimp = new Fooimpl();
                //IoTRemoteCall iotremcall = new IoTRemoteCall(foo.class, new Fooimpl(), 8000);
                new Thread() {
                        public void run() {
-                               IoTRemoteCall iotremcall = new IoTRemoteCall(foo.class, fooimp, 8000, "192.168.2.244"); 
+                               IoTRemoteCall iotremcall = new IoTRemoteCall(foo.class, fooimp, 8000);  
                        }
                }.start();
                System.out.println("server has started!");
@@ -477,5 +423,6 @@ public class IoTRemoteCall {
                //      }
                //}
 
-       }
+       }*/
 }
+