jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philippe Mouawad <philippe.moua...@gmail.com>
Subject Re: svn commit: r1776135 - in /jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http: control/CookieHandler.java control/HC3CookieHandler.java control/HC4CookieHandler.java gui/CookiePanel.java
Date Tue, 27 Dec 2016 14:25:33 GMT
On Tue, Dec 27, 2016 at 3:22 PM, Felix Schumacher <
felix.schumacher@internetallee.de> wrote:

> Am 27.12.2016 um 15:06 schrieb pmouawad@apache.org:
>
>> Author: pmouawad
>> Date: Tue Dec 27 14:06:11 2016
>> New Revision: 1776135
>>
>> URL: http://svn.apache.org/viewvc?rev=1776135&view=rev
>> Log:
>> Sonar : Fix errors, vulnerabilities
>>
>> Modified:
>>      jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/CookieHandler.java
>>      jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/HC3CookieHandler.java
>>      jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/HC4CookieHandler.java
>>      jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/gui/CookiePanel.java
>>
>> Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/CookieHandler.java
>> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/
>> org/apache/jmeter/protocol/http/control/CookieHandler.
>> java?rev=1776135&r1=1776134&r2=1776135&view=diff
>> ============================================================
>> ==================
>> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/CookieHandler.java (original)
>> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/CookieHandler.java Tue Dec 27 14:06:11 2016
>> @@ -53,5 +53,10 @@ public interface CookieHandler {
>>        * @return Cookie default policy name
>>        */
>>       String getDefaultPolicy();
>> +
>> +    /**
>> +     * @return Supported cookie policies
>> +     */
>> +    String[] getPolicies();
>>     }
>>
>> Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/HC3CookieHandler.java
>> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/
>> org/apache/jmeter/protocol/http/control/HC3CookieHandler.
>> java?rev=1776135&r1=1776134&r2=1776135&view=diff
>> ============================================================
>> ==================
>> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/HC3CookieHandler.java (original)
>> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/HC3CookieHandler.java Tue Dec 27 14:06:11 2016
>> @@ -39,7 +39,7 @@ public class HC3CookieHandler implements
>>      private static final Logger log = LoggingManager.getLoggerForCla
>> ss();
>>        static final String DEFAULT_POLICY_NAME = "compatibility";
>> -   public static final String[] AVAILABLE_POLICIES = new String[] {
>> +   private static final String[] AVAILABLE_POLICIES = new String[] {
>>          DEFAULT_POLICY_NAME,
>>          "default",
>>          "rfc2109",
>> @@ -51,6 +51,13 @@ public class HC3CookieHandler implements
>>       private final transient CookieSpec cookieSpec;
>>         /**
>> +     * Default constructor that uses {@link
>> HC3CookieHandler#DEFAULT_POLICY_NAME}
>> +     */
>> +    public HC3CookieHandler() {
>> +        this(DEFAULT_POLICY_NAME);
>> +    }
>> +
>> +    /**
>>        * @param policy
>>        *            cookie policy to which to conform (see
>>        *            {@link CookiePolicy#getCookieSpec(String)}
>> @@ -212,4 +219,9 @@ public class HC3CookieHandler implements
>>       public String getDefaultPolicy() {
>>           return DEFAULT_POLICY_NAME;
>>       }
>> +
>> +    @Override
>> +    public String[] getPolicies() {
>> +        return AVAILABLE_POLICIES;
>> +    }
>>   }
>>
>> Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/HC4CookieHandler.java
>> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/
>> org/apache/jmeter/protocol/http/control/HC4CookieHandler.
>> java?rev=1776135&r1=1776134&r2=1776135&view=diff
>> ============================================================
>> ==================
>> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/HC4CookieHandler.java (original)
>> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/control/HC4CookieHandler.java Tue Dec 27 14:06:11 2016
>> @@ -55,9 +55,9 @@ public class HC4CookieHandler implements
>>       private static final Logger log = LoggingManager.getLoggerForCla
>> ss();
>>         // Needed by CookiePanel
>> -    public static final String DEFAULT_POLICY_NAME =
>> CookieSpecs.STANDARD;
>> +    public static final String DEFAULT_POLICY_NAME =
>> CookieSpecs.STANDARD; // NOSONAR
>>   -    public static final String[] AVAILABLE_POLICIES = new String[]{
>> +    private static final String[] AVAILABLE_POLICIES = new String[]{
>>           DEFAULT_POLICY_NAME,
>>           CookieSpecs.STANDARD_STRICT,
>>           CookieSpecs.IGNORE_COOKIES,
>> @@ -87,6 +87,13 @@ public class HC4CookieHandler implements
>>               .register(CookieSpecs.NETSCAPE, new
>> NetscapeDraftSpecProvider())
>>               .build();
>>   +    /**
>> +     * Default constructor that uses {@link
>> HC4CookieHandler#DEFAULT_POLICY_NAME}
>> +     */
>> +    public HC4CookieHandler() {
>> +        this(DEFAULT_POLICY_NAME);
>> +    }
>> +
>>       public HC4CookieHandler(String policy) {
>>           super();
>>           if (policy.equals(org.apache.commons.httpclient.cookie.CookiePolicy.DEFAULT))
>> { // tweak diff HC3 vs HC4
>> @@ -250,4 +257,9 @@ public class HC4CookieHandler implements
>>       public String getDefaultPolicy() {
>>           return DEFAULT_POLICY_NAME;
>>       }
>> +
>> +    @Override
>> +    public String[] getPolicies() {
>> +        return AVAILABLE_POLICIES;
>>
> You would have to clone the array to make this operation safe. Another
> possibility would be to return an unmodifiable collection. I would prefer
> the second option, as we are breaking backwards compatibility here anyway.

Ok for me

>
> +    }
>>   }
>>
>> Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/
>> http/gui/CookiePanel.java
>> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/
>> org/apache/jmeter/protocol/http/gui/CookiePanel.java?rev=
>> 1776135&r1=1776134&r2=1776135&view=diff
>> ============================================================
>> ==================
>> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/CookiePanel.java
>> (original)
>> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/CookiePanel.java
>> Tue Dec 27 14:06:11 2016
>> @@ -40,6 +40,7 @@ import javax.swing.JScrollPane;
>>   import javax.swing.JTable;
>>   import javax.swing.ListSelectionModel;
>>   +import org.apache.commons.lang3.ClassUtils;
>>   import org.apache.jmeter.config.gui.AbstractConfigGui;
>>   import org.apache.jmeter.gui.util.FileDialoger;
>>   import org.apache.jmeter.gui.util.HeaderAsPropertyRenderer;
>> @@ -47,7 +48,6 @@ import org.apache.jmeter.gui.util.PowerT
>>   import org.apache.jmeter.protocol.http.control.Cookie;
>>   import org.apache.jmeter.protocol.http.control.CookieHandler;
>>   import org.apache.jmeter.protocol.http.control.CookieManager;
>> -import org.apache.jmeter.protocol.http.control.HC3CookieHandler;
>>   import org.apache.jmeter.protocol.http.control.HC4CookieHandler;
>>   import org.apache.jmeter.testelement.TestElement;
>>   import org.apache.jmeter.testelement.property.JMeterProperty;
>> @@ -238,13 +238,14 @@ public class CookiePanel extends Abstrac
>>        * @return cookie policies
>>        */
>>       private static String[] getPolicies(String className) {
>> -        // TODO it would be better if CookieHandler had a method
>> getSupportedPolicies() and empty constructor
>> -        if(HC3CookieHandler.class.getName().equals(className)) {
>> -            return HC3CookieHandler.AVAILABLE_POLICIES;
>> -        } else if(HC4CookieHandler.class.getName().equals(className)) {
>> -            return HC4CookieHandler.AVAILABLE_POLICIES;
>> +        try {
>> +            CookieHandler cookieHandler = (CookieHandler)
>> +                    ClassUtils.getClass(className).newInstance();
>> +            return cookieHandler.getPolicies();
>> +        } catch (Exception e) {
>> +            log.error("Error getting cookie policies from
>> implementation:"+className, e);
>> +            return getPolicies(DEFAULT_IMPLEMENTATION);
>>
> What Exceptions are you expecting here? Can we specify them a bit more?
>

Ones related to instantiation of class or class not implementing default
constructor I guess

>
> Regards,
>  Felix
>
>           }
>> -        return HC4CookieHandler.AVAILABLE_POLICIES;
>>       }
>>         private void addCookieToTable(Cookie cookie) {
>>
>>
>>
>


-- 
Cordialement.
Philippe Mouawad.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message