Java 类org.openqa.selenium.remote.http.HttpResponse 实例源码

项目:grid-refactor-remote-server    文件:DriverServlet.java   
private void handleCrossDomainRpc(
    HttpServletRequest servletRequest, HttpServletResponse servletResponse)
    throws ServletException, IOException {
  CrossDomainRpc rpc;

  try {
    rpc = new CrossDomainRpcLoader().loadRpc(servletRequest);
  } catch (IllegalArgumentException e) {
    servletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    servletResponse.getOutputStream().println(e.getMessage());
    servletResponse.getOutputStream().flush();
    return;
  }

  HttpRequest request = new HttpRequest(
      HttpMethod.valueOf(rpc.getMethod()),
      rpc.getPath());
  request.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
  request.setContent(rpc.getContent());

  HttpResponse response = commandHandler.handleRequest(request);
  sendResponse(response, servletResponse);
}
项目:grid-refactor-remote-server    文件:DriverServlet.java   
protected void handleRequest(
    HttpServletRequest servletRequest, HttpServletResponse servletResponse)
    throws ServletException, IOException {
  HttpRequest request = createInternalRequest(servletRequest);
  HttpResponse response = commandHandler.handleRequest(request);
  sendResponse(response, servletResponse);
}
项目:grid-refactor-remote-server    文件:DriverServlet.java   
private void sendResponse(HttpResponse response, HttpServletResponse servletResponse)
    throws IOException {
  servletResponse.setStatus(response.getStatus());
  for (String name : response.getHeaderNames()) {
    for (String value : response.getHeaders(name)) {
      servletResponse.addHeader(name, value);
    }
  }
  OutputStream output = servletResponse.getOutputStream();
  output.write(response.getContent());
  output.flush();
  output.close();
}