From 5b2ce17db71ec6214ad4892acc8a469c4f86b80b Mon Sep 17 00:00:00 2001 From: lastverb Date: Wed, 8 Apr 2020 15:17:34 +0200 Subject: [PATCH] Websocker routing changed from selectors to routing keys --- .gitignore | 1 + pom.xml | 4 ++-- .../bitbar/remotedevice/StaticParameters.java | 4 +--- .../remotedevice/api/APIClientManager.java | 6 ++---- .../remotedevice/websocket/WebsocketManager.java | 4 ++-- .../websocket/handlers/StompSessionHandler.java | 16 +++------------- 6 files changed, 11 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 13656d3..01d0cd3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ target/ # IDE .vscode/ .idea/ +*.iml !.idea/codeStyleSettings.xml # Logs diff --git a/pom.xml b/pom.xml index fb95407..eb81882 100644 --- a/pom.xml +++ b/pom.xml @@ -10,12 +10,12 @@ com.bitbar remote-device-client - 2.85 + 2.96 jar 1.8 - 2.85 + 2.96 1.3.1 0.1.55 2.2.0.RELEASE diff --git a/src/main/java/com/bitbar/remotedevice/StaticParameters.java b/src/main/java/com/bitbar/remotedevice/StaticParameters.java index 23b2aee..29a0bd0 100644 --- a/src/main/java/com/bitbar/remotedevice/StaticParameters.java +++ b/src/main/java/com/bitbar/remotedevice/StaticParameters.java @@ -4,9 +4,7 @@ public class StaticParameters { public static final String DEVICE_SESSIONS_URI = "/me/device-sessions"; - public static final String RELEASE_DS_URI = "/me/device-sessions/%d/release"; - - public static final String WEBSOCKET_CONNECTIONS_TOPIC = "/topic/device-session-connections"; + public static final String WEBSOCKET_CONNECTIONS_TOPIC_FORMAT = "/topic/device-sessions.%s.connections"; public static final String WEBSOCKET_URI = "/websocket"; diff --git a/src/main/java/com/bitbar/remotedevice/api/APIClientManager.java b/src/main/java/com/bitbar/remotedevice/api/APIClientManager.java index 7618977..aa5245f 100644 --- a/src/main/java/com/bitbar/remotedevice/api/APIClientManager.java +++ b/src/main/java/com/bitbar/remotedevice/api/APIClientManager.java @@ -6,8 +6,6 @@ import com.testdroid.api.dto.Context; import com.testdroid.api.dto.MappingKey; import com.testdroid.api.filter.FilterEntry; -import com.testdroid.api.filter.ListStringFilterEntry; -import com.testdroid.api.filter.NumberFilterEntry; import com.testdroid.api.model.APICloudInfo; import com.testdroid.api.model.APIDevice; import com.testdroid.api.model.APIDeviceSession; @@ -46,7 +44,7 @@ private APIClient createAPIClient(String cloudUrl, String apiKey) throws Require public List getSupportedDevices() throws APIException { Context ctx = new Context<>(APIDevice.class); - ctx.getFilters().add(new ListStringFilterEntry(OS_TYPE, IN, + ctx.getFilters().add(new FilterEntry(OS_TYPE, IN, Arrays.asList(ANDROID.getDisplayName(), IOS.getDisplayName()))); apiClient.findDevicePropertyInLabelGroup("supported-frameworks", "remote-session"). ifPresent(val -> ctx.setExtraParams( @@ -62,7 +60,7 @@ public List getSupportedDevices() throws APIException { public APIDevice getDevice(Long id) throws APIException { Context ctx = new Context<>(APIDevice.class); List filters = ctx.getFilters(); - filters.add(new NumberFilterEntry(ID, EQ, id)); + filters.add(new FilterEntry(ID, EQ, id)); APIList devices = apiClient.getDevices(ctx).getEntity(); if (devices.isEmpty()) { throw new APIException(String.format("Could not find device with id %d", id)); diff --git a/src/main/java/com/bitbar/remotedevice/websocket/WebsocketManager.java b/src/main/java/com/bitbar/remotedevice/websocket/WebsocketManager.java index b76c236..3e7f325 100644 --- a/src/main/java/com/bitbar/remotedevice/websocket/WebsocketManager.java +++ b/src/main/java/com/bitbar/remotedevice/websocket/WebsocketManager.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.concurrent.ExecutionException; -import static com.bitbar.remotedevice.StaticParameters.WEBSOCKET_CONNECTIONS_TOPIC; +import static com.bitbar.remotedevice.StaticParameters.WEBSOCKET_CONNECTIONS_TOPIC_FORMAT; import static com.bitbar.remotedevice.cli.CommandLineParameter.API_KEY; import static com.bitbar.remotedevice.cli.CommandLineParameter.CLOUD_URI; import static org.springframework.http.HttpHeaders.AUTHORIZATION; @@ -60,7 +60,7 @@ public StompSession startWebsocketSession(APIDeviceSession deviceSession) throws ExecutionException, InterruptedException { WebSocketStompClient stompClient = createStompClient(); - StompSessionHandler sessionHandler = new StompSessionHandler(this, WEBSOCKET_CONNECTIONS_TOPIC, + StompSessionHandler sessionHandler = new StompSessionHandler(this, WEBSOCKET_CONNECTIONS_TOPIC_FORMAT, deviceSession.getId()); WebSocketHttpHeaders webSocketHttpHeaders = new WebSocketHttpHeaders(); diff --git a/src/main/java/com/bitbar/remotedevice/websocket/handlers/StompSessionHandler.java b/src/main/java/com/bitbar/remotedevice/websocket/handlers/StompSessionHandler.java index cd7b6c6..f2922a9 100644 --- a/src/main/java/com/bitbar/remotedevice/websocket/handlers/StompSessionHandler.java +++ b/src/main/java/com/bitbar/remotedevice/websocket/handlers/StompSessionHandler.java @@ -11,28 +11,18 @@ public class StompSessionHandler extends StompSessionHandlerAdapter { private static final Logger LOGGER = LoggerFactory.getLogger(StompSessionHandler.class); - private static final String DEVICE_SESSION_SELECTOR_FORMAT = "deviceSessionId = %d"; - - private static final String SELECTOR_HEADER_NAME = "selector"; - private String connectionTopic; - private Long deviceSessionId; - private WebsocketManager websocketManager; - public StompSessionHandler(WebsocketManager websocketManager, String connectionTopic, Long deviceSessionId) { - this.connectionTopic = connectionTopic; - this.deviceSessionId = deviceSessionId; + public StompSessionHandler(WebsocketManager websocketManager, String connectionTopicFormat, Long deviceSessionId) { + this.connectionTopic = String.format(connectionTopicFormat, deviceSessionId); this.websocketManager = websocketManager; } @Override public void afterConnected(StompSession session, StompHeaders headers) { - StompHeaders subscribeHeaders = new StompHeaders(); - subscribeHeaders.setDestination(connectionTopic); - subscribeHeaders.set(SELECTOR_HEADER_NAME, String.format(DEVICE_SESSION_SELECTOR_FORMAT, deviceSessionId)); - session.subscribe(subscribeHeaders, new DeviceSessionStompFrameHandler(websocketManager)); + session.subscribe(connectionTopic, new DeviceSessionStompFrameHandler(websocketManager)); } /**