Skip to content

Commit 631a4e3

Browse files
committed
Fix ClassNotFoundException
1 parent fec8f16 commit 631a4e3

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lib/src/main/java/ua/naiksoftware/stomp/Stomp.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,24 @@ public static StompClient over(Class clazz, String uri, Map<String, String> conn
4747
* @return StompClient for receiving and sending messages. Call #StompClient.connect
4848
*/
4949
public static StompClient over(Class clazz, String uri, Map<String, String> connectHttpHeaders, Object webSocketClient) {
50-
if (clazz == WebSocket.class) {
50+
try {
51+
if (Class.forName("org.java_websocket.WebSocket") != null && clazz == WebSocket.class) {
5152

52-
if (webSocketClient != null) {
53-
throw new IllegalArgumentException("You cannot pass a webSocketClient with 'org.java_websocket.WebSocket'. use null instead.");
54-
}
53+
if (webSocketClient != null) {
54+
throw new IllegalArgumentException("You cannot pass a webSocketClient with 'org.java_websocket.WebSocket'. use null instead.");
55+
}
5556

56-
return createStompClient(new WebSocketsConnectionProvider(uri, connectHttpHeaders));
57-
} else if (clazz == okhttp3.WebSocket.class) {
57+
return createStompClient(new WebSocketsConnectionProvider(uri, connectHttpHeaders));
58+
}
59+
} catch (ClassNotFoundException e) {}
60+
try {
61+
if (Class.forName("okhttp3.WebSocket") != null && clazz == okhttp3.WebSocket.class) {
5862

59-
OkHttpClient okHttpClient = getOkHttpClient(webSocketClient);
63+
OkHttpClient okHttpClient = getOkHttpClient(webSocketClient);
6064

61-
return createStompClient(new OkHttpConnectionProvider(uri, connectHttpHeaders, okHttpClient));
62-
}
65+
return createStompClient(new OkHttpConnectionProvider(uri, connectHttpHeaders, okHttpClient));
66+
}
67+
} catch (ClassNotFoundException e) {}
6368

6469
throw new RuntimeException("Not supported overlay transport: " + clazz.getName());
6570
}

0 commit comments

Comments
 (0)