Skip to content

Commit 3ac8391

Browse files
committed
Fixed success return validation on calls and implemented validation
catching logic for URL issues. Fixes #73 Fixes #75
1 parent e62fcf7 commit 3ac8391

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.bwssystems.HABridge</groupId>
77
<artifactId>ha-bridge</artifactId>
8-
<version>1.4.2a</version>
8+
<version>1.4.3</version>
99
<packaging>jar</packaging>
1010

1111
<name>HA Bridge</name>

src/main/java/com/bwssystems/HABridge/hue/HueMulator.java

+21-18
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.bwssystems.harmony.RunActivity;
1515
import com.bwssystems.nest.controller.Nest;
1616
import com.bwssystems.util.JsonTransformer;
17-
import com.bwssystems.util.TextStringFormatter;
1817
import com.fasterxml.jackson.databind.DeserializationFeature;
1918
import com.fasterxml.jackson.databind.ObjectMapper;
2019
import com.google.gson.Gson;
@@ -565,23 +564,27 @@ protected String replaceIntensityValue(String request, int intensity){
565564

566565

567566
// This function executes the url from the device repository against the vera
568-
protected boolean doHttpRequest(String anUrl, String httpVerb, String contentType, String body) {
567+
protected boolean doHttpRequest(String url, String httpVerb, String contentType, String body) {
569568
HttpUriRequest request = null;
570-
String url = TextStringFormatter.forURL(anUrl);
571-
if(HttpGet.METHOD_NAME.equalsIgnoreCase(httpVerb) || httpVerb == null) {
572-
request = new HttpGet(url);
573-
}else if(HttpPost.METHOD_NAME.equalsIgnoreCase(httpVerb)){
574-
HttpPost postRequest = new HttpPost(url);
575-
ContentType parsedContentType = ContentType.parse(contentType);
576-
StringEntity requestBody = new StringEntity(body, parsedContentType);
577-
postRequest.setEntity(requestBody);
578-
request = postRequest;
579-
}else if(HttpPut.METHOD_NAME.equalsIgnoreCase(httpVerb)){
580-
HttpPut putRequest = new HttpPut(url);
581-
ContentType parsedContentType = ContentType.parse(contentType);
582-
StringEntity requestBody = new StringEntity(body, parsedContentType);
583-
putRequest.setEntity(requestBody);
584-
request = putRequest;
569+
try {
570+
if(HttpGet.METHOD_NAME.equalsIgnoreCase(httpVerb) || httpVerb == null) {
571+
request = new HttpGet(url);
572+
}else if(HttpPost.METHOD_NAME.equalsIgnoreCase(httpVerb)){
573+
HttpPost postRequest = new HttpPost(url);
574+
ContentType parsedContentType = ContentType.parse(contentType);
575+
StringEntity requestBody = new StringEntity(body, parsedContentType);
576+
postRequest.setEntity(requestBody);
577+
request = postRequest;
578+
}else if(HttpPut.METHOD_NAME.equalsIgnoreCase(httpVerb)){
579+
HttpPut putRequest = new HttpPut(url);
580+
ContentType parsedContentType = ContentType.parse(contentType);
581+
StringEntity requestBody = new StringEntity(body, parsedContentType);
582+
putRequest.setEntity(requestBody);
583+
request = putRequest;
584+
}
585+
} catch(IllegalArgumentException e) {
586+
log.warn("Error calling out to HA gateway: IllegalArgumentException in log", e);
587+
return false;
585588
}
586589
log.debug("Making outbound call in doHttpRequest: " + request);
587590
try {
@@ -592,7 +595,7 @@ protected boolean doHttpRequest(String anUrl, String httpVerb, String contentTyp
592595
return true;
593596
}
594597
} catch (IOException e) {
595-
log.warn("Error calling out to HA gateway", e);
598+
log.warn("Error calling out to HA gateway: IOException in log", e);
596599
}
597600
return false;
598601
}

src/main/java/com/bwssystems/util/TextStringFormatter.java

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ public static String forHrefAmpersand(String aURL) {
218218
return aURL.replace("&", "&amp;");
219219
}
220220

221+
public static String forQuerySpace(String aURL) {
222+
return aURL.replace(" ", "\u0020");
223+
}
221224
/**
222225
* Synonym for <tt>URLEncoder.encode(String, "UTF-8")</tt>.
223226
*

0 commit comments

Comments
 (0)