@@ -103,47 +103,49 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
103
103
List <Region > unvisitedRegions = new ArrayList <>(allRegions );
104
104
105
105
int attempt = 0 ;
106
- while (!allRegions .isEmpty ()) {
107
- attempt ++;
108
-
109
- Region currentRegion = hostSelectionStrategy .selectRegion (allRegions , unvisitedRegions );
110
- Host host = hostSelectionStrategy .selectHost (currentRegion .getHosts ());
111
-
112
- String route = host .getRoute ();
113
- try (CloseableHttpClient client = newHttpClient ()) {
114
- LOGGER .info ("[SESSION_ATTEMPTED] [{}] [{}] [{}] [{}] [{}]" , user , remoteHost , browser , route , attempt );
115
-
116
- String target = route + request .getRequestURI ();
117
- HttpResponse hubResponse = client .execute (post (target , message ));
118
- JsonMessage hubMessage = JsonMessageFactory .from (hubResponse .getEntity ().getContent ());
119
-
120
- if (hubResponse .getStatusLine ().getStatusCode () == SC_OK ) {
121
- String sessionId = hubMessage .getSessionId ();
122
- hubMessage .setSessionId (host .getRouteId () + sessionId );
123
- replyWithOk (hubMessage , response );
124
- LOGGER .info ("[SESSION_CREATED] [{}] [{}] [{}] [{}] [{}] [{}]" ,
125
- user , remoteHost , browser , route , sessionId , attempt );
126
- stats .startSession ();
127
- return ;
106
+ try (CloseableHttpClient client = newHttpClient ()) {
107
+ while (!allRegions .isEmpty ()) {
108
+ attempt ++;
109
+
110
+ Region currentRegion = hostSelectionStrategy .selectRegion (allRegions , unvisitedRegions );
111
+ Host host = hostSelectionStrategy .selectHost (currentRegion .getHosts ());
112
+
113
+ String route = host .getRoute ();
114
+ try {
115
+ LOGGER .info ("[SESSION_ATTEMPTED] [{}] [{}] [{}] [{}] [{}]" , user , remoteHost , browser , route , attempt );
116
+
117
+ String target = route + request .getRequestURI ();
118
+ HttpResponse hubResponse = client .execute (post (target , message ));
119
+ JsonMessage hubMessage = JsonMessageFactory .from (hubResponse .getEntity ().getContent ());
120
+
121
+ if (hubResponse .getStatusLine ().getStatusCode () == SC_OK ) {
122
+ String sessionId = hubMessage .getSessionId ();
123
+ hubMessage .setSessionId (host .getRouteId () + sessionId );
124
+ replyWithOk (hubMessage , response );
125
+ LOGGER .info ("[SESSION_CREATED] [{}] [{}] [{}] [{}] [{}] [{}]" ,
126
+ user , remoteHost , browser , route , sessionId , attempt );
127
+ stats .startSession ();
128
+ return ;
129
+ }
130
+ LOGGER .warn ("[SESSION_FAILED] [{}] [{}] [{}] [{}] - {}" ,
131
+ user , remoteHost , browser , route , hubMessage .getErrorMessage ());
132
+ } catch (JsonProcessingException exception ) {
133
+ LOGGER .error ("[BAD_HUB_JSON] [{}] [{}] [{}] - {}" , "" ,
134
+ user , remoteHost , browser , route , exception .getMessage ());
135
+ } catch (IOException exception ) {
136
+ LOGGER .error ("[HUB_COMMUNICATION_FAILURE] [{}] [{}] [{}] - {}" ,
137
+ user , remoteHost , browser , route , exception .getMessage ());
128
138
}
129
- LOGGER .warn ("[SESSION_FAILED] [{}] [{}] [{}] [{}] - {}" ,
130
- user , remoteHost , browser , route , hubMessage .getErrorMessage ());
131
- } catch (JsonProcessingException exception ) {
132
- LOGGER .error ("[BAD_HUB_JSON] [{}] [{}] [{}] - {}" , "" ,
133
- user , remoteHost , browser , route , exception .getMessage ());
134
- } catch (IOException exception ) {
135
- LOGGER .error ("[HUB_COMMUNICATION_FAILURE] [{}] [{}] [{}] - {}" ,
136
- user , remoteHost , browser , route , exception .getMessage ());
137
- }
138
139
139
- currentRegion .getHosts ().remove (host );
140
- if (currentRegion .getHosts ().isEmpty ()) {
141
- allRegions .remove (currentRegion );
142
- }
140
+ currentRegion .getHosts ().remove (host );
141
+ if (currentRegion .getHosts ().isEmpty ()) {
142
+ allRegions .remove (currentRegion );
143
+ }
143
144
144
- unvisitedRegions .remove (currentRegion );
145
- if (unvisitedRegions .isEmpty ()) {
146
- unvisitedRegions = new ArrayList <>(allRegions );
145
+ unvisitedRegions .remove (currentRegion );
146
+ if (unvisitedRegions .isEmpty ()) {
147
+ unvisitedRegions = new ArrayList <>(allRegions );
148
+ }
147
149
}
148
150
}
149
151
0 commit comments