mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 08:13:23 +00:00
Fixed success return validation on calls and implemented validation
catching logic for URL issues. Fixes #73 Fixes #75
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.bwssystems.HABridge</groupId>
|
<groupId>com.bwssystems.HABridge</groupId>
|
||||||
<artifactId>ha-bridge</artifactId>
|
<artifactId>ha-bridge</artifactId>
|
||||||
<version>1.4.2a</version>
|
<version>1.4.3</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import com.bwssystems.harmony.HarmonyHome;
|
|||||||
import com.bwssystems.harmony.RunActivity;
|
import com.bwssystems.harmony.RunActivity;
|
||||||
import com.bwssystems.nest.controller.Nest;
|
import com.bwssystems.nest.controller.Nest;
|
||||||
import com.bwssystems.util.JsonTransformer;
|
import com.bwssystems.util.JsonTransformer;
|
||||||
import com.bwssystems.util.TextStringFormatter;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -565,23 +564,27 @@ public class HueMulator {
|
|||||||
|
|
||||||
|
|
||||||
// This function executes the url from the device repository against the vera
|
// This function executes the url from the device repository against the vera
|
||||||
protected boolean doHttpRequest(String anUrl, String httpVerb, String contentType, String body) {
|
protected boolean doHttpRequest(String url, String httpVerb, String contentType, String body) {
|
||||||
HttpUriRequest request = null;
|
HttpUriRequest request = null;
|
||||||
String url = TextStringFormatter.forURL(anUrl);
|
try {
|
||||||
if(HttpGet.METHOD_NAME.equalsIgnoreCase(httpVerb) || httpVerb == null) {
|
if(HttpGet.METHOD_NAME.equalsIgnoreCase(httpVerb) || httpVerb == null) {
|
||||||
request = new HttpGet(url);
|
request = new HttpGet(url);
|
||||||
}else if(HttpPost.METHOD_NAME.equalsIgnoreCase(httpVerb)){
|
}else if(HttpPost.METHOD_NAME.equalsIgnoreCase(httpVerb)){
|
||||||
HttpPost postRequest = new HttpPost(url);
|
HttpPost postRequest = new HttpPost(url);
|
||||||
ContentType parsedContentType = ContentType.parse(contentType);
|
ContentType parsedContentType = ContentType.parse(contentType);
|
||||||
StringEntity requestBody = new StringEntity(body, parsedContentType);
|
StringEntity requestBody = new StringEntity(body, parsedContentType);
|
||||||
postRequest.setEntity(requestBody);
|
postRequest.setEntity(requestBody);
|
||||||
request = postRequest;
|
request = postRequest;
|
||||||
}else if(HttpPut.METHOD_NAME.equalsIgnoreCase(httpVerb)){
|
}else if(HttpPut.METHOD_NAME.equalsIgnoreCase(httpVerb)){
|
||||||
HttpPut putRequest = new HttpPut(url);
|
HttpPut putRequest = new HttpPut(url);
|
||||||
ContentType parsedContentType = ContentType.parse(contentType);
|
ContentType parsedContentType = ContentType.parse(contentType);
|
||||||
StringEntity requestBody = new StringEntity(body, parsedContentType);
|
StringEntity requestBody = new StringEntity(body, parsedContentType);
|
||||||
putRequest.setEntity(requestBody);
|
putRequest.setEntity(requestBody);
|
||||||
request = putRequest;
|
request = putRequest;
|
||||||
|
}
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
log.warn("Error calling out to HA gateway: IllegalArgumentException in log", e);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
log.debug("Making outbound call in doHttpRequest: " + request);
|
log.debug("Making outbound call in doHttpRequest: " + request);
|
||||||
try {
|
try {
|
||||||
@@ -592,7 +595,7 @@ public class HueMulator {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.warn("Error calling out to HA gateway", e);
|
log.warn("Error calling out to HA gateway: IOException in log", e);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,6 +218,9 @@ public final class TextStringFormatter {
|
|||||||
return aURL.replace("&", "&");
|
return aURL.replace("&", "&");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String forQuerySpace(String aURL) {
|
||||||
|
return aURL.replace(" ", "\u0020");
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Synonym for <tt>URLEncoder.encode(String, "UTF-8")</tt>.
|
* Synonym for <tt>URLEncoder.encode(String, "UTF-8")</tt>.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user