Deviceless Benchmark
[iotcloud.git] / version2 / src / java / light_fan_embed_fake_benchmark / IoTHTTP.java
diff --git a/version2/src/java/light_fan_embed_fake_benchmark/IoTHTTP.java b/version2/src/java/light_fan_embed_fake_benchmark/IoTHTTP.java
new file mode 100644 (file)
index 0000000..c364c4e
--- /dev/null
@@ -0,0 +1,150 @@
+\r
+// Java packages\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.io.IOException;\r
+import java.net.HttpURLConnection;\r
+import java.net.MalformedURLException;\r
+import java.net.UnknownHostException;\r
+import java.net.URL;\r
+import java.net.ProtocolException;\r
+\r
+\r
+/** Class IoTHTTP is a wrapper class that provides\r
+ *  minimum interfaces for user to interact with IoT\r
+ *  devices in our system\r
+ *\r
+ * @author      Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>\r
+ * @version     1.0\r
+ * @since       2016-02-18\r
+ */\r
+public class IoTHTTP {\r
+\r
+       /**\r
+        * IoTHTTP class properties\r
+        */\r
+       private IoTDeviceAddress iotDevAdd;\r
+       private URL url;\r
+       private HttpURLConnection httpConnection;\r
+\r
+       /**\r
+        * Class constructor\r
+        */\r
+       public IoTHTTP(IoTDeviceAddress _iotDevAdd) {\r
+\r
+               iotDevAdd = _iotDevAdd;\r
+               url = null;\r
+               httpConnection = null;\r
+       }\r
+\r
+       /**\r
+        * setURL() method\r
+        *\r
+        * @param  strUrlComplete  String to complete the URL\r
+        * @return void\r
+        */\r
+       public void setURL(String strUrlComplete) throws MalformedURLException {\r
+\r
+               url = new URL(iotDevAdd.getURL(strUrlComplete));\r
+               System.out.println(url.toString());\r
+\r
+       }\r
+\r
+       /**\r
+        * openConnection() method\r
+        */\r
+       public void openConnection() throws IOException {\r
+\r
+               httpConnection = (HttpURLConnection) url.openConnection();\r
+\r
+       }\r
+\r
+       /**\r
+        * setDoInput() method inherited from HttpURLConnection class\r
+        *\r
+        * @param  bSetDoInput\r
+        * @return void\r
+        */\r
+       public void setDoInput(boolean bSetDoInput) {\r
+\r
+               httpConnection.setDoInput(bSetDoInput);\r
+\r
+       }\r
+\r
+       /**\r
+        * setRequestProperty() method inherited from HttpURLConnection class\r
+        *\r
+        * @param  strProperty             String property\r
+        * @param  strHttpAuthCredentials  String HTTP authentication credentials\r
+        * @return void\r
+        */\r
+       public void setRequestProperty(String strProperty, String strHttpAuthCredentials) {\r
+\r
+               httpConnection.setRequestProperty(strProperty, strHttpAuthCredentials);\r
+\r
+       }\r
+\r
+       /**\r
+        * setRequestMethod() method inherited from HttpURLConnection class\r
+        *\r
+        * @param  strMethod             String method\r
+        * @return void\r
+        */\r
+       public void setRequestMethod(String strMethod) throws ProtocolException {\r
+\r
+               httpConnection.setRequestMethod(strMethod);\r
+\r
+       }\r
+\r
+       /**\r
+        * setDoOutput() method inherited from HttpURLConnection class\r
+        *\r
+        * @param  doOut\r
+        * @return void\r
+        */\r
+       public void setDoOutput(boolean doOut) {\r
+\r
+               httpConnection.setDoOutput(doOut);\r
+\r
+       }\r
+\r
+       /**\r
+        * getOutputStream() method inherited from HttpURLConnection class\r
+        *\r
+        * @return OutputStream\r
+        */\r
+       public OutputStream getOutputStream() throws IOException {\r
+\r
+               return httpConnection.getOutputStream();\r
+\r
+       }\r
+\r
+       /**\r
+        * getInputStream() method inherited from HttpURLConnection class\r
+        *\r
+        * @return InputStream\r
+        */\r
+       public InputStream getInputStream() throws IOException {\r
+\r
+               return httpConnection.getInputStream();\r
+\r
+       }\r
+\r
+       /**\r
+        * connect() method inherited from HttpURLConnection class\r
+        */\r
+       public void connect() throws IOException {\r
+\r
+               httpConnection.connect();\r
+\r
+       }\r
+\r
+       /**\r
+        * disconnect() method inherited from HttpURLConnection class\r
+        */\r
+       public void disconnect() throws IOException {\r
+\r
+               httpConnection.disconnect();\r
+\r
+       }\r
+}\r