4 import java.io.InputStream;
\r
5 import java.io.OutputStream;
\r
6 import java.io.IOException;
\r
7 import java.net.HttpURLConnection;
\r
8 import java.net.MalformedURLException;
\r
9 import java.net.UnknownHostException;
\r
10 import java.net.URL;
\r
11 import java.net.ProtocolException;
\r
13 import iotruntime.slave.IoTDeviceAddress;
\r
15 /** Class IoTHTTP is a wrapper class that provides
\r
16 * minimum interfaces for user to interact with IoT
\r
17 * devices in our system
\r
19 * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
\r
23 public final class IoTHTTP {
\r
26 * IoTHTTP class properties
\r
28 private IoTDeviceAddress iotDevAdd;
\r
30 private HttpURLConnection httpConnection;
\r
35 public IoTHTTP(IoTDeviceAddress _iotDevAdd) {
\r
37 iotDevAdd = _iotDevAdd;
\r
39 httpConnection = null;
\r
45 * @param strUrlComplete String to complete the URL
\r
48 public void setURL(String strUrlComplete) throws MalformedURLException {
\r
50 url = new URL(iotDevAdd.getURL(strUrlComplete));
\r
55 * openConnection() method
\r
57 public void openConnection() throws IOException {
\r
59 httpConnection = (HttpURLConnection) url.openConnection();
\r
64 * setDoInput() method inherited from HttpURLConnection class
\r
66 * @param bSetDoInput
\r
69 public void setDoInput(boolean bSetDoInput) {
\r
71 httpConnection.setDoInput(bSetDoInput);
\r
76 * setRequestProperty() method inherited from HttpURLConnection class
\r
78 * @param strProperty String property
\r
79 * @param strHttpAuthCredentials String HTTP authentication credentials
\r
82 public void setRequestProperty(String strProperty, String strHttpAuthCredentials) {
\r
84 httpConnection.setRequestProperty(strProperty, strHttpAuthCredentials);
\r
89 * setRequestMethod() method inherited from HttpURLConnection class
\r
91 * @param strMethod String method
\r
94 public void setRequestMethod(String strMethod) throws ProtocolException {
\r
96 httpConnection.setRequestMethod(strMethod);
\r
101 * setDoOutput() method inherited from HttpURLConnection class
\r
106 public void setDoOutput(boolean doOut) {
\r
108 httpConnection.setDoOutput(doOut);
\r
113 * getOutputStream() method inherited from HttpURLConnection class
\r
115 * @return OutputStream
\r
117 public OutputStream getOutputStream() throws IOException {
\r
119 return httpConnection.getOutputStream();
\r
124 * getInputStream() method inherited from HttpURLConnection class
\r
126 * @return InputStream
\r
128 public InputStream getInputStream() throws IOException {
\r
130 return httpConnection.getInputStream();
\r
135 * connect() method inherited from HttpURLConnection class
\r
137 public void connect() throws IOException {
\r
139 httpConnection.connect();
\r
144 * disconnect() method inherited from HttpURLConnection class
\r
146 public void disconnect() throws IOException {
\r
148 httpConnection.disconnect();
\r