Reverting local HTTP gateway back from HTTPS to HTTP; there was a change regarding...
authorrtrimana <rtrimana@uci.edu>
Thu, 1 Feb 2018 22:37:32 +0000 (14:37 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 1 Feb 2018 22:37:32 +0000 (14:37 -0800)
16 files changed:
benchmarks/drivers/Java/GPSPhoneGateway/GPSPhoneGateway.java
benchmarks/drivers/Java/WeatherPhoneGateway/WeatherPhoneGateway.java
benchmarks/other/PhoneInterface/Irrigation/app/src/main/java/com/example/xubin/irrigation/Helper.java
benchmarks/other/PhoneInterface/Irrigation/app/src/main/java/com/example/xubin/irrigation/MainActivity.java
benchmarks/other/PhoneInterface/Irrigation/app/src/main/res/layout/content_main.xml
benchmarks/other/PhoneInterface/Irrigation/app/src/main/res/values/strings.xml
benchmarks/other/PhoneInterface/Irrigation/build.gradle
benchmarks/other/PhoneInterface/Irrigation/gradle/wrapper/gradle-wrapper.properties
benchmarks/other/PhoneInterface/SpeakerLocator/app/Libs/indoor-positioning-1.1.jar [new file with mode: 0644]
benchmarks/other/PhoneInterface/SpeakerLocator/app/build.gradle
benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/java/com/example/xub3/speakerlocator/Helper.java
benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/java/com/example/xub3/speakerlocator/MainActivity.java
benchmarks/other/PhoneInterface/SpeakerLocator/app/src/main/res/values/strings.xml
benchmarks/other/PhoneInterface/SpeakerLocator/build.gradle
benchmarks/other/PhoneInterface/SpeakerLocator/gradle/wrapper/gradle-wrapper.properties
iotjava/iotruntime/stub/IoTRemoteCall.java

index 404292bfd55dc1ab4aa35196ae4098a137d7a29c..7f401ae35a6b3fed8cbcb8833c3f8ce0aa6f5085 100644 (file)
@@ -83,10 +83,17 @@ public class GPSPhoneGateway implements GPSGateway {
 
                // Launch IoTRemoteCall server in a separate thread
                workerThread = new Thread(new Runnable() {
+                       /* TODO: We revert back to HTTP because of new scheme for TLS context in Android 7
+                       This disrupts the usual setting for self-signed certificate
+                       See this link for more info: https://github.com/owntracks/android/issues/481
                        public void run() {
                                iotRemCall = new IoTRemoteCall(PhoneInfoInterface.class, 
                                        phoneInfo, iotDevAdd.getDestinationPortNumber(),
                                        IoTDeviceAddress.getLocalHostAddress());
+                       }*/
+                       public void run() {
+                               iotRemCall = new IoTRemoteCall(PhoneInfoInterface.class, 
+                                       phoneInfo, iotDevAdd.getDestinationPortNumber());
                        }
                });
                workerThread.start();
index 50b44508c08a749473d0db1556b45d15159e2886..7ac5b85be439da3b652cf1c6ecc532db1994a218 100644 (file)
@@ -101,10 +101,17 @@ public class WeatherPhoneGateway implements WeatherGateway {
 
                // Launch IoTRemoteCall server in a separate thread
                workerThread = new Thread(new Runnable() {
+                       /* TODO: We revert back to HTTP because of new scheme for TLS context in Android 7
+                       This disrupts the usual setting for self-signed certificate
+                       See this link for more info: https://github.com/owntracks/android/issues/481
                        public void run() {
                                iotRemCall = new IoTRemoteCall(WeatherInfoInterface.class, 
                                        weatherInfo, iotDevAdd.getDestinationPortNumber(),
                                        IoTDeviceAddress.getLocalHostAddress());
+                       }*/
+                       public void run() {
+                               iotRemCall = new IoTRemoteCall(WeatherInfoInterface.class, 
+                               weatherInfo, iotDevAdd.getDestinationPortNumber());
                        }
                });
                workerThread.start();
index 2ff9b49ab315c1091703df784e8c6b2475d3a83e..77f4ccf7a981370b1ec36ccdb961918af256a7e1 100644 (file)
@@ -10,7 +10,6 @@ import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.scheme.PlainSocketFactory;
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
@@ -26,12 +25,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.BufferedInputStream;
 import java.util.List;
-import java.security.cert.CertificateFactory;
-import java.security.cert.Certificate;
-import java.security.cert.X509Certificate;
-import java.security.KeyStore;
 
 /**
  * Created by xubin on 4/26/16.
@@ -39,16 +33,13 @@ import java.security.KeyStore;
 public class Helper {
     private static final int Driver_port = 8000;
     private static final String Tag = "http";
-    private static final String KEYEXT = ".pem";
 
     HttpClient httpclient;
     //Set up
-    void setConnection(String destIP) {
-
-        httpclient = createClient(destIP);
+    void setConnection() {
+        httpclient = createClient();
     }
-
-    HttpClient createClient(String destIP) {
+    HttpClient createClient() {
         HttpParams params = new BasicHttpParams();
         params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
         params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.DEFAULT_CONTENT_CHARSET);
@@ -58,22 +49,21 @@ public class Helper {
 
         SchemeRegistry schReg = new SchemeRegistry();
         schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Driver_port));
-        schReg.register(new Scheme("https", newSslSocketFactory(destIP), 443));
+        //schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
         ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
 
         return new DefaultHttpClient(conMgr, params);
     }
-
     //Make http request
     public void  makeRequest(String destIP, List<Object> paramObjects, String methodName) {
-        String url = "https://"+ destIP + ":"+Driver_port+ "/"+methodName;
-        System.out.println("URL: " + url);
+        String url = "http://"+ destIP + ":"+Driver_port+ "/"+methodName;
         InputStream inputStream = null;
         String result = "";
         try {
             HttpPost httpPost = new HttpPost(url);
             JSONArray params = new JSONArray();
 
+
             JSONObject parent = new JSONObject();
             for (int i = 0; i < paramObjects.size(); i++) {
                 JSONObject content = new JSONObject();
@@ -103,31 +93,6 @@ public class Helper {
             ex.printStackTrace();
         }
     }
-
-    private SSLSocketFactory newSslSocketFactory(String destIP) {
-        try {
-            // Load CAs from an InputStream
-            CertificateFactory cf = CertificateFactory.getInstance("X.509");
-            InputStream caInput = new
-                    BufferedInputStream(MainActivity.context.getAssets().open(destIP + KEYEXT));
-            Certificate ca;
-            try {
-                ca = cf.generateCertificate(caInput);
-                System.out.println("ca=" + ((X509Certificate) ca).getSubjectDN());
-            } finally {
-                caInput.close();
-            }
-            String keyStoreType = KeyStore.getDefaultType();
-            KeyStore keyStore = KeyStore.getInstance(keyStoreType);
-            keyStore.load(null, null);
-            keyStore.setCertificateEntry("ca", ca);
-            SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore);
-            return socketFactory;
-        } catch (Exception e) {
-            throw new AssertionError(e);
-        }
-    }
-
     private static String convertInputStreamToString(InputStream inputStream) throws IOException {
         BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
         String line = "";
index 65c7c34dc70db66646248c4a717fbeb68d629d54..ba573ecda8ba88b2dd1712bce2d33c50d1530424 100644 (file)
@@ -11,20 +11,17 @@ import android.view.Menu;
 import android.view.MenuItem;
 import android.widget.Button;
 import android.widget.EditText;
-import android.content.Context;
 
 import java.util.ArrayList;
 import java.util.List;
 
 public class MainActivity extends AppCompatActivity {
 
-    private EditText gatewayIP;
     private EditText inchesPerWeek;
     private EditText weatherZipCode;
     private EditText daysToWaterOn;
     private EditText inchesPerMinute;
     private Button submit_button;
-    protected static Context context;
     private Helper helper = new Helper();
 
     @Override
@@ -33,8 +30,6 @@ public class MainActivity extends AppCompatActivity {
         setContentView(R.layout.activity_main);
         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
-        context = getApplicationContext();
-        gatewayIP = (EditText) findViewById(R.id.gatewayip);
         inchesPerWeek = (EditText) findViewById(R.id.week);
         weatherZipCode = (EditText) findViewById(R.id.zip);
         daysToWaterOn = (EditText) findViewById(R.id.water);
@@ -50,7 +45,7 @@ public class MainActivity extends AppCompatActivity {
                 params.add(Integer.parseInt(daysToWaterOn.getText().toString()));
                 params.add(Double.parseDouble(inchesPerMinute.getText().toString()));
 
-                String ip = gatewayIP.getText().toString();
+                String ip = getApplicationContext().getResources().getString(R.string.destination_ip);
                 new MakeRequestTask(params).execute(ip, "getIrrigationInfo");
 
             }
@@ -65,7 +60,6 @@ public class MainActivity extends AppCompatActivity {
         });
     }
 
-
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         // Inflate the menu; this adds items to the action bar if it is present.
@@ -95,11 +89,9 @@ public class MainActivity extends AppCompatActivity {
         @Override
         protected Void doInBackground(String... argus) {
             if (helper.httpclient == null) {
-                helper.setConnection(argus[0]);
+                helper.setConnection();
             }
-
             helper.makeRequest(argus[0],params, argus[1]);
-
             return null;
         }
     }
index 53eecbf1398fca993bd3a5e3f9ec52806c7513cd..facc2b015a6463c11337a76710e458333513ab00 100644 (file)
         android:layout_weight="1"
         android:ems="10"
         android:inputType="number|numberDecimal"
-        android:text="192.168.0.84" />
+        android:text="192.168.2.191" />
 </RelativeLayout>
index 56f8e53b9888f0d1435ddfc064baea7ccf2f0588..2b20a3d478cfcb2a2a003051e2f6f40998bfed64 100644 (file)
@@ -1,5 +1,5 @@
 <resources>
     <string name="app_name">Irrigation</string>
     <string name="action_settings">Settings</string>
-    <string name="destination_ip">192.168.2.244</string>
+    <string name="destination_ip">192.168.2.191</string>
 </resources>
index c2eea8e27fd12cc1e274a0940f06f350e855e20f..a47fa4bbf6730c7d1269737564381c8464224713 100644 (file)
@@ -5,7 +5,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.3.3'
+        classpath 'com.android.tools.build:gradle:3.0.1'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
index 39c428071f28b9463da3f12df214015eee9e8014..7041afd8db7ccf8986d3e6185bf4525401c0d6f7 100644 (file)
@@ -1,6 +1,6 @@
-#Tue Jan 16 09:22:38 PST 2018
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+#Fri Jan 19 14:40:37 PST 2018\r
+distributionBase=GRADLE_USER_HOME\r
+distributionPath=wrapper/dists\r
+zipStoreBase=GRADLE_USER_HOME\r
+zipStorePath=wrapper/dists\r
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip\r
diff --git a/benchmarks/other/PhoneInterface/SpeakerLocator/app/Libs/indoor-positioning-1.1.jar b/benchmarks/other/PhoneInterface/SpeakerLocator/app/Libs/indoor-positioning-1.1.jar
new file mode 100644 (file)
index 0000000..21ca4c0
Binary files /dev/null and b/benchmarks/other/PhoneInterface/SpeakerLocator/app/Libs/indoor-positioning-1.1.jar differ
index d56e24368d1a38242f3a1cb29fd2d41a4d6d3d97..b860e1ca53df4959e41af4aac92d37ad89e38452 100644 (file)
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
 
 android {
     compileSdkVersion 23
-    buildToolsVersion '25.0.0'
+    buildToolsVersion '26.0.2'
     useLibrary 'org.apache.http.legacy'
     defaultConfig {
         applicationId "com.example.xub3.speakerlocator"
@@ -25,6 +25,7 @@ dependencies {
     testCompile 'junit:junit:4.12'
     compile 'com.android.support:appcompat-v7:23.3.0'
     compile 'com.android.support:design:23.3.0'
-    compile files('Libs/indoor-positioning-1.0.jar')
+    compile files('Libs/indoor-positioning-1.1.jar')
     compile 'com.google.android.gms:play-services-appindexing:8.1.0'
+    implementation files('Libs/indoor-positioning-1.1.jar')
 }
index c5997813b7e51e3a3d559463900e126bce739b61..0d57b85da233ac623d012a93ee8f0d6e1e6fcc67 100644 (file)
@@ -37,105 +37,78 @@ import java.security.cert.X509Certificate;
  * Created by xub3 on 4/14/16.
  */
 public class Helper {
-       private static final int Driver_port = 8000;
-       private static final String Tag = "CallReceiver";
-       private static final String KEYEXT = ".pem";
-       HttpClient httpclient;
-       //Set up
-       //Set up
-       void setConnection(String destIP) {
-
-               httpclient = createClient(destIP);
-       }
-
-       HttpClient createClient(String destIP) {
-               HttpParams params = new BasicHttpParams();
-               params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
-               params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.DEFAULT_CONTENT_CHARSET);
-               params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
-               params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30 * 1000);
-               params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 30 * 1000);
-
-               SchemeRegistry schReg = new SchemeRegistry();
-               schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Driver_port));
-               schReg.register(new Scheme("https", newSslSocketFactory(destIP), 443));
-               ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
-
-               return new DefaultHttpClient(conMgr, params);
-       }
-
-       private SSLSocketFactory newSslSocketFactory(String destIP) {
-               try {
-                       // Load CAs from an InputStream
-                       CertificateFactory cf = CertificateFactory.getInstance("X.509");
-                       InputStream caInput = new
-                                       BufferedInputStream(MainActivity.context.getAssets().open(destIP + KEYEXT));
-                       Certificate ca;
-                       try {
-                               ca = cf.generateCertificate(caInput);
-                               System.out.println("ca=" + ((X509Certificate) ca).getSubjectDN());
-                       } finally {
-                               caInput.close();
-                       }
-                       String keyStoreType = KeyStore.getDefaultType();
-                       KeyStore keyStore = KeyStore.getInstance(keyStoreType);
-                       keyStore.load(null, null);
-                       keyStore.setCertificateEntry("ca", ca);
-                       SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore);
-                       return socketFactory;
-               } catch (Exception e) {
-                       throw new AssertionError(e);
-               }
-       }
-
-       //Make http request
-       public void  makeRequest(String destIP, Object contentStr, String methodName) {
-               String url = "https://"+ destIP+":" + Driver_port + "/"+methodName;
-               System.out.println("URL: " + url);
-
-               InputStream inputStream = null;
-               String result = "";
-                       StringBuilder sb = new StringBuilder();
-                       try {
-                               HttpPost httpPost = new HttpPost(url);
-                               JSONArray params = new JSONArray();
-
-                               JSONObject content = new JSONObject();
-                               JSONObject parent = new JSONObject();
-                               content.put("type", contentStr.getClass().getName());
-                               content.put("value", contentStr);
-                               params.put(0,content);
-                               parent.put("params", params);
-                               StringEntity se = new StringEntity(parent.toString());
-                               httpPost.setEntity(se);
-                               httpPost.setHeader("Accept", "application/json");
-                               httpPost.setHeader("Content-type", "application/json");
-                               HttpResponse httpResponse = httpclient.execute(httpPost);
-                               // 9. receive response as inputStream
-                               inputStream = httpResponse.getEntity().getContent();
-
-                               // 10. convert inputstream to string
-                               if(inputStream != null)
-                                       result = convertInputStreamToString(inputStream);
-                               else
-                                       result = "Did not work!";
-                               Log.v(Tag, result);
-                       } catch (Exception ex) {
-                               if (ex.getMessage() != null) {
-                                       Log.v(Tag, ex.getMessage());
-                               }
-                               ex.printStackTrace();
-                       }
-               }
-       private static String convertInputStreamToString(InputStream inputStream) throws IOException{
-               BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
-               String line = "";
-               String result = "";
-               while((line = bufferedReader.readLine()) != null)
-                       result += line;
-
-               inputStream.close();
-               return result;
-       }
+    private static final int Driver_port = 8000;
+    private static final String Tag = "CallReceiver";
+    HttpClient httpclient;
+    //Set up
+    void setConnection() {
+        httpclient = createClient();
+    }
+    HttpClient createClient() {
+        HttpParams params = new BasicHttpParams();
+        params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
+        params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.DEFAULT_CONTENT_CHARSET);
+        params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
+        params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30 * 1000);
+        params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 30 * 1000);
+
+        SchemeRegistry schReg = new SchemeRegistry();
+        schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 8000));
+        ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
+
+        return new DefaultHttpClient(conMgr, params);
+    }
+
+    //Make http request
+    public void  makeRequest(String destIP, Object contentStr, String methodName) {
+        String url = "http://"+ destIP+":" + Driver_port + "/"+methodName;
+
+
+        InputStream inputStream = null;
+        String result = "";
+        StringBuilder sb = new StringBuilder();
+        try {
+            HttpPost httpPost = new HttpPost(url);
+            JSONArray params = new JSONArray();
+
+            JSONObject content = new JSONObject();
+            JSONObject parent = new JSONObject();
+            content.put("type", contentStr.getClass().getName());
+            content.put("value", contentStr);
+            params.put(0,content);
+            parent.put("params", params);
+            StringEntity se = new StringEntity(parent.toString());
+            httpPost.setEntity(se);
+            httpPost.setHeader("Accept", "application/json");
+            httpPost.setHeader("Content-type", "application/json");
+            HttpResponse httpResponse = httpclient.execute(httpPost);
+            // 9. receive response as inputStream
+            inputStream = httpResponse.getEntity().getContent();
+
+            // 10. convert inputstream to string
+            if(inputStream != null)
+                result = convertInputStreamToString(inputStream);
+            else
+                result = "Did not work!";
+            Log.v(Tag, result);
+        } catch (Exception ex) {
+            if (ex.getMessage() != null) {
+                Log.v(Tag, ex.getMessage());
+            }
+            ex.printStackTrace();
+        }
+    }
+
+    private static String convertInputStreamToString(InputStream inputStream) throws IOException{
+        BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
+        String line = "";
+        String result = "";
+        while((line = bufferedReader.readLine()) != null)
+            result += line;
+
+        inputStream.close();
+        return result;
+
+    }
 }
 
