33
33
import org .openqa .selenium .remote .http .HttpResponse ;
34
34
35
35
import java .io .IOException ;
36
- import java .net .MalformedURLException ;
37
36
import java .net .URL ;
38
37
import java .util .Map ;
39
- import java .util .Optional ;
40
38
41
39
import static java .util .Collections .emptyMap ;
42
40
import static org .openqa .selenium .json .Json .JSON_UTF_8 ;
@@ -58,20 +56,14 @@ public class HttpCommandExecutor implements CommandExecutor, NeedsLocalLogs {
58
56
59
57
private LocalLogs logs = LocalLogs .getNullLogger ();
60
58
61
- private static URL getDefaultServerURL () {
62
- try {
63
- return new URL (System .getProperty ("webdriver.remote.server" , "http://localhost:4444/" ));
64
- } catch (MalformedURLException e ) {
65
- throw new WebDriverException (e );
66
- }
67
- }
68
-
69
59
public HttpCommandExecutor (URL addressOfRemoteServer ) {
70
- this (emptyMap (), addressOfRemoteServer );
60
+ this (emptyMap (), Require . nonNull ( "Server URL" , addressOfRemoteServer ) );
71
61
}
72
62
73
63
public HttpCommandExecutor (ClientConfig config ) {
74
- this (emptyMap (), config , defaultClientFactory );
64
+ this (emptyMap (),
65
+ Require .nonNull ("HTTP client configuration" , config ),
66
+ defaultClientFactory );
75
67
}
76
68
77
69
/**
@@ -85,7 +77,9 @@ public HttpCommandExecutor(
85
77
Map <String , CommandInfo > additionalCommands ,
86
78
URL addressOfRemoteServer )
87
79
{
88
- this (additionalCommands , addressOfRemoteServer , defaultClientFactory );
80
+ this (Require .nonNull ("Additional commands" , additionalCommands ),
81
+ Require .nonNull ("Server URL" , addressOfRemoteServer ),
82
+ defaultClientFactory );
89
83
}
90
84
91
85
public HttpCommandExecutor (
@@ -95,8 +89,7 @@ public HttpCommandExecutor(
95
89
{
96
90
this (additionalCommands ,
97
91
ClientConfig .defaultConfig ()
98
- .baseUrl (Optional .ofNullable (addressOfRemoteServer )
99
- .orElseGet (HttpCommandExecutor ::getDefaultServerURL )),
92
+ .baseUrl (Require .nonNull ("Server URL" , addressOfRemoteServer )),
100
93
httpClientFactory );
101
94
}
102
95
@@ -105,12 +98,9 @@ public HttpCommandExecutor(
105
98
ClientConfig config ,
106
99
HttpClient .Factory httpClientFactory )
107
100
{
108
- if (config .baseUri () == null ) {
109
- config = config .baseUrl (getDefaultServerURL ());
110
- }
111
- remoteServer = config .baseUrl ();
112
- this .additionalCommands = additionalCommands ;
113
- this .httpClientFactory = httpClientFactory ;
101
+ remoteServer = Require .nonNull ("HTTP client configuration" , config ).baseUrl ();
102
+ this .additionalCommands = Require .nonNull ("Additional commands" , additionalCommands );
103
+ this .httpClientFactory = Require .nonNull ("HTTP client factory" , httpClientFactory );
114
104
this .client = this .httpClientFactory .createClient (config );
115
105
}
116
106
0 commit comments