mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 00:10:20 +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>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>1.4.2a</version>
|
||||
<version>1.4.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -14,7 +14,6 @@ import com.bwssystems.harmony.HarmonyHome;
|
||||
import com.bwssystems.harmony.RunActivity;
|
||||
import com.bwssystems.nest.controller.Nest;
|
||||
import com.bwssystems.util.JsonTransformer;
|
||||
import com.bwssystems.util.TextStringFormatter;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
@@ -565,23 +564,27 @@ public class HueMulator {
|
||||
|
||||
|
||||
// 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;
|
||||
String url = TextStringFormatter.forURL(anUrl);
|
||||
if(HttpGet.METHOD_NAME.equalsIgnoreCase(httpVerb) || httpVerb == null) {
|
||||
request = new HttpGet(url);
|
||||
}else if(HttpPost.METHOD_NAME.equalsIgnoreCase(httpVerb)){
|
||||
HttpPost postRequest = new HttpPost(url);
|
||||
ContentType parsedContentType = ContentType.parse(contentType);
|
||||
StringEntity requestBody = new StringEntity(body, parsedContentType);
|
||||
postRequest.setEntity(requestBody);
|
||||
request = postRequest;
|
||||
}else if(HttpPut.METHOD_NAME.equalsIgnoreCase(httpVerb)){
|
||||
HttpPut putRequest = new HttpPut(url);
|
||||
ContentType parsedContentType = ContentType.parse(contentType);
|
||||
StringEntity requestBody = new StringEntity(body, parsedContentType);
|
||||
putRequest.setEntity(requestBody);
|
||||
request = putRequest;
|
||||
try {
|
||||
if(HttpGet.METHOD_NAME.equalsIgnoreCase(httpVerb) || httpVerb == null) {
|
||||
request = new HttpGet(url);
|
||||
}else if(HttpPost.METHOD_NAME.equalsIgnoreCase(httpVerb)){
|
||||
HttpPost postRequest = new HttpPost(url);
|
||||
ContentType parsedContentType = ContentType.parse(contentType);
|
||||
StringEntity requestBody = new StringEntity(body, parsedContentType);
|
||||
postRequest.setEntity(requestBody);
|
||||
request = postRequest;
|
||||
}else if(HttpPut.METHOD_NAME.equalsIgnoreCase(httpVerb)){
|
||||
HttpPut putRequest = new HttpPut(url);
|
||||
ContentType parsedContentType = ContentType.parse(contentType);
|
||||
StringEntity requestBody = new StringEntity(body, parsedContentType);
|
||||
putRequest.setEntity(requestBody);
|
||||
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);
|
||||
try {
|
||||
@@ -592,7 +595,7 @@ public class HueMulator {
|
||||
return true;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
@@ -218,6 +218,9 @@ public final class TextStringFormatter {
|
||||
return aURL.replace("&", "&");
|
||||
}
|
||||
|
||||
public static String forQuerySpace(String aURL) {
|
||||
return aURL.replace(" ", "\u0020");
|
||||
}
|
||||
/**
|
||||
* Synonym for <tt>URLEncoder.encode(String, "UTF-8")</tt>.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user