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
54 * openConnection() method
\r
56 public void openConnection() throws IOException {
\r
58 httpConnection = (HttpURLConnection) url.openConnection();
\r
63 * setDoInput() method inherited from HttpURLConnection class
\r
65 * @param bSetDoInput
\r
68 public void setDoInput(boolean bSetDoInput) {
\r
70 httpConnection.setDoInput(bSetDoInput);
\r
75 * setRequestProperty() method inherited from HttpURLConnection class
\r
77 * @param strProperty String property
\r
78 * @param strHttpAuthCredentials String HTTP authentication credentials
\r
81 public void setRequestProperty(String strProperty, String strHttpAuthCredentials) {
\r
83 httpConnection.setRequestProperty(strProperty, strHttpAuthCredentials);
\r
88 * setRequestMethod() method inherited from HttpURLConnection class
\r
90 * @param strMethod String method
\r
93 public void setRequestMethod(String strMethod) throws ProtocolException {
\r
95 httpConnection.setRequestMethod(strMethod);
\r
100 * setDoOutput() method inherited from HttpURLConnection class
\r
105 public void setDoOutput(boolean doOut) {
\r
107 httpConnection.setDoOutput(doOut);
\r
112 * getOutputStream() method inherited from HttpURLConnection class
\r
114 * @return OutputStream
\r
116 public OutputStream getOutputStream() throws IOException {
\r
118 return httpConnection.getOutputStream();
\r
123 * getInputStream() method inherited from HttpURLConnection class
\r
125 * @return InputStream
\r
127 public InputStream getInputStream() throws IOException {
\r
129 return httpConnection.getInputStream();
\r
134 * connect() method inherited from HttpURLConnection class
\r
136 public void connect() throws IOException {
\r
138 httpConnection.connect();
\r
143 * disconnect() method inherited from HttpURLConnection class
\r
145 public void disconnect() throws IOException {
\r
147 httpConnection.disconnect();
\r