Package net.sf.sahi.session

Examples of net.sf.sahi.session.Session


    public SimpleHttpResponse getRecordedSteps(final HttpRequest request) {
      return new StepWiseRecorder().getSteps(request);
    }
   
    public void setLastIdentifiedElement(final HttpRequest request) {
      Session session = request.session();
    session.setVariable("__sahi__lastIdentifiedElement", request.getParameter("element"));
    }
View Full Code Here


      Session session = request.session();
    session.setVariable("__sahi__lastIdentifiedElement", request.getParameter("element"));
    }
   
    public SimpleHttpResponse getLastIdentifiedElement(final HttpRequest request) {
      Session session = request.session();
    String val = session.getVariable("__sahi__lastIdentifiedElement");
    session.setVariable("__sahi__lastIdentifiedElement", null);
    return new SimpleHttpResponse(val == null ? "" : val);
  }
View Full Code Here

    if (!"true".equals(request.getParameter("fromBrowser")))
      setStep(request, "_sahi.openController()");
    }

  private void record(final HttpRequest request) {
    Session session = request.session();
    session.setIsRecording(true);
      new StepWiseRecorder().start(request);
    session.setIsPlaying(false);
  }
View Full Code Here

    session.setIsPlaying(false);
  }

    public void stopRecording(final HttpRequest request) {
      new StepWiseRecorder().stop(request);
      Session session = request.session();
      session.setIsWindowOpen(false);
    if (!"true".equals(request.getParameter("fromBrowser")))
      setStep(request, "_sahi.closeController()");
    session.setIsRecording(false);
    session.setIsPlaying(true);     
    }
View Full Code Here

    public SimpleHttpResponse isRecording(final HttpRequest request) {
      return new SimpleHttpResponse("" + request.session().isRecording());
    }
   
  private void setStep(final HttpRequest request, String step) {
    Session session = request.session();
    session.getScriptRunner().setStep(step, "");
  }   
View Full Code Here

*/


public class Recorder2 {   
    public void addRecordedStep(HttpRequest request){
        Session session = request.session();
        String steps = session.getVariable("CONTROLLER_RecordedSteps");
      String step = request.getParameter("step");
    steps = (steps != null) ? (steps + "\n" + step) : step;
    session.setVariable("CONTROLLER_RecordedSteps", steps);
//    String fileName = session.getVariable("CONTROLLER_recordFile");
//    if (!Utils.isBlankOrNull(fileName)){
//      Utils.writeFile(steps, fileName, true);
//    }
    }
View Full Code Here

//      Utils.writeFile(steps, fileName, true);
//    }
    }

    public HttpResponse getRecordedSteps(HttpRequest request){
        Session session = request.session();
        String steps = session.getVariable("CONTROLLER_RecordedSteps");
        return new NoCacheHttpResponse(steps == null ? "" : steps);
    }
View Full Code Here

        String steps = session.getVariable("CONTROLLER_RecordedSteps");
        return new NoCacheHttpResponse(steps == null ? "" : steps);
    }
   
    public void setRecordedSteps(HttpRequest request){
        Session session = request.session();
        String content = request.getParameter("content");
//        boolean append = "1".equals(request.getParameter("append"));
//    String fileName = "" + session.getVariable("CONTROLLER_recordFile");
//    if (append) content = Utils.readFileAsString(fileName) + "\n" + content;
//        System.out.println(content);
        session.setVariable("CONTROLLER_RecordedSteps", content);
//    if (!Utils.isBlankOrNull(fileName)){
//      Utils.writeFile(content, fileName, !append);
//    }     
    }
View Full Code Here

//      Utils.writeFile(content, fileName, !append);
//    }     
    }
   
    public HttpResponse setFile(HttpRequest request){
        Session session = request.session();
        String fileName = request.getParameter("file");
        if (Utils.isBlankOrNull(fileName)){
          fileName = Utils.concatPaths(Configuration.getScriptRoots()[0], "/tmp/" + session.id() + ".sah");
        }
    session.setVariable("CONTROLLER_recordFile", fileName);
    return new SimpleHttpResponse(fileName);
    }
