Skip to content

Commit de27e32

Browse files
Preparing for release
1 parent 0e82ce9 commit de27e32

File tree

3 files changed

+33
-43
lines changed

3 files changed

+33
-43
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Overview
66

7-
**Note that this is a FORK of a project by NaikSoftware! This version is purely to avoid using RetroLambda!**
7+
**Note that this is a FORK of a project by NaikSoftware! This version is made to avoid using RetroLambda! (Scroll down to see other changes)**
88

99
This library provides support for [STOMP protocol](https://stomp.github.io/) over Websockets.
1010

@@ -19,7 +19,7 @@ repositories {
1919
maven { url "https://jitpack.io" }
2020
}
2121
dependencies {
22-
compile 'com.github.forresthopkinsa:StompProtocolAndroid:{latest version}'
22+
compile 'com.github.forresthopkinsa:StompProtocolAndroid:1.4.0'
2323
}
2424
```
2525

@@ -29,11 +29,17 @@ You can use this library two ways:
2929
- If you have Java 8 compatiblity and Jack enabled, this library will work for you
3030
- Using the new Native Java 8 support
3131
- As of this writing, you must be using Android Studio Canary to use this feature.
32+
- Has been tested in the following environments:
33+
- Canary 9, Gradle plugin v3.0.0-alpha9
34+
- Canary 8, Gradle plugin v3.0.0-alpha8
35+
- It *should* work in all 3.0.0+ versions
3236
- You can find more info on the [Releases Page](https://github.com/forresthopkinsa/StompProtocolAndroid/releases)
3337

3438
However, *this fork is NOT compatible with Retrolambda.*
3539
If you have RL as a dependency, then you should be using the [upstream version](https://github.com/NaikSoftware/StompProtocolAndroid) of this project!
3640

41+
Finally, please take bugs and questions to the [Issues page](https://github.com/forresthopkinsa/StompProtocolAndroid/issues)! I'll try to answer within one business day.
42+
3743
## Example backend (Spring Boot)
3844

3945
**WebSocketConfig.java**
@@ -71,7 +77,7 @@ class SocketController {
7177
}
7278
```
7379

74-
Check out the full example server https://github.com/NaikSoftware/stomp-protocol-example-server
80+
Check out the [full example server](https://github.com/NaikSoftware/stomp-protocol-example-server)
7581

7682
## Example library usage
7783

@@ -104,7 +110,7 @@ Check out the full example server https://github.com/NaikSoftware/stomp-protocol
104110

105111
```
106112

107-
See the full example https://github.com/NaikSoftware/StompProtocolAndroid/tree/master/example-client
113+
See the [full example](https://github.com/NaikSoftware/StompProtocolAndroid/tree/master/example-client)
108114

109115
Method `Stomp.over` consume class for create connection as first parameter.
110116
You must provide dependency for lib and pass class.
@@ -134,7 +140,7 @@ client.lifecycle().subscribe(lifecycleEvent -> {
134140

135141
**Custom client**
136142

137-
You can use a custom OkHttpClient (for example, [if you want to allow untrusted HTTPS](getUnsafeOkHttpClient())) using the four-argument overload of Stomp.over, like so:
143+
You can use a custom OkHttpClient (for example, [if you want to allow untrusted HTTPS](https://gist.github.com/grow2014/b6969d8f0cfc0f0a1b2bf12f84973dec)) using the four-argument overload of Stomp.over, like so:
138144

139145
``` java
140146
client = Stomp.over(WebSocket.class, address, null, getUnsafeOkHttpClient());

lib/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'com.github.dcendents.android-maven'
33

4-
group='com.github.NaikSoftware'
4+
group='com.github.forresthopkinsa'
55

66
android {
77
compileSdkVersion 25
@@ -37,6 +37,7 @@ dependencies {
3737
// Supported transports
3838
compile 'org.java-websocket:java-websocket:1.3.2'
3939
compile 'com.squareup.okhttp3:okhttp:3.8.1'
40+
implementation 'com.android.support:support-annotations:24.2.0'
4041
}
4142

4243
task sourcesJar(type: Jar) {
Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ua.naiksoftware.stomp;
22

3-
import org.java_websocket.WebSocket;
3+
import android.support.annotation.Nullable;
44

55
import java.util.Map;
66

@@ -19,19 +19,19 @@
1919
*/
2020
public class Stomp {
2121

22-
public static StompClient over(Class clazz, String uri) {
23-
return over(clazz, uri, null, null);
22+
public static StompClient over(Transport transport, String uri) {
23+
return over(transport, uri, null, null);
2424
}
2525

2626
/**
2727
*
28-
* @param clazz class for using as transport
28+
* @param transport transport method
2929
* @param uri URI to connect
3030
* @param connectHttpHeaders HTTP headers, will be passed with handshake query, may be null
3131
* @return StompClient for receiving and sending messages. Call #StompClient.connect
3232
*/
33-
public static StompClient over(Class clazz, String uri, Map<String, String> connectHttpHeaders) {
34-
return over(clazz, uri, connectHttpHeaders, null);
33+
public static StompClient over(Transport transport, String uri, Map<String, String> connectHttpHeaders) {
34+
return over(transport, uri, connectHttpHeaders, null);
3535
}
3636

3737
/**
@@ -40,49 +40,32 @@ public static StompClient over(Class clazz, String uri, Map<String, String> conn
4040
* <li>{@code org.java_websocket.WebSocket}: cannot accept an existing client</li>
4141
* <li>{@code okhttp3.WebSocket}: can accept a non-null instance of {@code okhttp3.OkHttpClient}</li>
4242
* </ul>
43-
* @param clazz class for using as transport
43+
* @param transport transport method
4444
* @param uri URI to connect
4545
* @param connectHttpHeaders HTTP headers, will be passed with handshake query, may be null
46-
* @param webSocketClient Existing client that will be used to open the WebSocket connection, may be null to use default client
46+
* @param okHttpClient Existing client that will be used to open the WebSocket connection, may be null to use default client
4747
* @return StompClient for receiving and sending messages. Call #StompClient.connect
4848
*/
49-
public static StompClient over(Class clazz, String uri, Map<String, String> connectHttpHeaders, Object webSocketClient) {
50-
try {
51-
if (Class.forName("org.java_websocket.WebSocket") != null && clazz == WebSocket.class) {
52-
53-
if (webSocketClient != null) {
54-
throw new IllegalArgumentException("You cannot pass a webSocketClient with 'org.java_websocket.WebSocket'. use null instead.");
55-
}
56-
57-
return createStompClient(new WebSocketsConnectionProvider(uri, connectHttpHeaders));
49+
public static StompClient over(Transport transport, String uri, @Nullable Map<String, String> connectHttpHeaders, @Nullable OkHttpClient okHttpClient) {
50+
if (transport == Transport.JWS) {
51+
if (okHttpClient != null) {
52+
throw new IllegalArgumentException("You cannot pass a webSocketClient with 'org.java_websocket.WebSocket'. use null instead.");
5853
}
59-
} catch (ClassNotFoundException e) {}
60-
try {
61-
if (Class.forName("okhttp3.WebSocket") != null && clazz == okhttp3.WebSocket.class) {
62-
63-
OkHttpClient okHttpClient = getOkHttpClient(webSocketClient);
54+
return createStompClient(new WebSocketsConnectionProvider(uri, connectHttpHeaders));
55+
}
6456

65-
return createStompClient(new OkHttpConnectionProvider(uri, connectHttpHeaders, okHttpClient));
66-
}
67-
} catch (ClassNotFoundException e) {}
57+
if (transport == Transport.OKHTTP) {
58+
return createStompClient(new OkHttpConnectionProvider(uri, connectHttpHeaders, (okHttpClient == null) ? new OkHttpClient() : okHttpClient));
59+
}
6860

69-
throw new RuntimeException("Not supported overlay transport: " + clazz.getName());
61+
throw new IllegalArgumentException("Transport type not supported: " + transport.toString());
7062
}
7163

7264
private static StompClient createStompClient(ConnectionProvider connectionProvider) {
7365
return new StompClient(connectionProvider);
7466
}
7567

76-
private static OkHttpClient getOkHttpClient(Object webSocketClient) {
77-
if (webSocketClient != null) {
78-
if (webSocketClient instanceof OkHttpClient) {
79-
return (OkHttpClient) webSocketClient;
80-
} else {
81-
throw new IllegalArgumentException("You must pass a non-null instance of an 'okhttp3.OkHttpClient'. Or pass null to use a default websocket client.");
82-
}
83-
} else {
84-
// default http client
85-
return new OkHttpClient();
86-
}
68+
public enum Transport {
69+
OKHTTP, JWS
8770
}
8871
}

0 commit comments

Comments
 (0)