Skip to content

Commit

Permalink
Fixed MQTT initialization error with maven build inclusion. Added URI
Browse files Browse the repository at this point in the history
encoder to handle URI calls with URL characters.

Fixes #250
Fixes #251
Fixes #252
  • Loading branch information
bwssytems committed Nov 19, 2016
1 parent 9c4b428 commit e7acff9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 7 additions & 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>3.5.0</version>
<version>3.5.1</version>
<packaging>jar</packaging>

<name>HA Bridge</name>
Expand Down Expand Up @@ -192,6 +192,12 @@
<include>**</include>
</includes>
</filter>
<filter>
<artifact>org.eclipse.paho:org.eclipse.paho.client.mqttv3</artifact>
<includes>
<include>**</include>
</includes>
</filter>
</filters>
<transformers>
<transformer
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/bwssystems/HABridge/hue/HueMulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -1125,24 +1127,30 @@ protected String replaceIntensityValue(String request, int intensity, boolean is
protected String doHttpRequest(String url, String httpVerb, String contentType, String body, NameValue[] headers) {
HttpUriRequest request = null;
String theContent = null;
URI theURI = null;
ContentType parsedContentType = null;
StringEntity requestBody = null;
if(contentType != null && contentType.length() > 0) {
parsedContentType = ContentType.parse(contentType);
if(body != null && body.length() > 0)
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 {
if(HttpGet.METHOD_NAME.equalsIgnoreCase(httpVerb) || httpVerb == null) {
request = new HttpGet(url);
request = new HttpGet(theURI);
}else if(HttpPost.METHOD_NAME.equalsIgnoreCase(httpVerb)){
HttpPost postRequest = new HttpPost(url);
HttpPost postRequest = new HttpPost(theURI);
if(requestBody != null)
postRequest.setEntity(requestBody);
request = postRequest;
}else if(HttpPut.METHOD_NAME.equalsIgnoreCase(httpVerb)){
HttpPut putRequest = new HttpPut(url);
HttpPut putRequest = new HttpPut(theURI);
if(requestBody != null)
putRequest.setEntity(requestBody);
request = putRequest;
Expand Down

0 comments on commit e7acff9

Please sign in to comment.