Пример #1
0
  private NodeList load()
      throws IOException, FileNotFoundException, ParserConfigurationException, SAXException,
          TransformerException {
    InputStream fis = null;
    NodeList nl = null;
    try {
      DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

      fis = new FileInputStream(fileName);
      nl = XPathAPI.selectNodeList(builder.parse(fis), xpath);
      log.debug("found " + nl.getLength());

    } catch (FileNotFoundException e) {
      log.warn(e.toString());
      throw e;
    } catch (IOException e) {
      log.warn(e.toString());
      throw e;
    } catch (ParserConfigurationException e) {
      log.warn(e.toString());
      throw e;
    } catch (SAXException e) {
      log.warn(e.toString());
      throw e;
    } catch (TransformerException e) {
      log.warn(e.toString());
      throw e;
    } finally {
      JOrphanUtils.closeQuietly(fis);
    }
    return nl;
  }
Пример #2
0
  /**
   * Read the whole file content and return it as a string.
   *
   * @return the content of the file
   */
  public String getText() {
    String lineEnd = System.getProperty("line.separator"); // $NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    Reader reader = null;
    BufferedReader br = null;
    try {
      if (encoding == null) {
        reader = new FileReader(this);
      } else {
        reader = new InputStreamReader(new FileInputStream(this), encoding);
      }
      br = new BufferedReader(reader);
      String line = "NOTNULL"; // $NON-NLS-1$
      while (line != null) {
        line = br.readLine();
        if (line != null) {
          sb.append(line + lineEnd);
        }
      }
    } catch (IOException ioe) {
      log.error("", ioe); // $NON-NLS-1$
    } finally {
      JOrphanUtils.closeQuietly(br); // closes reader as well
    }

    return sb.toString();
  }
  /**
   * Listen on the daemon port and handle incoming requests. This method will not exit until {@link
   * #stopServer()} is called or an error occurs.
   */
  @Override
  public void run() {
    except = null;
    running = true;
    ServerSocket mainSocket = null;

    try {
      log.info("Creating HttpMirror ... on port " + daemonPort);
      mainSocket = new ServerSocket(daemonPort);
      mainSocket.setSoTimeout(ACCEPT_TIMEOUT);
      log.info("HttpMirror up and running!");

      while (running) {
        try {
          // Listen on main socket
          Socket clientSocket = mainSocket.accept();
          if (running) {
            // Pass request to new thread
            HttpMirrorThread thd = new HttpMirrorThread(clientSocket);
            log.debug("Starting new Mirror thread");
            thd.start();
          } else {
            log.warn("Server not running");
            JOrphanUtils.closeQuietly(clientSocket);
          }
        } catch (InterruptedIOException e) {
          // Timeout occurred. Ignore, and keep looping until we're
          // told to stop running.
        }
      }
      log.info("HttpMirror Server stopped");
    } catch (Exception e) {
      except = e;
      log.warn("HttpMirror Server stopped", e);
    } finally {
      JOrphanUtils.closeQuietly(mainSocket);
    }
  }
