Search in sources :

Example 1 with IllegalUserActionException

use of org.apache.jmeter.exceptions.IllegalUserActionException in project jmeter by apache.

the class JMeter method setProxy.

/**
     * Sets a proxy server for the JVM if the command line arguments are
     * specified.
     */
private void setProxy(CLArgsParser parser) throws IllegalUserActionException {
    if (parser.getArgumentById(PROXY_USERNAME) != null) {
        Properties jmeterProps = JMeterUtils.getJMeterProperties();
        if (parser.getArgumentById(PROXY_PASSWORD) != null) {
            String u = parser.getArgumentById(PROXY_USERNAME).getArgument();
            String p = parser.getArgumentById(PROXY_PASSWORD).getArgument();
            Authenticator.setDefault(new ProxyAuthenticator(u, p));
            log.info("Set Proxy login: {}/{}", u, p);
            //for Httpclient
            jmeterProps.setProperty(HTTP_PROXY_USER, u);
            //for Httpclient
            jmeterProps.setProperty(HTTP_PROXY_PASS, p);
        } else {
            String u = parser.getArgumentById(PROXY_USERNAME).getArgument();
            Authenticator.setDefault(new ProxyAuthenticator(u, ""));
            log.info("Set Proxy login: {}", u);
            jmeterProps.setProperty(HTTP_PROXY_USER, u);
        }
    }
    if (parser.getArgumentById(PROXY_HOST) != null && parser.getArgumentById(PROXY_PORT) != null) {
        String h = parser.getArgumentById(PROXY_HOST).getArgument();
        String p = parser.getArgumentById(PROXY_PORT).getArgument();
        // $NON-NLS-1$
        System.setProperty("http.proxyHost", h);
        // $NON-NLS-1$
        System.setProperty("https.proxyHost", h);
        // $NON-NLS-1$
        System.setProperty("http.proxyPort", p);
        // $NON-NLS-1$
        System.setProperty("https.proxyPort", p);
        log.info("Set http[s].proxyHost: {} Port: {}", h, p);
    } else if (parser.getArgumentById(PROXY_HOST) != null || parser.getArgumentById(PROXY_PORT) != null) {
        // $NON-NLS-1$
        throw new IllegalUserActionException(JMeterUtils.getResString("proxy_cl_error"));
    }
    if (parser.getArgumentById(NONPROXY_HOSTS) != null) {
        String n = parser.getArgumentById(NONPROXY_HOSTS).getArgument();
        // $NON-NLS-1$
        System.setProperty("http.nonProxyHosts", n);
        // $NON-NLS-1$
        System.setProperty("https.nonProxyHosts", n);
        log.info("Set http[s].nonProxyHosts: {}", n);
    }
}
Also used : IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) Properties(java.util.Properties)

Example 2 with IllegalUserActionException

use of org.apache.jmeter.exceptions.IllegalUserActionException in project jmeter by apache.

the class JMeter method start.

/**
     * Takes the command line arguments and uses them to determine how to
     * startup JMeter.
     * 
     * Called reflectively by {@link NewDriver#main(String[])}
     * @param args The arguments for JMeter
     */
