Bug 42867 - Only default parameters of Java Request Samplers are stored
Summary: Only default parameters of Java Request Samplers are stored
Status: NEEDINFO
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: 3.1
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-12 04:04 UTC by chris.p
Modified: 2016-12-29 00:24 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description chris.p 2007-07-12 04:04:47 UTC
I created a new JavaSamplerClient by extending AbstractJavaSamplerClient. The
method getDefaultParameters returns five parameters with default values.

Everything works fine, but when I add a new Parameter to the Java Request, it
disappears when selecting another element in the left tree and changing back to
the Java Request.

If the Java Request settings are still open when executing the Test Plan, the
additional Parameter is handed over to the Java Request correctly. The parameter
even is stored in the JMX file, but when the file is loaded again, it disappears
again.
Comment 1 chris.p 2007-07-12 04:43:40 UTC
According to the documentation, the Add/Delete buttons do not serve any purpose.
So this is a feature request and not a bug report.

It would be great, if this feature could be implemented soon. If this is not
possible, please tell me. Then I will have to find another solution for my problem.

Thank You!
Comment 2 Sebb 2007-07-12 05:56:09 UTC
Unlikely to be fixed in near future, so if you want a quick solution, I 
suggest you add some more optional parameters to your client.
Comment 3 Aleksey 2013-10-16 07:58:27 UTC
I have a same problem. But I can to fix it.
To fix this bug you may apply this patch:

Add this code to the JavaConfigGui.java (version 2.9):

public void actionPerformed(ActionEvent evt) {
...
    if (currArgs.getArgumentCount() != 0) {
       // Already configured - skip getting defaults
       argsPanel.configure(currArgs);
       return;
    }
...


Full method code:

    @Override
    public void actionPerformed(ActionEvent evt) {
        if (evt.getSource() == classnameCombo) {
            String className = ((String) classnameCombo.getSelectedItem()).trim();
            try {
                JavaSamplerClient client = (JavaSamplerClient) Class.forName(className, true,
                        Thread.currentThread().getContextClassLoader()).newInstance();

                Arguments currArgs = new Arguments();
                argsPanel.modifyTestElement(currArgs);
                
                if (currArgs.getArgumentCount() != 0) {
                    // Already configured - skip getting defaults
                    argsPanel.configure(currArgs);
                    return;
                }
                
                Map<String, String> currArgsMap = currArgs.getArgumentsAsMap();

                Arguments newArgs = new Arguments();
                Arguments testParams = null;
                try {
                    testParams = client.getDefaultParameters();
                } catch (AbstractMethodError e) {
                    log.warn("JavaSamplerClient doesn't implement "
                            + "getDefaultParameters.  Default parameters won't "
                            + "be shown.  Please update your client class: " + className);
                }

                if (testParams != null) {
                    PropertyIterator i = testParams.getArguments().iterator();
                    while (i.hasNext()) {
                        Argument arg = (Argument) i.next().getObjectValue();
                        String name = arg.getName();
                        String value = arg.getValue();

                        // If a user has set parameters in one test, and then
                        // selects a different test which supports the same
                        // parameters, those parameters should have the same
                        // values that they did in the original test.
                        if (currArgsMap.containsKey(name)) {
                            String newVal = currArgsMap.get(name);
                            if (newVal != null && newVal.length() > 0) {
                                value = newVal;
                            }
                        }
                        newArgs.addArgument(name, value);
                    }
                }

                argsPanel.configure(newArgs);
            } catch (Exception e) {
                log.error("Error getting argument list for " + className, e);
            }
        }
    }
Comment 4 Peter Lambrechtsen 2014-05-18 01:29:45 UTC
Any chance the below patch could get applied to trunk?
Comment 5 Milamber 2014-05-18 08:45:22 UTC

Unfortunately, this fix is not correct with the logic of the Java Sampler. 

With this patch, if I add a Java Sampler with JavaTest, I have some parameters (like ResultData, SamplerData, etc.), then (always in the same sampler and without any modification), when I change the classname to SleepTest, I keep the JavaTest parameters and I don't have the SleepTest params (SleepTime and SleepMask)! 

It's normal to reset the params when you change the classname (the if statement : "if (evt.getSource() == classnameCombo) { }").

If your issue is to allow to save the additional params added by the Add button, the patch would be more bigger.
Comment 6 Peter Lambrechtsen 2014-05-23 22:57:38 UTC
(In reply to Milamber from comment #5)
> 
> Unfortunately, this fix is not correct with the logic of the Java Sampler. 
> 
> With this patch, if I add a Java Sampler with JavaTest, I have some
> parameters (like ResultData, SamplerData, etc.), then (always in the same
> sampler and without any modification), when I change the classname to
> SleepTest, I keep the JavaTest parameters and I don't have the SleepTest
> params (SleepTime and SleepMask)! 

But that is easy to work-around, just remove all the values and then select the class you want and the defaults get added in. That seemed to work fine for me and didn't add any more sigficiant complexity in the process, just needed to know if I didn't want the current values for that sampler.

> 
> It's normal to reset the params when you change the classname (the if
> statement : "if (evt.getSource() == classnameCombo) { }").
> 
> If your issue is to allow to save the additional params added by the Add
> button, the patch would be more bigger.

Agreed, but that would require quite a change to the logic as it would require knowing if you had just changed the Java sampler or not. However this patch does resolve the issue without needing a complete re-write of the sampler.