View | Details | Raw Unified | Return to bug 63025
Collapse All | Expand All

(-)a/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (-32 / +22 lines)
Lines 39-44 import java.util.Set; Link Here
39
import java.util.concurrent.Callable;
39
import java.util.concurrent.Callable;
40
import java.util.concurrent.ExecutionException;
40
import java.util.concurrent.ExecutionException;
41
import java.util.concurrent.Future;
41
import java.util.concurrent.Future;
42
import java.util.function.Consumer;
42
43
43
import org.apache.commons.io.IOUtils;
44
import org.apache.commons.io.IOUtils;
44
import org.apache.commons.lang3.StringUtils;
45
import org.apache.commons.lang3.StringUtils;
Lines 2092-2133 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
2092
    @Override
2093
    @Override
2093
    public int replace(String regex, String replaceBy, boolean caseSensitive) throws Exception {
2094
    public int replace(String regex, String replaceBy, boolean caseSensitive) throws Exception {
2094
        int totalReplaced = 0;
2095
        int totalReplaced = 0;
2096
2095
        for (JMeterProperty jMeterProperty : getArguments()) {
2097
        for (JMeterProperty jMeterProperty : getArguments()) {
2096
            HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
2098
            HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
2097
            String value = arg.getValue();
2099
            totalReplaced += replaceValue(regex, replaceBy, caseSensitive, arg.getValue(), arg::setValue);
2098
            if(!StringUtils.isEmpty(value)) {
2099
                Object[] result = JOrphanUtils.replaceAllWithRegex(value, regex, replaceBy, caseSensitive);
2100
                // check if there is anything to replace
2101
                int nbReplaced = ((Integer)result[1]).intValue();
2102
                if (nbReplaced>0) {
2103
                    String replacedText = (String) result[0];
2104
                    arg.setValue(replacedText);
2105
                    totalReplaced += nbReplaced;
2106
                }
2107
            }
2108
        }
2109
        String value = getPath();
2110
        if(!StringUtils.isEmpty(value)) {
2111
            Object[] result = JOrphanUtils.replaceAllWithRegex(value, regex, replaceBy, caseSensitive);
2112
            // check if there is anything to replace
2113
            int nbReplaced = ((Integer)result[1]).intValue();
2114
            if (nbReplaced>0) {
2115
                String replacedText = (String) result[0];
2116
                setPath(replacedText);
2117
                totalReplaced += nbReplaced;
2118
            }
2119
        }
2100
        }
2120
2101
2121
        if(!StringUtils.isEmpty(getDomain())) {
2102
        totalReplaced += replaceValue(regex, replaceBy, caseSensitive, getPath(), this::setPath);
2122
            Object[] result = JOrphanUtils.replaceAllWithRegex(getDomain(), regex, replaceBy, caseSensitive);            
2103
        totalReplaced += replaceValue(regex, replaceBy, caseSensitive, getDomain(), this::setDomain);
2123
            // check if there is anything to replace
2104
        totalReplaced += replaceValue(regex, replaceBy, caseSensitive, getProtocol(), this::setProtocol);
2124
            int nbReplaced = ((Integer)result[1]).intValue();
2105
        totalReplaced += replaceValue(regex, replaceBy, caseSensitive, getPort() + "", (s) -> setPort(Integer.parseInt(s)));
2125
            if (nbReplaced>0) {
2106
2126
                String replacedText = (String) result[0];
2127
                setDomain(replacedText);
2128
                totalReplaced += nbReplaced;
2129
            }
2130
        }
2131
        return totalReplaced;
2107
        return totalReplaced;
2132
    }
2108
    }
2109
2110
    private int replaceValue(String regex, String replaceBy, boolean caseSensitive, String value, Consumer<String> setter) {
2111
        if (StringUtils.isBlank(value)) {
2112
            return 0;
2113
        }
2114
        Object[] result = JOrphanUtils.replaceAllWithRegex(value, regex, replaceBy, caseSensitive);
2115
        int nbReplaced = ((Integer) result[1]).intValue();
2116
        if (nbReplaced <= 0) {
2117
            return 0;
2118
        }
2119
        setter.accept((String) result[0]);
2120
        return nbReplaced;
2121
    }
2122
2133
}
2123
}

Return to bug 63025