Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #59 from sathipal/master
Browse files Browse the repository at this point in the history
Fix to handle when default charset is not UTF-8
  • Loading branch information
Lokesh K Haralakatta authored Sep 7, 2016
2 parents d4d5b71 + 22e61fa commit 211b11e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/ibm/iotf/client/AbstractClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,7 @@ protected static int publishEventsThroughHttps(String organization,

LoggerUtility.fine(CLASS_NAME, METHOD, "ReST URL::"+sb.toString());
BufferedReader br = null;
br = new BufferedReader(new InputStreamReader(System.in));


// Create the payload message in Json format
JsonObject message = (JsonObject) gson.toJsonTree(payload);
StringEntity input = new StringEntity(message.toString(), StandardCharsets.UTF_8);
Expand Down Expand Up @@ -722,7 +721,7 @@ protected static int publishEventsThroughHttps(String organization,
.append('\n');
}
log.append("\nResponse \n");
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8));
log.append(br.readLine());
LoggerUtility.severe(CLASS_NAME, METHOD, log.toString());

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ibm/iotf/client/api/APIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private HttpResponse caseDeleteFromConnect(List<NameValuePair> queryParameters,
private String readContent(HttpResponse response, String method)
throws IllegalStateException, IOException {

BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8));
String line = null;
try {
line = br.readLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ private void addDevice(String deviceType, String deviceId) throws IoTFCReSTExcep
* can publish its own events as well.
*
* The test verifies whether the gateway can publish an event to the Platform
* @throws Exception
*/
public void testGatewayEventPublishMethod() {
public void testGatewayEventPublishMethod() throws Exception {

if(gwClient.isConnected() == false) {
return;
Expand All @@ -241,21 +242,28 @@ public void testGatewayEventPublishMethod() {

// publish using default QoS0
code = gwClient.publishGatewayEvent("blink", event, 1);

// custom publish
code = gwClient.publishGatewayEvent("blink", "rotation:80", "text", 1);
assertTrue("Failed to publish the event......", code);


// custom publish
code = gwClient.publishGatewayEvent("blink", new byte[]{80}, "binary", 1);
assertTrue("Failed to publish the event......", code);

// try publish after disconnect
gwClient.disconnect();
code = gwClient.publishGatewayEvent("blink", event, 1);
assertFalse("Should not publish an event after disconnect......", code);

// try publish after disconnect

System.out.println("Successfully published a Gateway event !!");
}

/**
* The test verifies whether the gateway can publish an event for the attached device to the Platform
* @throws Exception
*/
public void testDeviceEventPublishMethod() {
public void testDeviceEventPublishMethod() throws Exception {

if(gwClient.isConnected() == false) {
return;
Expand All @@ -281,6 +289,14 @@ public void testDeviceEventPublishMethod() {
// Publish using default QoS1
code = gwClient.publishDeviceEvent(DEVICE_TYPE, SIMULATOR_DEVICE_ID, "blink", null, 1);
assertTrue("Failed to publish the device event......", code);

// Publish text event
code = gwClient.publishDeviceEvent(DEVICE_TYPE, SIMULATOR_DEVICE_ID, "blink", "rotation:80", "text", 2);
assertTrue("Failed to publish the device event......", code);

// Publish using default QoS1
code = gwClient.publishDeviceEvent(DEVICE_TYPE, SIMULATOR_DEVICE_ID, "blink", new byte[]{90, 8, 9, 0}, "binary", 1);
assertTrue("Failed to publish the device event......", code);

System.out.println("Successfully published a device event !!");
}
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/gateway.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Registration-Mode = Manual
## Mandatory if Registration-Mode is Manual
API-Key = <Organization API Key>
API-Token = <Organization API Token>

##Optional properties
WebSocket = false
Secure = true
Expand Down

0 comments on commit 211b11e

Please sign in to comment.