index a8b6b9287b7a7ffe8778ea3f4060e6e59f8d95a5..a12a1f7fee786e2753d261a532f76fbdc69a8574 100644 (file)
@@ -67,9 +67,9 @@ public class MainActivity extends AppCompatActivity implements PositionListener
                initializePositioning();
                FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
                tv = (TextView) findViewById(R.id.hellotext);
-//             if (helper.httpclient == null) {
-//                     helper.setConnection(getApplicationContext().getResources().getString(R.string.gateway_ip));
-//             }
+               if (helper.httpclient == null) {
+                       helper.setConnection();
+               }
                fab.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
@@ -120,7 +120,7 @@ public class MainActivity extends AppCompatActivity implements PositionListener
                File file = new File(Environment.getExternalStorageDirectory(), "positioningPersistence.xml");
                try {
                        positionManager = new PositionManager(file);
-                       //Log.d("positionManager", "initialized");
+                       Log.d("positionManager", "initialized");
                        //System.out.println("PositionManager: Initialized successfully!");
                } catch (PositioningPersistenceException e) {
                        e.printStackTrace();
index c87cf7f9128f7d11ab2a6b7f3992e13c82886bee..d05272a619b5a1f8270f8c425f91a55325b7ae88 100644 (file)
@@ -1,7 +1,7 @@
 <resources>
     <string name="app_name">SpeakerLocator</string>
     <string name="action_settings">Settings</string>
-    <string name="gateway_ip">192.168.0.84</string>
+    <string name="gateway_ip">192.168.2.191</string>
     <string name="mac_1">b0:b9:8a:73:69:f4</string>
     <string name="mac_2">b0:b9:8a:73:69:f3</string>
     <string name="mac_3">00:24:98:9a:92:ef</string>
index c2eea8e27fd12cc1e274a0940f06f350e855e20f..a47fa4bbf6730c7d1269737564381c8464224713 100644 (file)
@@ -5,7 +5,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.3.3'
+        classpath 'com.android.tools.build:gradle:3.0.1'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
index 1dd327cc67c9b282749f1d2f9e018a47b4cea6bb..f1a51cdb64a705ee3c3c95176afa463f293b6663 100644 (file)
@@ -1,6 +1,6 @@
-#Tue Jan 16 09:33:57 PST 2018
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+#Fri Jan 19 15:48:36 PST 2018\r
+distributionBase=GRADLE_USER_HOME\r
+distributionPath=wrapper/dists\r
+zipStoreBase=GRADLE_USER_HOME\r
+zipStorePath=wrapper/dists\r
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip\r
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 {
                //      }
                //}
 
-       }
+       }*/
 }
+