Repository navigation
fix: update executor and driver server URL state on directConnect #2500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hoanle0126
wants to merge
8
commits into
appium:master
Choose a base branch
from
hoanle0126:fix/direct-connect-server-url-state
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,114
−101
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d010be
fix: update executor and driver server URL state on directConnect
hoanle0126 e4eed84
fix: address review feedback on executor client state and log broadca…
hoanle0126 8ee115c
fix: address review feedback on LogBroadcastEndpoints and DirectConne…
hoanle0126 176274b
fix: keep broadcast overload defaults and simplify scheme resolution
hoanle0126 d23b566
fix: retain initial server URL scheme for log broadcast overloads
hoanle0126 4d09c25
Merge branch 'master' into fix/direct-connect-server-url-state
hoanle0126 b6e90f5
chore: mark deprecated-only log broadcast helpers for removal
hoanle0126 fe2668c
fix: simplify initial server URL accessor and verify DirectConnect ho…
hoanle0126 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
src/main/java/io/appium/java_client/internal/LogBroadcastEndpoints.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * See the NOTICE file distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.appium.java_client.internal; | ||
|
|
||
| import io.appium.java_client.CommandExecutionHelper; | ||
| import io.appium.java_client.ExecutesMethod; | ||
| import io.appium.java_client.remote.AppiumCommandExecutor; | ||
| import io.appium.java_client.remote.AppiumRemoteWebDriver; | ||
| import io.appium.java_client.remote.SessionId; | ||
| import io.appium.java_client.ws.StringWebSocketClient; | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.net.URL; | ||
| import java.util.function.Supplier; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| /** | ||
| * Shared endpoint resolution and WebSocket startup helpers for device log broadcast listeners. | ||
| * | ||
| * @deprecated The logs broadcasting web socket of the Appium drivers is deprecated and will be removed | ||
| * together with this API. Subscribe to the BiDi {@code log.entryAdded} event instead, see the | ||
| * <a href="https://github.com/appium/java-client/blob/master/docs/selenium-bridge.md#bidi">Selenium | ||
| * bridge documentation</a>. | ||
| */ | ||
| @NullMarked | ||
| @Deprecated(since = "11.1.0", forRemoval = true) | ||
| @SuppressWarnings("removal") | ||
| public final class LogBroadcastEndpoints { | ||
| private LogBroadcastEndpoints() { | ||
| } | ||
|
|
||
| /** | ||
| * Starts server-side log streaming and connects the WebSocket client to the currently connected | ||
| * Appium server endpoint using its host, port, and scheme. | ||
| * | ||
| * @param driver the driver executing {@code mobile: startLogsBroadcast} | ||
| * @param clientSupplier supplier for the target WebSocket client, invoked after starting server streaming | ||
| * @param deviceLogType the log endpoint suffix (such as {@code logcat} or {@code syslog}) | ||
| */ | ||
| @Deprecated(since = "11.1.0", forRemoval = true) | ||
| public static void startBroadcast( | ||
| ExecutesMethod driver, | ||
| Supplier<StringWebSocketClient> clientSupplier, | ||
| String deviceLogType | ||
| ) { | ||
| var remoteWebDriver = (AppiumRemoteWebDriver) driver; | ||
| var executor = (AppiumCommandExecutor) remoteWebDriver.getCommandExecutor(); | ||
| URL serverUrl = executor.getAddressOfRemoteServer(); | ||
| if (serverUrl == null) { | ||
| throw new IllegalArgumentException("The Appium server address is not set"); | ||
| } | ||
| startBroadcast( | ||
| remoteWebDriver, | ||
| driver, | ||
| clientSupplier, | ||
| serverUrl, | ||
| serverUrl.getHost(), | ||
| serverUrl.getPort(), | ||
| deviceLogType | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Starts server-side log streaming and connects the WebSocket client to the broadcast endpoint. | ||
| * The WebSocket scheme ({@code ws} or {@code wss}) is derived from the executor's initial server URL | ||
| * before any {@code directConnect} or server URL override so existing callers keep their original scheme. | ||
| * | ||
| * @param driver the driver executing {@code mobile: startLogsBroadcast} | ||
| * @param clientSupplier supplier for the target WebSocket client, invoked after starting server streaming | ||
| * @param host the target WebSocket host | ||
| * @param port the target WebSocket port, or a negative value to omit the port | ||
| * @param deviceLogType the log endpoint suffix (such as {@code logcat} or {@code syslog}) | ||
| */ | ||
| @Deprecated(since = "11.1.0", forRemoval = true) | ||
| public static void startBroadcast( | ||
| ExecutesMethod driver, | ||
| Supplier<StringWebSocketClient> clientSupplier, | ||
| String host, | ||
| int port, | ||
| String deviceLogType | ||
| ) { | ||
| var remoteWebDriver = (AppiumRemoteWebDriver) driver; | ||
| var executor = (AppiumCommandExecutor) remoteWebDriver.getCommandExecutor(); | ||
| startBroadcast( | ||
| remoteWebDriver, | ||
| driver, | ||
| clientSupplier, | ||
| executor.getInitialServerUrl(), | ||
| host, | ||
| port, | ||
| deviceLogType | ||
| ); | ||
| } | ||
|
|
||
| private static void startBroadcast( | ||
| AppiumRemoteWebDriver remoteWebDriver, | ||
| ExecutesMethod driver, | ||
| Supplier<StringWebSocketClient> clientSupplier, | ||
| @Nullable URL serverUrl, | ||
| String host, | ||
| int port, | ||
| String deviceLogType | ||
| ) { | ||
| URI endpoint = buildBroadcastUri( | ||
| serverUrl, | ||
| host, | ||
| port, | ||
| remoteWebDriver.getSessionId(), | ||
| deviceLogType | ||
| ); | ||
| CommandExecutionHelper.executeScript(driver, "mobile: startLogsBroadcast"); | ||
| clientSupplier.get().connect(endpoint); | ||
| } | ||
|
|
||
| /** | ||
| * Builds a device log broadcast WebSocket URI using {@code wss} when {@code serverUrl} uses | ||
| * {@code https} or {@code wss}, or {@code ws} otherwise. | ||
| * | ||
| * @param serverUrl the server URL used to choose the WebSocket scheme, or {@code null} if unknown | ||
| * @param host the target WebSocket host (bare IPv6 literals are bracketed automatically) | ||
| * @param port the target WebSocket port, or a negative value to omit the port | ||
| * @param sessionId the active session identifier | ||
| * @param deviceLogType the log endpoint suffix (such as {@code logcat} or {@code syslog}) | ||
| * @return the WebSocket endpoint URI | ||
| */ | ||
| @Deprecated(since = "11.1.0", forRemoval = true) | ||
| public static URI buildBroadcastUri( | ||
| @Nullable URL serverUrl, | ||
| String host, | ||
| int port, | ||
| @Nullable SessionId sessionId, | ||
| String deviceLogType | ||
| ) { | ||
| String protocol = serverUrl == null ? null : serverUrl.getProtocol(); | ||
| String scheme = "https".equalsIgnoreCase(protocol) || "wss".equalsIgnoreCase(protocol) ? "wss" : "ws"; | ||
| String validatedHost = requireNonNull(host, "Host"); | ||
| if (validatedHost.isBlank()) { | ||
| throw new IllegalArgumentException("Host must not be blank"); | ||
| } | ||
| String path = "/ws/session/" + sessionId + "/appium/device/" + deviceLogType; | ||
| int normalizedPort = port < 0 ? -1 : port; | ||
| try { | ||
| URI endpoint = new URI( | ||
| scheme, | ||
| null, | ||
| Strings.formatHost(validatedHost), | ||
| normalizedPort, | ||
| path, | ||
| null, | ||
| null | ||
| ); | ||
| if (endpoint.getHost() == null | ||
| || endpoint.getPort() != normalizedPort | ||
| || endpoint.getRawUserInfo() != null | ||
| || endpoint.getRawQuery() != null | ||
| || endpoint.getRawFragment() != null | ||
| || !path.equals(endpoint.getPath())) { | ||
| throw new IllegalArgumentException("Cannot build the log broadcast web socket endpoint"); | ||
| } | ||
| return endpoint; | ||
| } catch (URISyntaxException e) { | ||
| throw new IllegalArgumentException("Cannot build the log broadcast web socket endpoint", e); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.