19
19
package org .openqa .grid .web .servlet .handler ;
20
20
21
21
import com .google .common .annotations .VisibleForTesting ;
22
+ import com .google .common .collect .ImmutableList ;
22
23
import com .google .common .io .ByteStreams ;
23
24
24
25
import org .openqa .grid .common .SeleniumProtocol ;
26
+ import org .openqa .grid .common .exception .GridException ;
25
27
import org .openqa .grid .internal .ExternalSessionKey ;
26
28
import org .openqa .grid .internal .Registry ;
27
29
import org .openqa .grid .internal .TestSession ;
38
40
import java .nio .charset .CharsetDecoder ;
39
41
import java .text .SimpleDateFormat ;
40
42
import java .util .Date ;
43
+ import java .util .List ;
41
44
import java .util .Map ;
42
45
43
46
import javax .servlet .ServletInputStream ;
@@ -60,27 +63,20 @@ public abstract class SeleniumBasedRequest extends HttpServletRequestWrapper {
60
63
private final Map <String , Object > desiredCapability ;
61
64
private final long timestamp = System .currentTimeMillis ();
62
65
66
+ private static List <SeleniumBasedRequestFactory > requestFactories =
67
+ new ImmutableList .Builder <SeleniumBasedRequestFactory >()
68
+ .add (new LegacySeleniumRequestFactory ())
69
+ .add (new WebDriverRequestFactory ())
70
+ .build ();
63
71
64
72
public static SeleniumBasedRequest createFromRequest (HttpServletRequest request , Registry registry ) {
65
- if (SeleniumBasedRequest .getRequestProtocol (request ) == SeleniumProtocol .Selenium ) {
66
- return new LegacySeleniumRequest (request , registry );
67
- } else {
68
- return new WebDriverRequest (request , registry );
69
- }
70
- }
71
-
72
-
73
- /**
74
- * check the request and finds out if that's a selenium legacy protocol( RC ) or a WebDriver one.
75
- * @param request
76
- * @return Either SeleniumProtocol.Selenium or SeleniumProtocol.WebDriver.
77
- */
78
- public static SeleniumProtocol getRequestProtocol (HttpServletRequest request ) {
79
- if ("/selenium-server/driver" .equals (request .getServletPath ())) {
80
- return SeleniumProtocol .Selenium ;
81
- } else {
82
- return SeleniumProtocol .WebDriver ;
73
+ for (SeleniumBasedRequestFactory factory : requestFactories ) {
74
+ SeleniumBasedRequest sbr = factory .createFromRequest (request , registry );
75
+ if (sbr != null ) {
76
+ return sbr ;
77
+ }
83
78
}
79
+ throw new GridException ("Request path " + request .getServletPath () + " is not recognized" );
84
80
}
85
81
86
82
@ VisibleForTesting
@@ -135,13 +131,10 @@ public Registry getRegistry() {
135
131
*/
136
132
public abstract Map <String , Object > extractDesiredCapability ();
137
133
138
-
139
134
// TODO freynaud remove the TestSession parameter.The listener can modify the
140
135
// original request instead.
141
136
public abstract String getNewSessionRequestedCapability (TestSession session );
142
137
143
-
144
-
145
138
public RequestType getRequestType () {
146
139
return type ;
147
140
}
@@ -163,7 +156,6 @@ public int getContentLength() {
163
156
}else {
164
157
return body .length ;
165
158
}
166
-
167
159
}
168
160
169
161
public String getBody () {
@@ -191,7 +183,6 @@ public long getCreationTime(){
191
183
return timestamp ;
192
184
}
193
185
194
-
195
186
public String toString () {
196
187
SimpleDateFormat format = new SimpleDateFormat ("d MMM yyyy HH:mm:ss" );
197
188
StringBuilder builder = new StringBuilder ();
@@ -231,7 +222,4 @@ public synchronized void reset() throws IOException {
231
222
throw new RuntimeException ("not implemented" );
232
223
}
233
224
}
234
-
235
-
236
-
237
225
}
0 commit comments