1
1
package ru .qatools .gridrouter ;
2
2
3
3
import org .apache .commons .io .IOUtils ;
4
- import org .apache .http .client .utils .URIBuilder ;
5
4
import org .eclipse .jetty .client .api .Request ;
6
5
import org .eclipse .jetty .client .util .StringContentProvider ;
7
6
import org .slf4j .Logger ;
18
17
import javax .servlet .http .HttpServletRequest ;
19
18
import javax .servlet .http .HttpServletResponse ;
20
19
import java .io .IOException ;
21
- import java .io .UnsupportedEncodingException ;
22
- import java .net .URISyntaxException ;
23
- import java .net .URLDecoder ;
24
20
25
21
import static java .nio .charset .StandardCharsets .UTF_8 ;
26
- import static org .springframework .http .HttpMethod .DELETE ;
27
22
import static org .springframework .web .context .support .SpringBeanAutowiringSupport .processInjectionBasedOnServletContext ;
23
+ import static ru .qatools .gridrouter .JsonWireUtils .*;
28
24
import static ru .qatools .gridrouter .RequestUtils .getRemoteHost ;
29
25
30
26
/**
34
30
* @author Artem Eroshenko [email protected]
35
31
*/
36
32
@ WebServlet (
37
- urlPatterns = {ProxyServlet . WD_HUB_SESSION + "*" },
33
+ urlPatterns = {WD_HUB_SESSION + "*" },
38
34
asyncSupported = true ,
39
35
initParams = {
40
36
@ WebInitParam (name = "timeout" , value = "300000" ),
@@ -45,10 +41,6 @@ public class ProxyServlet extends org.eclipse.jetty.proxy.ProxyServlet {
45
41
46
42
private static final Logger LOGGER = LoggerFactory .getLogger (ProxyServlet .class );
47
43
48
- public static final String WD_HUB_SESSION = "/wd/hub/session/" ;
49
-
50
- public static final int SESSION_HASH_LENGTH = 32 ;
51
-
52
44
@ Autowired
53
45
private ConfigRepository config ;
54
46
@@ -85,7 +77,7 @@ protected String rewriteTarget(HttpServletRequest request) {
85
77
return null ;
86
78
}
87
79
88
- String route = getRoute (uri );
80
+ String route = config . getRoute (getSessionHash ( uri ) );
89
81
String command = getCommand (uri );
90
82
91
83
if (route == null ) {
@@ -132,39 +124,4 @@ private String removeSessionIdSafe(String content, String remoteHost) {
132
124
}
133
125
return content ;
134
126
}
135
-
136
- protected String redirectionUrl (String host , String command ) throws URISyntaxException {
137
- return new URIBuilder (host ).setPath (WD_HUB_SESSION + command ).build ().toString ();
138
- }
139
-
140
- protected String getRoute (String uri ) {
141
- return config .getRoutes ().get (getSessionHash (uri ));
142
- }
143
-
144
- protected String getCommand (String uri ) {
145
- String encodedCommand = uri .substring (getUriPrefixLength ());
146
- try {
147
- return URLDecoder .decode (encodedCommand , UTF_8 .name ());
148
- } catch (UnsupportedEncodingException e ) {
149
- LOGGER .error ("[UNABLE_TO_DECODE_COMMAND] - could not decode command: {}" , encodedCommand , e );
150
- return encodedCommand ;
151
- }
152
- }
153
-
154
- protected boolean isUriValid (String uri ) {
155
- return uri .length () > getUriPrefixLength ();
156
- }
157
-
158
- protected boolean isSessionDeleteRequest (HttpServletRequest request , String command ) {
159
- return DELETE .name ().equalsIgnoreCase (request .getMethod ())
160
- && !command .contains ("/" );
161
- }
162
-
163
- protected String getSessionHash (String uri ) {
164
- return uri .substring (WD_HUB_SESSION .length (), getUriPrefixLength ());
165
- }
166
-
167
- protected int getUriPrefixLength () {
168
- return WD_HUB_SESSION .length () + SESSION_HASH_LENGTH ;
169
- }
170
127
}
0 commit comments