Fixed MQTT initialization error with maven build inclusion. Added URI

encoder to handle URI calls with URL characters.

Fixes #250
Fixes #251
Fixes #252
This commit is contained in:
bwssystems
2016-11-19 14:12:32 -06:00
parent 9c4b428c86
commit e7acff9f54
2 changed files with 19 additions and 5 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId> <groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId> <artifactId>ha-bridge</artifactId>
<version>3.5.0</version> <version>3.5.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HA Bridge</name> <name>HA Bridge</name>
@@ -192,6 +192,12 @@
<include>**</include> <include>**</include>
</includes> </includes>
</filter> </filter>
<filter>
<artifact>org.eclipse.paho:org.eclipse.paho.client.mqttv3</artifact>
<includes>
<include>**</include>
</includes>
</filter>
</filters> </filters>
<transformers> <transformers>
<transformer <transformer

View File

@@ -66,6 +66,8 @@ import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@@ -1125,6 +1127,7 @@ public class HueMulator implements HueErrorStringSet {
protected String doHttpRequest(String url, String httpVerb, String contentType, String body, NameValue[] headers) { protected String doHttpRequest(String url, String httpVerb, String contentType, String body, NameValue[] headers) {
HttpUriRequest request = null; HttpUriRequest request = null;
String theContent = null; String theContent = null;
URI theURI = null;
ContentType parsedContentType = null; ContentType parsedContentType = null;
StringEntity requestBody = null; StringEntity requestBody = null;
if(contentType != null && contentType.length() > 0) { if(contentType != null && contentType.length() > 0) {
@@ -1132,17 +1135,22 @@ public class HueMulator implements HueErrorStringSet {
if(body != null && body.length() > 0) if(body != null && body.length() > 0)
requestBody = new StringEntity(body, parsedContentType); requestBody = new StringEntity(body, parsedContentType);
} }
try {
theURI = new URI(url);
} catch (URISyntaxException e1) {
log.warn("Error creating URI http request: " + url + " with message: " + e1.getMessage());
return null;
}
try { try {
if(HttpGet.METHOD_NAME.equalsIgnoreCase(httpVerb) || httpVerb == null) { if(HttpGet.METHOD_NAME.equalsIgnoreCase(httpVerb) || httpVerb == null) {
request = new HttpGet(url); request = new HttpGet(theURI);
}else if(HttpPost.METHOD_NAME.equalsIgnoreCase(httpVerb)){ }else if(HttpPost.METHOD_NAME.equalsIgnoreCase(httpVerb)){
HttpPost postRequest = new HttpPost(url); HttpPost postRequest = new HttpPost(theURI);
if(requestBody != null) if(requestBody != null)
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(theURI);
if(requestBody != null) if(requestBody != null)
putRequest.setEntity(requestBody); putRequest.setEntity(requestBody);
request = putRequest; request = putRequest;