Skip to content

Commit

Permalink
Fixed success return validation on calls and implemented validation
Browse files Browse the repository at this point in the history
catching logic for URL issues.

Fixes #73
Fixes #75
  • Loading branch information
bwssytems committed Mar 29, 2016
1 parent e62fcf7 commit 3ac8391
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
39 changes: 21 additions & 18 deletions src/main/java/com/bwssystems/HABridge/hue/HueMulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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;
Expand Down Expand Up @@ -565,23 +564,27 @@ protected String replaceIntensityValue(String request, int intensity){


// 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 {
Expand All @@ -592,7 +595,7 @@ protected boolean doHttpRequest(String anUrl, String httpVerb, String contentTyp
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;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/bwssystems/util/TextStringFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ public static String forHrefAmpersand(String aURL) {
return aURL.replace("&", "&amp;");
}

public static String forQuerySpace(String aURL) {
return aURL.replace(" ", "\u0020");
}
/**
* Synonym for <tt>URLEncoder.encode(String, "UTF-8")</tt>.
*
Expand Down

0 comments on commit 3ac8391

Please sign in to comment.