3 import java.io.InputStream;
\r
4 import java.io.OutputStream;
\r
5 import java.io.IOException;
\r
6 import java.net.HttpURLConnection;
\r
7 import java.net.MalformedURLException;
\r
8 import java.net.UnknownHostException;
\r
10 import java.net.ProtocolException;
\r
13 /** Class IoTHTTP is a wrapper class that provides
\r
14 * minimum interfaces for user to interact with IoT
\r
15 * devices in our system
\r
17 * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
\r
21 public class IoTHTTP {
\r
24 * IoTHTTP class properties
\r
26 private IoTDeviceAddress iotDevAdd;
\r
28 private HttpURLConnection httpConnection;
\r
33 public IoTHTTP(IoTDeviceAddress _iotDevAdd) {
\r
35 iotDevAdd = _iotDevAdd;
\r
37 httpConnection = null;
\r
43 * @param strUrlComplete String to complete the URL
\r
46 public void setURL(String strUrlComplete) throws MalformedURLException {
\r
48 url = new URL(iotDevAdd.getURL(strUrlComplete));
\r
49 System.out.println(url.toString());
\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