Testing api 1.10.0

This commit is contained in:
Admin
2016-06-07 16:39:59 -05:00
parent 9438b25538
commit a276f97776
3 changed files with 56 additions and 11 deletions

View File

@@ -133,7 +133,34 @@ public class HueMulator implements HueErrorStringSet {
// This function sets up the sparkjava rest calls for the hue api // This function sets up the sparkjava rest calls for the hue api
public void setupServer() { public void setupServer() {
log.info("Hue emulator service started...."); log.info("Hue emulator service started....");
// http://ip_address:port/api/{userId}/lights returns json objects of all lights configured // http://ip_address:port/api/{userId}/groups returns json objects of all groups configured
get(HUE_CONTEXT + "/:userid/groups", "application/json", (request, response) -> {
String userId = request.params(":userid");
log.debug("hue groups list requested: " + userId + " from " + request.ip());
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
return "";
} , new JsonTransformer());
// http://ip_address:port/api/{userId}/groups/0 returns json objects of all groups configured
get(HUE_CONTEXT + "/:userid/groups/0", "application/json", (request, response) -> {
String userId = request.params(":userid");
log.debug("hue group 0 list requested: " + userId + " from " + request.ip());
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
return "";
} , new JsonTransformer());
// http://ip_address:port/api/{userId}/scenes returns json objects of all scenes configured
get(HUE_CONTEXT + "/:userid/scenes", "application/json", (request, response) -> {
String userId = request.params(":userid");
log.debug("hue scenes list requested: " + userId + " from " + request.ip());
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
return "";
} , new JsonTransformer());
// http://ip_address:port/api/{userId}/schedules returns json objects of all schedules configured
get(HUE_CONTEXT + "/:userid/schedules", "application/json", (request, response) -> {
String userId = request.params(":userid");
log.debug("hue schedules list requested: " + userId + " from " + request.ip());
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
return "";
} , new JsonTransformer());
get(HUE_CONTEXT + "/:userid/lights", "application/json", (request, response) -> { get(HUE_CONTEXT + "/:userid/lights", "application/json", (request, response) -> {
String userId = request.params(":userid"); String userId = request.params(":userid");
if(bridgeSettings.isTraceupnp()) if(bridgeSettings.isTraceupnp())
@@ -146,6 +173,7 @@ public class HueMulator implements HueErrorStringSet {
deviceResponseMap.put(device.getId(), deviceResponse); deviceResponseMap.put(device.getId(), deviceResponse);
} }
response.type("application/json; charset=utf-8"); response.type("application/json; charset=utf-8");
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
response.status(HttpStatus.SC_OK); response.status(HttpStatus.SC_OK);
return deviceResponseMap; return deviceResponseMap;
} , new JsonTransformer()); } , new JsonTransformer());
@@ -219,7 +247,6 @@ public class HueMulator implements HueErrorStringSet {
aDeviceType = "<not given>"; aDeviceType = "<not given>";
log.debug("HH trace: hue api user create requested for device type: " + aDeviceType + " and username: " + newUser); log.debug("HH trace: hue api user create requested for device type: " + aDeviceType + " and username: " + newUser);
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
response.type("application/json; charset=utf-8"); response.type("application/json; charset=utf-8");
response.status(HttpStatus.SC_OK); response.status(HttpStatus.SC_OK);
return "[{\"success\":{\"username\":\"" + newUser + "\"}}]"; return "[{\"success\":{\"username\":\"" + newUser + "\"}}]";
@@ -233,6 +260,7 @@ public class HueMulator implements HueErrorStringSet {
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), "My App", "none"); HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), "My App", "none");
response.type("application/json; charset=utf-8"); response.type("application/json; charset=utf-8");
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
response.status(HttpStatus.SC_OK); response.status(HttpStatus.SC_OK);
// String responseString = null; // String responseString = null;
// responseString = "[{\"swversion\":\"" + apiResponse.getConfig().getSwversion() + "\",\"apiversion\":\"" + apiResponse.getConfig().getApiversion() + "\",\"name\":\"" + apiResponse.getConfig().getName() + "\",\"mac\":\"" + apiResponse.getConfig().getMac() + "\"}]"; // responseString = "[{\"swversion\":\"" + apiResponse.getConfig().getSwversion() + "\",\"apiversion\":\"" + apiResponse.getConfig().getApiversion() + "\",\"name\":\"" + apiResponse.getConfig().getName() + "\",\"mac\":\"" + apiResponse.getConfig().getMac() + "\"}]";
@@ -249,6 +277,7 @@ public class HueMulator implements HueErrorStringSet {
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), "My App", userId); HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), "My App", userId);
response.type("application/json; charset=utf-8"); response.type("application/json; charset=utf-8");
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
response.status(HttpStatus.SC_OK); response.status(HttpStatus.SC_OK);
return apiResponse.getConfig(); return apiResponse.getConfig();
}, new JsonTransformer()); }, new JsonTransformer());
@@ -258,6 +287,9 @@ public class HueMulator implements HueErrorStringSet {
get(HUE_CONTEXT + "/:userid", "application/json", (request, response) -> { get(HUE_CONTEXT + "/:userid", "application/json", (request, response) -> {
String userId = request.params(":userid"); String userId = request.params(":userid");
log.debug("hue api full state requested: " + userId + " from " + request.ip()); log.debug("hue api full state requested: " + userId + " from " + request.ip());
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
if(userId.equalsIgnoreCase("undefined"))
return "[{\"error\":{\"address\":\"/\",\"description\":\"unauthorized user\",\"type\":\"1\"}}]";
List<DeviceDescriptor> descriptorList = repository.findAll(); List<DeviceDescriptor> descriptorList = repository.findAll();
if (descriptorList == null) { if (descriptorList == null) {
response.status(HttpStatus.SC_NOT_FOUND); response.status(HttpStatus.SC_NOT_FOUND);
@@ -282,6 +314,7 @@ public class HueMulator implements HueErrorStringSet {
get(HUE_CONTEXT + "/:userid/lights/:id", "application/json", (request, response) -> { get(HUE_CONTEXT + "/:userid/lights/:id", "application/json", (request, response) -> {
String userId = request.params(":userid"); String userId = request.params(":userid");
String lightId = request.params(":id"); String lightId = request.params(":id");
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
log.debug("hue light requested: " + lightId + " for user: " + userId + " from " + request.ip()); log.debug("hue light requested: " + lightId + " for user: " + userId + " from " + request.ip());
DeviceDescriptor device = repository.findOne(lightId); DeviceDescriptor device = repository.findOne(lightId);
if (device == null) { if (device == null) {

View File

@@ -22,6 +22,7 @@ public class UpnpListener {
private boolean strict; private boolean strict;
private boolean traceupnp; private boolean traceupnp;
private BridgeControlDescriptor bridgeControl; private BridgeControlDescriptor bridgeControl;
private boolean discoveryTemplateLatest;
private String discoveryTemplate = "HTTP/1.1 200 OK\r\n" + private String discoveryTemplate = "HTTP/1.1 200 OK\r\n" +
"CACHE-CONTROL: max-age=86400\r\n" + "CACHE-CONTROL: max-age=86400\r\n" +
"EXT:\r\n" + "EXT:\r\n" +
@@ -29,15 +30,13 @@ public class UpnpListener {
"SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/1.10.0\r\n" + "SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/1.10.0\r\n" +
"ST: urn:schemas-upnp-org:device:basic:1\r\n" + "ST: urn:schemas-upnp-org:device:basic:1\r\n" +
"USN: uuid:Socket-1_0-221438K0100073::urn:schemas-upnp-org:device:basic:1\r\n\r\n"; "USN: uuid:Socket-1_0-221438K0100073::urn:schemas-upnp-org:device:basic:1\r\n\r\n";
private String discoveryTemplateNew = "HTTP/1.1 200 OK\r\n" + private String discoveryTemplateOld = "HTTP/1.1 200 OK\r\n" +
"HOST: %s:%s\r\n" + "CACHE-CONTROL: max-age=86400\r\n" +
"EXT:\r\n" + "EXT:\r\n" +
"CACHE-CONTROL: max-age=100\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: http://%s:%s/description.xml\r\n" +
"SERVER: FreeRTOS/7.4.2 UPnP/1.0 IpBridge/1.10.0\r\n" + "SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/0.1\r\n" +
"ST: upnp:rootdevice\r\n" + "ST: urn:schemas-upnp-org:device:basic:1\r\n" +
"hue-bridgeid: 001788FFFE09A206\r\n" + "USN: uuid:Socket-1_0-221438K0100073::urn:schemas-upnp-org:device:basic:1\r\n\r\n";
"USN: uuid:88f6698f-2c83-4393-bd03-cd54a9f8595:upnp:rootdevice\r\n\r\n";
public UpnpListener(BridgeSettingsDescriptor theSettings, BridgeControlDescriptor theControl) { public UpnpListener(BridgeSettingsDescriptor theSettings, BridgeControlDescriptor theControl) {
super(); super();
@@ -47,6 +46,7 @@ public class UpnpListener {
strict = theSettings.isUpnpStrict(); strict = theSettings.isUpnpStrict();
traceupnp = theSettings.isTraceupnp(); traceupnp = theSettings.isTraceupnp();
bridgeControl = theControl; bridgeControl = theControl;
discoveryTemplateLatest = true;
} }
@SuppressWarnings("resource") @SuppressWarnings("resource")
@@ -207,10 +207,10 @@ public class UpnpListener {
protected void sendUpnpResponse(DatagramSocket socket, InetAddress requester, int sourcePort) throws IOException { protected void sendUpnpResponse(DatagramSocket socket, InetAddress requester, int sourcePort) throws IOException {
String discoveryResponse = null; String discoveryResponse = null;
if(true) if(discoveryTemplateLatest)
discoveryResponse = String.format(discoveryTemplate, responseAddress, httpServerPort); discoveryResponse = String.format(discoveryTemplate, responseAddress, httpServerPort);
else else
discoveryResponse = String.format(discoveryTemplateNew, Configuration.UPNP_MULTICAST_ADDRESS, Configuration.UPNP_DISCOVERY_PORT, responseAddress, httpServerPort); discoveryResponse = String.format(discoveryTemplateOld, Configuration.UPNP_MULTICAST_ADDRESS, Configuration.UPNP_DISCOVERY_PORT, responseAddress, httpServerPort);
if(traceupnp) if(traceupnp)
log.info("Traceupnp: sendUpnpResponse discovery template with address: " + responseAddress + " and port: " + httpServerPort); log.info("Traceupnp: sendUpnpResponse discovery template with address: " + responseAddress + " and port: " + httpServerPort);
else else

View File

@@ -97,5 +97,17 @@ public class UpnpSettingsResource {
return filledTemplate; return filledTemplate;
} ); } );
// http://ip_adress:port/favicon.ico
get("/favicon.ico", "application/xml; charset=utf-8", (request, response) -> {
return "";
} );
// http://ip_adress:port/hue_logo_0.png
get("/hue_logo_0.png", "application/xml; charset=utf-8", (request, response) -> {
return "";
} );
// http://ip_adress:port/hue_logo_3.png
get("/hue_logo_3.png", "application/xml; charset=utf-8", (request, response) -> {
return "";
} );
} }
} }