1 package org.iotivity.bundle.hue;
3 import java.io.IOException;
5 import org.apache.http.HttpEntity;
6 import org.apache.http.client.ClientProtocolException;
7 import org.apache.http.client.methods.CloseableHttpResponse;
8 import org.apache.http.client.methods.HttpPost;
9 import org.apache.http.entity.ContentType;
10 import org.apache.http.entity.StringEntity;
11 import org.apache.http.impl.client.CloseableHttpClient;
12 import org.apache.http.impl.client.HttpClients;
13 import org.apache.http.util.EntityUtils;
14 import org.iotivity.resourcecontainer.bundle.api.ProtocolBridgeConnector;
16 public class HueConnector implements ProtocolBridgeConnector {
17 public void connect() {
21 public void disconnect() {
25 public void transmit(String target, String payload) {
27 CloseableHttpClient httpclient = HttpClients.createDefault();
28 HttpPost httpPost = new HttpPost(target);
29 // httpPost.setHeader("content-type","application/json");
30 StringEntity stringEntity = new StringEntity(payload,
31 ContentType.create("application/json", "UTF-8"));
32 httpPost.setEntity(stringEntity);
34 CloseableHttpResponse response1;
35 response1 = httpclient.execute(httpPost);
36 // The underlying HTTP connection is still held by the response
38 // to allow the response content to be streamed directly from the
40 // In order to ensure correct deallocation of system resources
41 // the user MUST call CloseableHttpResponse#close() from a finally
43 // Please note that if response content is not fully consumed the
45 // connection cannot be safely re-used and will be shut down and
47 // by the connection manager.
49 HttpEntity entity1 = response1.getEntity();
50 // do something useful with the response body
51 // and ensure it is fully consumed
52 EntityUtils.consume(entity1);
57 } catch (ClientProtocolException e) {
58 // TODO Auto-generated catch block
60 } catch (IOException e) {
61 // TODO Auto-generated catch block
66 public String read(String target) {