public SeleneseCommand parse(EnvironmentManager environmentManager) { final String command = parameters.get("cmd"); if (command.equals(NEW_BROWSER_SESSION)) { final Environment environment; final String environmentName; environmentName = parameters.get("1"); environment = environmentManager.environment(environmentName); if (null == environment) { throw new CommandParsingException("ERROR: Unknown environment '" + environmentName + "'"); } parameters.put("1", environment.browser()); return new NewBrowserSessionCommand(environment, parameters); } else if (command.equals(TEST_COMPLETE)) { return new TestCompleteCommand(retrieveSessionId(parameters), parameters); } else { return new SeleneseCommand(retrieveSessionId(parameters), parameters); } }
public Response execute(RemoteControlPool pool) throws IOException { final RemoteControlProxy remoteControl; final Response response; if (null == sessionId) { return new Response("Selenium Driver error: No sessionId provided for command '" + parameters.toString() + "'"); } remoteControl = pool.retrieve(sessionId()); pool.updateSessionLastActiveAt(sessionId); response = remoteControl.forward(parameters()); pool.updateSessionLastActiveAt(sessionId); return response; }
public Response execute(RemoteControlPool pool) throws IOException { RemoteControlProxy remoteControl; final String sessionId; final Response response; remoteControl = pool.reserve(environment); if (null == remoteControl) { final String message = "No available remote control for environment '" + environment.name() + "'"; logger.warn(message); return new Response(message); } try { response = remoteControl.forward(parameters()); sessionId = parseSessionId(response.body()); if (null == sessionId) { pool.release(remoteControl); return new Response("Could not retrieve a new session"); } pool.associateWithSession(remoteControl, sessionId); pool.updateSessionLastActiveAt(sessionId); return response; } catch (Exception e) { logger.error("Problem while requesting new browser session", e); pool.release(remoteControl); return new Response(e.getMessage()); } }
protected Response forward(HttpParameters parameters, DynamicRemoteControlPool pool, EnvironmentManager environmentManager) throws IOException { final SeleneseCommand command; final Response response; LOGGER.info("Processing '" + parameters.toString() + "'"); try { command = new HttpCommandParser(parameters).parse(environmentManager); response = command.execute(pool); } catch (CommandParsingException e) { LOGGER.error("Failed to parse '" + parameters.toString() + "' : " + e.getMessage()); return new Response(e.getMessage()); } catch (NoSuchEnvironmentException e) { LOGGER.error("Could not find any remote control providing the '" + e.environment() + "' environment. Please make sure you started some remote controls which registered as offering this environment."); return new Response(e.getMessage()); } LOGGER.info("Responding with " + response.statusCode() + "/ '" + response.body() + "'"); return response; }
public SeleneseCommand parse(EnvironmentManager environmentManager) { final String command = parameters.get("cmd"); if (command.equals(NEW_BROWSER_SESSION)) { final Environment environment; final String environmentName; environmentName = parameters.get("1"); environment = environmentManager.environment(environmentName); if (null == environment) { throw new CommandParsingException("ERROR: Unknown environment '" + environmentName + "'"); } parameters.put("1", environment.browser()); return new NewBrowserSessionCommand(environment, parameters); } else if (command.equals(TEST_COMPLETE)) { return new TestCompleteCommand(retrieveSessionId(parameters), parameters); } else { return new SeleneseCommand(retrieveSessionId(parameters), parameters); } }
public Response execute(RemoteControlPool pool) throws IOException { final RemoteControlProxy remoteControl; final Response response; if (null == sessionId) { return new Response("Selenium Driver error: No sessionId provided for command '" + parameters.toString() + "'"); } remoteControl = pool.retrieve(sessionId()); pool.updateSessionLastActiveAt(sessionId); response = remoteControl.forward(parameters()); pool.updateSessionLastActiveAt(sessionId); return response; }
public Response execute(RemoteControlPool pool) throws IOException { RemoteControlProxy remoteControl; final String sessionId; final Response response; remoteControl = pool.reserve(environment); if (null == remoteControl) { final String message = "No available remote control for environment '" + environment.name() + "'"; logger.warn(message); return new Response(message); } try { response = remoteControl.forward(parameters()); sessionId = parseSessionId(response.body()); if (null == sessionId) { pool.release(remoteControl); return new Response("Could not retrieve a new session"); } pool.associateWithSession(remoteControl, sessionId); pool.updateSessionLastActiveAt(sessionId); return response; } catch (Exception e) { logger.error("Problem while requesting new browser session", e); pool.release(remoteControl); return new Response(e.getMessage()); } }
protected Response forward(HttpParameters parameters, DynamicRemoteControlPool pool, EnvironmentManager environmentManager) throws IOException { final SeleneseCommand command; final Response response; LOGGER.info("Processing '" + parameters.toString() + "'"); try { command = new HttpCommandParser(parameters).parse(environmentManager); response = command.execute(pool); } catch (CommandParsingException e) { LOGGER.error("Failed to parse '" + parameters.toString() + "' : " + e.getMessage()); return new Response(e.getMessage()); } catch (NoSuchEnvironmentException e) { LOGGER.error("Could not find any remote control providing the '" + e.environment() + "' environment. Please make sure you started some remote controls which registered as offering this environment."); return new Response(e.getMessage()); } catch (NoSuchSessionException e) { LOGGER.error(e.getMessage()); return new Response(e.getMessage()); } final String responseBody = response.body(); if (responseBody.length() > 128) { final int truncated = responseBody.length() - 128; LOGGER.info(String.format("Responding with %d / %s...[%d characters truncated]", response.statusCode(), responseBody.substring(0, 128), truncated)); } else { LOGGER.info(String.format("Responding with %d / %s", response.statusCode(), responseBody)); } return response; }