Пример #4
0
 /**
  * Create the file with the given string as content -- or replace it's content with the given
  * string if the file already existed.
  *
  * @param body New content for the file.
  */
 public void setText(String body) {
   Writer writer = null;
   try {
     if (encoding == null) {
       writer = new FileWriter(this);
     } else {
       writer = new OutputStreamWriter(new FileOutputStream(this), encoding);
     }
     writer.write(body);
     writer.flush();
   } catch (IOException ioe) {
     log.error("", ioe);
   } finally {
     JOrphanUtils.closeQuietly(writer);
   }
 }
 @Override
 public void actionPerformed(ActionEvent ev) {
   if (ev.getSource() == saveTable) {
     JFileChooser chooser = FileDialoger.promptToSaveFile("summary.csv"); // $NON-NLS-1$
     if (chooser == null) {
       return;
     }
     FileWriter writer = null;
     try {
       writer = new FileWriter(chooser.getSelectedFile());
       CSVSaveService.saveCSVStats(model, writer, saveHeaders.isSelected());
     } catch (FileNotFoundException e) {
       log.warn(e.getMessage());
     } catch (IOException e) {
       log.warn(e.getMessage());
     } finally {
       JOrphanUtils.closeQuietly(writer);
     }
   }
 }
 @Override
 public void actionPerformed(ActionEvent ev) {
   if (ev.getSource() == saveTable) {
     JFileChooser chooser = FileDialoger.promptToSaveFile("synthesis.csv"); // $NON-NLS-1$
     if (chooser == null) {
       return;
     }
     FileWriter writer = null;
     try {
       writer = new FileWriter(chooser.getSelectedFile()); // TODO
       // Charset ?
       CSVSaveService.saveCSVStats(
           getAllTableData(model, FORMATS),
           writer,
           saveHeaders.isSelected() ? getLabels(COLUMNS) : null);
     } catch (FileNotFoundException e) {
       log.warn(e.getMessage());
     } catch (IOException e) {
       log.warn(e.getMessage());
     } finally {
       JOrphanUtils.closeQuietly(writer);
     }
   }
 }
 @Override
 public void actionPerformed(ActionEvent event) {
   boolean forceReloadData = false;
   final Object eventSource = event.getSource();
   if (eventSource == displayButton) {
     actionMakeGraph();
   } else if (eventSource == saveGraph) {
     saveGraphToFile = true;
     try {
       ActionRouter.getInstance()
           .getAction(ActionNames.SAVE_GRAPHICS, SaveGraphics.class.getName())
           .doAction(new ActionEvent(this, 1, ActionNames.SAVE_GRAPHICS));
     } catch (Exception e) {
       log.error(e.getMessage());
     }
   } else if (eventSource == saveTable) {
     JFileChooser chooser = FileDialoger.promptToSaveFile("statistics.csv"); // $NON-NLS-1$
     if (chooser == null) {
       return;
     }
     FileWriter writer = null;
     try {
       writer = new FileWriter(chooser.getSelectedFile()); // TODO Charset ?
       CSVSaveService.saveCSVStats(
           getAllTableData(), writer, saveHeaders.isSelected() ? COLUMNS : null);
     } catch (FileNotFoundException e) {
       log.warn(e.getMessage());
     } catch (IOException e) {
       log.warn(e.getMessage());
     } finally {
       JOrphanUtils.closeQuietly(writer);
     }
   } else if (eventSource == chooseForeColor) {
     Color color =
         JColorChooser.showDialog(
             null,
             JMeterUtils.getResString("aggregate_graph_choose_color"), // $NON-NLS-1$
             colorBarGraph);
     if (color != null) {
       colorForeGraph = color;
     }
   } else if (eventSource == syncWithName) {
     graphTitle.setText(namePanel.getName());
   } else if (eventSource == dynamicGraphSize) {
     // if use dynamic graph size is checked, we disable the dimension fields
     if (dynamicGraphSize.isSelected()) {
       graphWidth.setEnabled(false);
       graphHeight.setEnabled(false);
     } else {
       graphWidth.setEnabled(true);
       graphHeight.setEnabled(true);
     }
   } else if (eventSource == columnSelection) {
     if (columnSelection.isSelected()) {
       columnMatchLabel.setEnabled(true);
       applyFilterBtn.setEnabled(true);
       caseChkBox.setEnabled(true);
       regexpChkBox.setEnabled(true);
     } else {
       columnMatchLabel.setEnabled(false);
       applyFilterBtn.setEnabled(false);
       caseChkBox.setEnabled(false);
       regexpChkBox.setEnabled(false);
       // Force reload data
       forceReloadData = true;
     }
   }
   // Not 'else if' because forceReloadData
   if (eventSource == applyFilterBtn || forceReloadData) {
     if (columnSelection.isSelected()
         && columnMatchLabel.getText() != null
         && columnMatchLabel.getText().length() > 0) {
       pattern = createPattern(columnMatchLabel.getText());
     } else if (forceReloadData) {
       pattern = null;
       matcher = null;
     }
     if (getFile() != null && getFile().length() > 0) {
       clearData();
       FilePanel filePanel = (FilePanel) getFilePanel();
       filePanel.actionPerformed(event);
     }
   } else if (eventSource instanceof JButton) {
     // Changing color for column
     JButton btn = ((JButton) eventSource);
     if (btn.getName() != null) {
       try {
         BarGraph bar = eltList.get(Integer.parseInt(btn.getName()));
         Color color = JColorChooser.showDialog(null, bar.getLabel(), bar.getBackColor());
         if (color != null) {
           bar.setBackColor(color);
           btn.setBackground(bar.getBackColor());
         }
       } catch (NumberFormatException nfe) {
       } // nothing to do
     }
   }
 }