public void start(String[] args) {
    CLArgsParser parser = new CLArgsParser(args, options);
    String error = parser.getErrorString();
    if (error == null) {
        // Check option combinations
        boolean gui = parser.getArgumentById(NONGUI_OPT) == null;
        boolean nonGuiOnly = parser.getArgumentById(REMOTE_OPT) != null || parser.getArgumentById(REMOTE_OPT_PARAM) != null || parser.getArgumentById(REMOTE_STOP) != null;
        if (gui && nonGuiOnly) {
            error = "-r and -R and -X are only valid in non-GUI mode";
        }
    }
    if (null != error) {
        //NOSONAR
        System.err.println("Error: " + error);
        //NOSONAR
        System.out.println("Usage");
        //NOSONAR
        System.out.println(CLUtil.describeOptions(options).toString());
        // repeat the error so no need to scroll back past the usage to see it
        //NOSONAR
        System.out.println("Error: " + error);
        return;
    }
    try {
        // Also initialises JMeter logging
        initializeProperties(parser);
        Thread.setDefaultUncaughtExceptionHandler((Thread t, Throwable e) -> {
            if (!(e instanceof ThreadDeath)) {
                log.error("Uncaught exception: ", e);
                //NOSONAR
                System.err.println("Uncaught Exception " + e + ". See log file for details.");
            }
        });
        if (log.isInfoEnabled()) {
            log.info(JMeterUtils.getJMeterCopyright());
            log.info("Version {}", JMeterUtils.getJMeterVersion());
            //$NON-NLS-1$ //$NON-NLS-2$
            log.info("java.version={}", System.getProperty("java.version"));
            //$NON-NLS-1$ //$NON-NLS-2$
            log.info("java.vm.name={}", System.getProperty("java.vm.name"));
            //$NON-NLS-1$ //$NON-NLS-2$
            log.info("os.name={}", System.getProperty("os.name"));
            //$NON-NLS-1$ //$NON-NLS-2$
            log.info("os.arch={}", System.getProperty("os.arch"));
            //$NON-NLS-1$ //$NON-NLS-2$
            log.info("os.version={}", System.getProperty("os.version"));
            //$NON-NLS-1$ //$NON-NLS-2$
            log.info("file.encoding={}", System.getProperty("file.encoding"));
            log.info("Max memory     ={}", Runtime.getRuntime().maxMemory());
            log.info("Available Processors ={}", Runtime.getRuntime().availableProcessors());
            log.info("Default Locale={}", Locale.getDefault().getDisplayName());
            log.info("JMeter  Locale={}", JMeterUtils.getLocale().getDisplayName());
            log.info("JMeterHome={}", JMeterUtils.getJMeterHome());
            //$NON-NLS-1$ //$NON-NLS-2$
            log.info("user.dir  ={}", System.getProperty("user.dir"));
            //$NON-NLS-1$
            log.info("PWD       ={}", new File(".").getCanonicalPath());
            log.info("IP: {} Name: {} FullName: {}", JMeterUtils.getLocalHostIP(), JMeterUtils.getLocalHostName(), JMeterUtils.getLocalHostFullName());
        }
        setProxy(parser);
        updateClassLoader();
        if (log.isDebugEnabled()) {
            // $NON-NLS-1$
            String jcp = System.getProperty("java.class.path");
            String[] bits = jcp.split(File.pathSeparator);
            log.debug("ClassPath");
            for (String bit : bits) {
                log.debug(bit);
            }
        }
        // Set some (hopefully!) useful properties
        long now = System.currentTimeMillis();
        // $NON-NLS-1$
        JMeterUtils.setProperty("START.MS", Long.toString(now));
        // so it agrees with above
        Date today = new Date(now);
        // $NON-NLS-1$ $NON-NLS-2$
        JMeterUtils.setProperty("START.YMD", new SimpleDateFormat("yyyyMMdd").format(today));
        // $NON-NLS-1$ $NON-NLS-2$
        JMeterUtils.setProperty("START.HMS", new SimpleDateFormat("HHmmss").format(today));
        if (parser.getArgumentById(VERSION_OPT) != null) {
            displayAsciiArt();
        } else if (parser.getArgumentById(HELP_OPT) != null) {
            displayAsciiArt();
            //NOSONAR $NON-NLS-1$
            System.out.println(JMeterUtils.getResourceFileAsText("org/apache/jmeter/help.txt"));
        } else if (parser.getArgumentById(OPTIONS_OPT) != null) {
            displayAsciiArt();
            //NOSONAR
            System.out.println(CLUtil.describeOptions(options).toString());
        } else if (parser.getArgumentById(SERVER_OPT) != null) {
            // Start the server
            try {
                // $NON-NLS-1$
                RemoteJMeterEngineImpl.startServer(JMeterUtils.getPropDefault("server_port", 0));
                startOptionalServers();
            } catch (Exception ex) {
                //NOSONAR
                System.err.println("Server failed to start: " + ex);
                log.error("Giving up, as server failed with:", ex);
                throw ex;
            }
        } else {
            String testFile = null;
            CLOption testFileOpt = parser.getArgumentById(TESTFILE_OPT);
            if (testFileOpt != null) {
                testFile = testFileOpt.getArgument();
                if (USE_LAST_JMX.equals(testFile)) {
                    // most recent
                    testFile = LoadRecentProject.getRecentFile(0);
                }
            }
            CLOption testReportOpt = parser.getArgumentById(REPORT_GENERATING_OPT);
            if (testReportOpt != null) {
                // generate report from existing file
                String reportFile = testReportOpt.getArgument();
                extractAndSetReportOutputFolder(parser);
                ReportGenerator generator = new ReportGenerator(reportFile, null);
                generator.generate();
            } else if (parser.getArgumentById(NONGUI_OPT) == null) {
                // not non-GUI => GUI
                startGui(testFile);
                startOptionalServers();
            } else {
                // NON-GUI must be true
                extractAndSetReportOutputFolder(parser);
                CLOption rem = parser.getArgumentById(REMOTE_OPT_PARAM);
                if (rem == null) {
                    rem = parser.getArgumentById(REMOTE_OPT);
                }
                CLOption jtl = parser.getArgumentById(LOGFILE_OPT);
                String jtlFile = null;
                if (jtl != null) {
                    // $NON-NLS-1$
                    jtlFile = processLAST(jtl.getArgument(), ".jtl");
                }
                CLOption reportAtEndOpt = parser.getArgumentById(REPORT_AT_END_OPT);
                if (reportAtEndOpt != null && jtlFile == null) {
                    throw new IllegalUserActionException("Option -" + ((char) REPORT_AT_END_OPT) + " requires -" + ((char) LOGFILE_OPT) + " option");
                }
                startNonGui(testFile, jtlFile, rem, reportAtEndOpt != null);
                startOptionalServers();
            }
        }
    } catch (IllegalUserActionException e) {
        // NOSONAR
        //NOSONAR
        System.out.println("Incorrect Usage:" + e.getMessage());
        //NOSONAR
        System.out.println(CLUtil.describeOptions(options).toString());
    } catch (Throwable e) {
        // NOSONAR
        log.error("An error occurred: ", e);
        //NOSONAR
        System.out.println("An error occurred: " + e.getMessage());
        // FIXME Should we exit here ? If we are called by Maven or Jenkins
        System.exit(1);
    }
}
Also used : CLOption(org.apache.commons.cli.avalon.CLOption) Date(java.util.Date) ConfigurationException(org.apache.jmeter.report.config.ConfigurationException) JMeterException(org.apache.jorphan.util.JMeterException) FileNotFoundException(java.io.FileNotFoundException) ConversionException(com.thoughtworks.xstream.converters.ConversionException) SocketException(java.net.SocketException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) GenerationException(org.apache.jmeter.report.dashboard.GenerationException) ReportGenerator(org.apache.jmeter.report.dashboard.ReportGenerator) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) CLArgsParser(org.apache.commons.cli.avalon.CLArgsParser) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with IllegalUserActionException

