Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaba committed Nov 29, 2014
2 parents daa28f2 + 9e597c8 commit dc2f630
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.source=1.6
59 changes: 50 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This library offers MQTT client functionality over WebSocket transport with [Pah
# Supported Paho MQTT library version and Jetty WebSocket Client version

1. [Paho org.eclipse.paho.mqtt.java 1.0.0](http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.java.git/tag/?id=v1.0.0)
1. [Jetty websocket-client 9.2.1.v20140609](http://www.eclipse.org/jetty/documentation/9.2.1.v20140609/jetty-websocket-client-api.html)
1. [Jetty websocket-client 9.2.5.v20141112](http://www.eclipse.org/jetty/documentation/9.2.3.v20140905/jetty-websocket-client-api.html)

# Supported JDK/JRE Version

Expand All @@ -22,10 +22,32 @@ The following libraries are requried as well.

| GroupId | ArtifactId | Version |
|---------------------------|----------------|---------------|
|org.eclipse.jetty |jetty-io |9.2.1.v20140609|
|org.eclipse.jetty |jetty-util |9.2.1.v20140609|
|org.eclipse.jetty.websocket|websocket-api |9.2.1.v20140609|
|org.eclipse.jetty.websocket|websocket-common|9.2.1.v20140609|
|org.eclipse.jetty |jetty-io |9.2.5.v20141112|
|org.eclipse.jetty |jetty-util |9.2.5.v20141112|
|org.eclipse.jetty.websocket|websocket-api |9.2.5.v20141112|
|org.eclipse.jetty.websocket|websocket-common|9.2.5.v20141112|

## maven pom.xml settings

Adds the following elements to your pom.xml if you're using maven.

```
<dependency>
<groupId>io.inventit.dev</groupId>
<artifactId>mqtt-websocket-java</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>9.2.5.v20141112</version>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.0.0</version>
</dependency>
```

# How to build

Expand All @@ -35,13 +57,19 @@ Note that Paho Java library is included in this project as the binary isn't uplo

$ mvn clean package

Then you'll get `mqtt-websocket-java-1.0.0.jar` under the `target` directory.

Then you'll get `mqtt-websocket-java-<version>.jar` under the `target` directory.

# How to use
Here is a sample code to use `MqttWebSocketAsyncClient`.
You can use this library as the same manner as Paho's library but use `MqttWebSocketAsyncClient` instead of Paho's classes such as `MqttClient` and `MqttAsyncClient`.

The `MqttWebSocketAsyncClient` supports the following URI schimes:

Do NOT use `MqttClient` as it always uses Paho's default async client `MqttAsyncClient`.
1. `ws://<host>:<port>` ... for a plain WebSocket
1. `wss://<host>:<port>` ... for a WebSocket with SSL/TLS
1. `tcp://<host>:<port>` ... for a plain TCP MQTT socket
1. `ssl://<host>:<port>` ... for a secure SSL/TLS MQTT socket

Here is sample code to use `MqttWebSocketAsyncClient`.

// Plain MQTT
// final String uriString = "tcp://your-mqtt-broker:1883";
Expand Down Expand Up @@ -90,3 +118,16 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# Change History

[1.0.1 : November 29, 2014](https://github.com/inventit/mqtt-websocket-java/releases/tag/1.0.1)

* Upgrades Jetty 9 library
* Adds a new factory method for WebSocketNetworkModule instance
* Adds new constructors with a new paramter for specifying the logger name to MqttWebSocketAsyncClient
* Releases a JDK1.6 class version (50) jar as well in order for Android app to include this library (**Note that Jetty 9 itself doesn't support Android and JDK 1.6**)

[1.0.0 : July 30, 2014](https://github.com/inventit/mqtt-websocket-java/releases/tag/1.0.0)

* Initial
28 changes: 20 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.inventit.dev</groupId>
<artifactId>mqtt-websocket-java</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<name>MQTT over WebScoket for Java with Paho and Jetty</name>
<url>https://github.com/inventit/mqtt-websocket-java</url>
<licenses>
Expand Down Expand Up @@ -34,6 +34,8 @@
</repository>
</distributionManagement>
<properties>
<jdk.classifier></jdk.classifier>
<target.jdk>1.7</target.jdk>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand All @@ -53,8 +55,8 @@
<version>3.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.7</source>
<target>1.7</target>
<source>1.6</source>
<target>${target.jdk}</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -107,7 +109,6 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<configuration>
Expand All @@ -121,9 +122,9 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>${jdk.classifier}</classifier>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
Expand All @@ -143,14 +144,13 @@
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>9.2.1.v20140609</version>
<scope>compile</scope>
<version>9.2.5.v20141112</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -177,4 +177,16 @@
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>jdk16</id>
<activation>
<jdk>1.6</jdk>
</activation>
<properties>
<jdk.classifier>jdk16</jdk.classifier>
<target.jdk>1.6</target.jdk>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public class MqttWebSocketAsyncClient extends MqttAsyncClient {

private static final String CLASS_NAME = MqttWebSocketAsyncClient.class
.getName();
private static final Logger log = LoggerFactory.getLogger(
LoggerFactory.MQTT_CLIENT_MSG_CAT, CLASS_NAME);
private final Logger log;

private final String serverURI;

Expand All @@ -33,7 +32,7 @@ public class MqttWebSocketAsyncClient extends MqttAsyncClient {
* @param original
* @return
*/
static String createDummyURI(String original) {
protected static String createDummyURI(String original) {
if (!original.startsWith("ws:") && !original.startsWith("wss:")) {
return original;
}
Expand All @@ -42,34 +41,50 @@ static String createDummyURI(String original) {
+ (uri.getPort() > 0 ? uri.getPort() : 80);
}

static boolean isDummyURI(String uri) {
protected static boolean isDummyURI(String uri) {
return uri.startsWith("tcp://DUMMY-");
}

public MqttWebSocketAsyncClient(String serverURI, String clientId,
MqttClientPersistence persistence, MqttPingSender pingSender)
throws MqttException {
MqttClientPersistence persistence, MqttPingSender pingSender,
String loggerName) throws MqttException {

super(createDummyURI(serverURI), clientId, persistence, pingSender);
this.serverURI = serverURI;

final String methodName = "MqttWebSocketAsyncClient";

this.log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT,
(loggerName == null || loggerName.length() == 0) ? CLASS_NAME
: loggerName);

// @TRACE 101=<init> ClientID={0} ServerURI={1} PersistenceType={2}
if (log.isLoggable(Logger.FINE)) {
log.fine(CLASS_NAME, methodName, "101", new Object[] { clientId,
serverURI, persistence });
}
}

public MqttWebSocketAsyncClient(String serverURI, String clientId,
MqttClientPersistence persistence, String loggerName)
throws MqttException {
this(serverURI, clientId, persistence, new TimerPingSender(),
loggerName);
}

public MqttWebSocketAsyncClient(String serverURI, String clientId,
MqttClientPersistence persistence) throws MqttException {
this(serverURI, clientId, persistence, new TimerPingSender());
this(serverURI, clientId, persistence, null);
}

public MqttWebSocketAsyncClient(String serverURI, String clientId,
String loggerName) throws MqttException {
this(serverURI, clientId, new MqttDefaultFilePersistence(), loggerName);
}

public MqttWebSocketAsyncClient(String serverURI, String clientId)
throws MqttException {
this(serverURI, clientId, new MqttDefaultFilePersistence());
this(serverURI, clientId, (String) null);
}

/**
Expand Down Expand Up @@ -136,9 +151,25 @@ protected NetworkModule createNetworkModule(String input,
// http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/cs01/mqtt-v3.1.1-cs01.html#_Toc388534418
subProtocol = "mqtt";
}
return newWebSocketNetworkModule(URI.create(address), subProtocol,
options);
}

/**
* A factory method for instantiating a {@link NetworkModule} with websocket
* support. Subclasses is able to extend this method in order to create an
* arbitrary {@link NetworkModule} class instance.
*
* @param uri
* @param subProtocol
* Either `mqtt` for MQTT v3 or `mqttv3.1` for MQTT v3.1
* @param options
* @return
*/
protected NetworkModule newWebSocketNetworkModule(URI uri,
String subProtocol, MqttConnectOptions options) {
final WebSocketNetworkModule netModule = new WebSocketNetworkModule(
URI.create(address), subProtocol, getClientId());
uri, subProtocol, getClientId());
netModule.setConnectTimeout(options.getConnectionTimeout());
return netModule;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.eclipse.paho.client.mqttv3.logging.LoggerFactory;

/**
* A network module for connecting over WebScoket with Jetty.
* A network module for connecting over WebScoket with Jetty 9.
*/
public class WebSocketNetworkModule extends WebSocketAdapter implements
NetworkModule {
Expand All @@ -45,7 +45,7 @@ public class WebSocketNetworkModule extends WebSocketAdapter implements
private final String subProtocol;

/**
* A stream for outgonig data
* A stream for outgoing data
*/
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream() {
@Override
Expand Down

0 comments on commit dc2f630

Please sign in to comment.