View Full Code Here

        return processHttp(requestFromBrowser, true);
    }

    public HttpResponse processHttp(HttpRequest requestFromBrowser, boolean modify) {
      try {
        Session session = requestFromBrowser.session();
      ThreadLocalMap.put("session", session);

        TrafficLogger.storeRequestHeader(requestFromBrowser.rawHeaders(), "unmodified");
        TrafficLogger.storeRequestBody(requestFromBrowser.data(), "unmodified");
        requestFromBrowser.modifyForFetch();
        TrafficLogger.storeRequestHeader(requestFromBrowser.rawHeaders(), "modified");
      String urlStr = requestFromBrowser.url();
      URL url =  new URL(urlStr);
      if (logger.isLoggable(Level.FINE)){
        logger.fine(url.toString());
      }
      HttpURLConnection connection = (HttpURLConnection)url.openConnection();
      connection.setDefaultUseCaches(true);
      connection.setUseCaches(true);
      HttpURLConnection.setFollowRedirects(false);
      if (logger.isLoggable(Level.FINEST)){
        logger.finest("requestFromBrowser.headers():");
        logger.finest(requestFromBrowser.headers().toString());
      }
      setConnectionRequestHeaders(requestFromBrowser, connection);

      if (logger.isLoggable(Level.FINEST)){
        logger.finest("Request headers set on connection:");
        logger.finest(getReqHeaders(connection));
      }     

      HttpResponse response = null;
      int responseCode = -1;
      try{
        connection.setRequestMethod(requestFromBrowser.method().toUpperCase());
        if (requestFromBrowser.isPost() || requestFromBrowser.isPut()){
          if (logger.isLoggable(Level.FINEST)){
            logger.finest("In post requestFromBrowser.data() = " + requestFromBrowser.data());
          }
          connection.setDoOutput(true);
          OutputStream outputStreamToHost = connection.getOutputStream();
          outputStreamToHost.write(requestFromBrowser.data());
          outputStreamToHost.close();
        }
        InputStream inputStreamFromHost = null;
        responseCode = connection.getResponseCode();
        if (logger.isLoggable(Level.FINE)){
          logger.fine("responseCode  = " + responseCode);
        }
        if (responseCode < 400){
          inputStreamFromHost = connection.getInputStream();
            }else{
              if (logger.isLoggable(Level.FINE)){
            logger.fine("Fetching error stream");
          }
              inputStreamFromHost = connection.getErrorStream();
            }
        boolean isGZIP = "gzip".equals(connection.getContentEncoding());
        if (logger.isLoggable(Level.FINER)){
          logger.finer("isGZIP=" + isGZIP + "; connection.getContentEncoding()=" + connection.getContentEncoding());
        }       
        if (isGZIP){
          if (logger.isLoggable(Level.FINE)){
            logger.fine("Using GZIPInputStream");
          }
          try {
            inputStreamFromHost = new GZIPInputStream(inputStreamFromHost);
          } catch (IOException ioe) {
            // happens for redirects etc. where there is no body. Ignore
          }
        }
        if (responseCode >= 500 && !requestFromBrowser.isAjax()){
          if (logger.isLoggable(Level.FINE)){
            logger.fine("Returning get5xxResponse");
          }
          response = getWrappedResponse(get5xxResponse(responseCode, inputStreamFromHost));
        } else if (responseCode == 401){
          if (logger.isLoggable(Level.FINE)){
            logger.fine("Returning process401");
          }
          response = process401(connection, inputStreamFromHost);
        }else {
          response = getResponse(inputStreamFromHost, connection);
          TrafficLogger.storeResponseHeader(response.headers().toString().getBytes(), "unmodified");
          TrafficLogger.storeResponseBody(response.data(), "unmodified");
        }
       
        if (requestFromBrowser.isAjax() && responseCode > 300 && responseCode < 308){
          String redirectedTo = response.getLastSetValueOfHeader("Location");
          if (redirectedTo != null) session.addAjaxRedirect(redirectedTo);
        }
       
        if (isGZIP) {
          response.removeHeader("Content-Encoding", "gzip");
          if (response instanceof StreamingHttpResponse) response.setContentLength(-1);
        }
       
      }catch(IOException uhe){
        if (uhe instanceof SSLHandshakeException)
          uhe.printStackTrace();
        if (logger.isLoggable(Level.WARNING) && !urlStr.contains("DesignerOutput")){
          logger.warning("Returning CannotConnectResponse for: " + urlStr);
          logger.fine(Utils.getStackTraceString(uhe));
        }
        response = getWrappedResponse(getCannotConnectResponse(uhe));
      }
      if (responseCode != 204 && responseCode != 304){
        String contentTypeHeader = response.contentTypeHeader();
        boolean downloadContentType = isDownloadContentType(contentTypeHeader);
        boolean attachment = response.isAttachment();

        String fileName = null;
        boolean contentDispositionForcesDownload = false;
     
        if (fileName == nullfileName = requestFromBrowser.fileName();
       
        boolean downloadURL = isDownloadURL(urlStr);
        if (logger.isLoggable(Level.FINER)){
          logger.finer("downloadURL = " + downloadURL);
          logger.finer("response.isAttachment() = " + attachment);
          logger.finer("fileName = " + fileName);
          logger.finer("contentTypeHeader = " + contentTypeHeader);
          logger.finer("downloadContentType = " + downloadContentType);
          logger.finer("Content-Disposition=" + response.getLastSetValueOfHeader("Content-Disposition"));
        }
        if (responseCode == 200
            && (downloadContentType ||
                contentDispositionForcesDownload ||
                downloadURL)) {
          if (logger.isLoggable(Level.INFO)){
            StringBuilder sb = new StringBuilder();
            sb.append("\n-- Calling downloadFile --\n");
            sb.append(requestFromBrowser.url());
            sb.append("\ndownloadURL = " + downloadURL);
            sb.append("\nresponse.isAttachment() = " + attachment);
            sb.append("\nfileName = " + fileName);
            sb.append("\ncontentTypeHeader = " + contentTypeHeader);
            sb.append("\ndownloadContentType = " + downloadContentType);
            sb.append("\nContent-Disposition=" + response.getLastSetValueOfHeader("Content-Disposition"));
            sb.append("\ncontentDispositionForcesDownload = " + contentDispositionForcesDownload);
            sb.append("\n--");
            logger.info(sb.toString());
          }
          downloadFile(requestFromBrowser, response, fileName);
          if (session.sendHTMLResponseAfterFileDownload()) {
            response = getWrappedResponse(getFileDownloadedResponse(fileName));
          } else {
            session.set204(true);
            return new NoContentResponse();
          }
        }
        response = addFilters(requestFromBrowser, modify, response, responseCode);
      }
      if (responseCode == 204){
        session.set204(true);
      }
//      Can be used to induce a delay in playback for testing Sahi
//      if (requestFromBrowser.url().contains("DropDownListExample.swf")) {
//        Thread.sleep(10000);
//      }
View Full Code Here

TOP

Related Classes of net.sf.sahi.session.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.