Пример #8
0
  public boolean runTestPlan(String testPlanFilename) {

    jmeterResults = "";
    createJmeterEngine();
    File f = new File(testPlanFilename);
    if (!f.exists() || !f.isFile()) {
      jmeterResults += "Could not open " + testPlanFilename;
      System.out.println(jmeterResults);
      return false;
    }

    FileInputStream reader = null;
    try {
      reader = new FileInputStream(new File(testPlanFilename));
      currentHashTree = SaveService.loadTree(reader);
      // store log file in ./FitNesseRoot/files/testResults/testPlanFilename.log
      String logFile =
          new File(jmeterLogPath, (new File(testPlanFilename).getName() + ".log"))
              .getCanonicalPath();
      lastJmeterLog = logFile;

      @SuppressWarnings("deprecation") // Deliberate use of deprecated ctor
      JMeterTreeModel treeModel =
          new JMeterTreeModel(new Object()); // Create non-GUI version to avoid headless problems
      JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();
      treeModel.addSubTree(currentHashTree, root);

      // Hack to resolve ModuleControllers in non GUI mode
      SearchByClass<ReplaceableController> replaceableControllers =
          new SearchByClass<ReplaceableController>(ReplaceableController.class);
      currentHashTree.traverse(replaceableControllers);
      Collection<ReplaceableController> replaceableControllersRes =
          replaceableControllers.getSearchResults();
      for (Iterator<ReplaceableController> iter = replaceableControllersRes.iterator();
          iter.hasNext(); ) {
        ReplaceableController replaceableController = iter.next();
        replaceableController.resolveReplacementSubTree(root);
      }

      // Remove the disabled items
      // For GUI runs this is done in Start.java
      JMeter.convertSubTree(currentHashTree);

      Summariser summer = null;
      String summariserName =
          JMeterUtils.getPropDefault("summariser.name", "summary"); // $NON-NLS-1$
      if (summariserName.length() > 0) {
        // log.info("Creating summariser <" + summariserName + ">");
        // println("Creating summariser <" + summariserName + ">");
        summer = new Summariser(summariserName);
      }

      if (logFile != null) {
        ResultCollector logger = new ResultCollector(summer);
        logger.setFilename(logFile);
        currentHashTree.add(currentHashTree.getArray()[0], logger);
      } else {
        // only add Summariser if it can not be shared with the ResultCollector
        if (summer != null) {
          currentHashTree.add(currentHashTree.getArray()[0], summer);
        }
      }

      // Used for remote notification of threads start/stop,see BUG 54152
      // Summariser uses this feature to compute correctly number of threads
      // when NON GUI mode is used
      currentHashTree.add(currentHashTree.getArray()[0], new RemoteThreadsListenerTestElement());

      jEngine.configure(currentHashTree);
      jEngine.runTest();
      // reader.close();
      JOrphanUtils.closeQuietly(reader);
      Util.waitForFileToExists(logFile, 5); // wait up to 5 seconds for file to exist
      String logStr = Util.fileToString(logFile);
      // logStr = logStr.replaceAll("\n", "<br/>\n");
      jmeterResults += logStr;
      jmeterResults += "Test " + testPlanFilename + " completed.";
      System.out.println("Test " + testPlanFilename + " completed.");

    } catch (Exception e) {
      e.printStackTrace();
      jmeterResults += "\r\nException: " + e.getMessage();
      return false;
    }
    return true;
  }