use of org.apache.jmeter.exceptions.IllegalUserActionException in project jmeter by apache.

the class JMeterTreeModel method addComponent.

/**
     * Add a {@link TestElement} to a {@link JMeterTreeNode}
     * @param component The {@link TestElement} to be used as data for the newly created node
     * @param node The {@link JMeterTreeNode} into which the newly created node is to be inserted
     * @return new {@link JMeterTreeNode} for the given <code>component</code>
     * @throws IllegalUserActionException
     *             when the user object for the <code>node</code> is not an instance
     *             of {@link AbstractConfigGui}
     */
public JMeterTreeNode addComponent(TestElement component, JMeterTreeNode node) throws IllegalUserActionException {
    if (node.getUserObject() instanceof AbstractConfigGui) {
        throw new IllegalUserActionException("This node cannot hold sub-elements");
    }
    GuiPackage guiPackage = GuiPackage.getInstance();
    if (guiPackage != null) {
        // The node can be added in non GUI mode at startup
        guiPackage.updateCurrentNode();
        JMeterGUIComponent guicomp = guiPackage.getGui(component);
        guicomp.clearGui();
        guicomp.configure(component);
        guicomp.modifyTestElement(component);
        // put the gui object back
        guiPackage.getCurrentGui();
    // to the way it was.
    }
    JMeterTreeNode newNode = new JMeterTreeNode(component, this);
    // disable the loaded node
    try {
        newNode.setEnabled(component.isEnabled());
    } catch (Exception e) {
        // TODO - can this ever happen?
        newNode.setEnabled(true);
    }
    this.insertNodeInto(newNode, node, node.getChildCount());
    return newNode;
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) AbstractConfigGui(org.apache.jmeter.config.gui.AbstractConfigGui)

Example 4 with IllegalUserActionException

use of org.apache.jmeter.exceptions.IllegalUserActionException in project jmeter by apache.

the class Load method insertLoadedTree.

/**
     * Inserts (or merges) the tree into the GUI.
     * Does not check if the previous tree has been saved.
     * Clears the existing GUI test plan if we are inserting a complete plan.
     * @param id the id for the ActionEvent that is created
     * @param tree the tree to load
     * @param merging true if the tree is to be merged; false if it is to replace the existing tree
     * @return true if the loaded tree was a full test plan
     * @throws IllegalUserActionException if the tree cannot be merged at the selected position or the tree is empty
     */
// Does not appear to be used externally; called by #loadProjectFile()
public static boolean insertLoadedTree(final int id, final HashTree tree, final boolean merging) throws IllegalUserActionException {
    if (tree == null) {
        throw new IllegalUserActionException("Empty TestPlan or error reading test plan - see log file");
    }
    final boolean isTestPlan = tree.getArray()[0] instanceof TestPlan;
    // If we are loading a new test plan, initialize the tree with the testplan node we are loading
    final GuiPackage guiInstance = GuiPackage.getInstance();
    if (isTestPlan && !merging) {
        // Why does this not call guiInstance.clearTestPlan() ?
        // Is there a reason for not clearing everything?
        guiInstance.clearTestPlan((TestElement) tree.getArray()[0]);
    }
    if (merging) {
        // Check if target of merge is reasonable
        final TestElement te = (TestElement) tree.getArray()[0];
        if (!(te instanceof WorkBench || te instanceof TestPlan)) {
            // These are handled specially by addToTree
            final boolean ok = MenuFactory.canAddTo(guiInstance.getCurrentNode(), te);
            if (!ok) {
                String name = te.getName();
                String className = te.getClass().getName();
                className = className.substring(className.lastIndexOf('.') + 1);
                throw new IllegalUserActionException("Can't merge " + name + " (" + className + ") here");
            }
        }
    }
    final HashTree newTree = guiInstance.addSubTree(tree);
    guiInstance.updateCurrentGui();
    guiInstance.getMainFrame().getTree().setSelectionPath(new TreePath(((JMeterTreeNode) newTree.getArray()[0]).getPath()));
    final HashTree subTree = guiInstance.getCurrentSubTree();
    // Send different event wether we are merging a test plan into another test plan,
    // or loading a testplan from scratch
    ActionEvent actionEvent = new ActionEvent(subTree.get(subTree.getArray()[subTree.size() - 1]), id, merging ? ActionNames.SUB_TREE_MERGED : ActionNames.SUB_TREE_LOADED);
    ActionRouter.getInstance().actionPerformed(actionEvent);
    final JTree jTree = guiInstance.getMainFrame().getTree();
    if (EXPAND_TREE && !merging) {
        // don't automatically expand when merging
        for (int i = 0; i < jTree.getRowCount(); i++) {
            jTree.expandRow(i);
        }
    } else {
        jTree.expandRow(0);
    }
    jTree.setSelectionPath(jTree.getPathForRow(1));
    FocusRequester.requestFocus(jTree);
    return isTestPlan;
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) TestPlan(org.apache.jmeter.testelement.TestPlan) ActionEvent(java.awt.event.ActionEvent) TestElement(org.apache.jmeter.testelement.TestElement) WorkBench(org.apache.jmeter.testelement.WorkBench) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) GuiPackage(org.apache.jmeter.gui.GuiPackage) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 5 with IllegalUserActionException

use of org.apache.jmeter.exceptions.IllegalUserActionException in project jmeter by apache.

the class AddThinkTimeBetweenEachStep method addThinkTimeToChildren.

/**
     * Add Think Time to children of parentNode
     * @param guiPackage {@link GuiPackage}
     * @param parentNode Parent node of elements on which we add think times
     * @throws IllegalUserActionException 
     */
private void addThinkTimeToChildren(GuiPackage guiPackage, JMeterTreeNode parentNode) throws IllegalUserActionException {
    guiPackage.updateCurrentNode();
    boolean insertThinkTime = false;
    try {
        int index = 0;
        while (true) {
            if (index == parentNode.getChildCount()) {
                index++;
                break;
            }
            JMeterTreeNode childNode = (JMeterTreeNode) parentNode.getChildAt(index);
            Object userObject = childNode.getUserObject();
            if (userObject instanceof Sampler || userObject instanceof Controller) {
                insertThinkTime = true;
            }
            if (insertThinkTime) {
                JMeterTreeNode[] nodes = createThinkTime(guiPackage, parentNode);
                if (nodes.length != 2) {
                    throw new IllegalArgumentException("Invalid Think Time, expected 2 nodes, got:" + nodes.length);
                }
                index++;
                addNodesToTreeHierachically(guiPackage, parentNode, nodes, index);
                insertThinkTime = false;
            }
            index++;
        }
    } catch (Exception ex) {
        throw new IllegalUserActionException("Cannot add think times", ex);
    }
}
Also used : Sampler(org.apache.jmeter.samplers.Sampler) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) Controller(org.apache.jmeter.control.Controller) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Aggregations

IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)12 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)8 TestElement (org.apache.jmeter.testelement.TestElement)5 IOException (java.io.IOException)4 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)3 TestPlan (org.apache.jmeter.testelement.TestPlan)3 ActionEvent (java.awt.event.ActionEvent)2 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)2 InvalidVariableException (org.apache.jmeter.functions.InvalidVariableException)2 GuiPackage (org.apache.jmeter.gui.GuiPackage)2 JMeterGUIComponent (org.apache.jmeter.gui.JMeterGUIComponent)2 HashTree (org.apache.jorphan.collections.HashTree)2 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)2 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1