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

(-)a/src/protocol/build.gradle.kts (+8 lines)
Lines 89-94 project("http") { Link Here
89
        implementation("com.fasterxml.jackson.core:jackson-databind")
89
        implementation("com.fasterxml.jackson.core:jackson-databind")
90
        testImplementation(testFixtures(project(":src:testkit-wiremock")))
90
        testImplementation(testFixtures(project(":src:testkit-wiremock")))
91
        testImplementation("com.github.tomakehurst:wiremock-jre8")
91
        testImplementation("com.github.tomakehurst:wiremock-jre8")
92
        // For some reason JMeter bundles just tika-core and tika-parsers without transitive
93
        // dependencies. So we exclude those
94
        implementation("org.apache.tika:tika-core") {
95
            isTransitive = false
96
        }
97
        runtimeOnly("org.apache.tika:tika-parsers") {
98
            isTransitive = false
99
        }
92
    }
100
    }
93
}
101
}
94
102
(-)a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java (-12 / +13 lines)
Lines 43-48 import org.apache.commons.cli.avalon.CLArgsParser; Link Here
43
import org.apache.commons.cli.avalon.CLOption;
43
import org.apache.commons.cli.avalon.CLOption;
44
import org.apache.commons.cli.avalon.CLOptionDescriptor;
44
import org.apache.commons.cli.avalon.CLOptionDescriptor;
45
import org.apache.commons.io.FileUtils;
45
import org.apache.commons.io.FileUtils;
46
import org.apache.commons.lang3.tuple.Pair;
46
import org.apache.jmeter.protocol.http.control.AuthManager.Mechanism;
47
import org.apache.jmeter.protocol.http.control.AuthManager.Mechanism;
47
import org.apache.jmeter.protocol.http.control.Authorization;
48
import org.apache.jmeter.protocol.http.control.Authorization;
48
import org.apache.jmeter.protocol.http.control.Cookie;
49
import org.apache.jmeter.protocol.http.control.Cookie;
Lines 123-129 public class BasicCurlParser { Link Here
123
    public static final class Request {
124
    public static final class Request {
124
        private boolean compressed;
125
        private boolean compressed;
125
        private String url;
126
        private String url;
126
        private Map<String, String> headers = new LinkedHashMap<>();
127
        private List<Pair<String, String>> headers = new ArrayList<>();
127
        private String method = "GET";
128
        private String method = "GET";
128
        private String postData;
129
        private String postData;
129
        private String interfaceName;
130
        private String interfaceName;
Lines 133-140 public class BasicCurlParser { Link Here
133
        private String filepathCookie="";
134
        private String filepathCookie="";
134
        private Authorization authorization = new Authorization();
135
        private Authorization authorization = new Authorization();
135
        private String caCert = "";
136
        private String caCert = "";
136
        private Map<String, String> formData = new LinkedHashMap<>();
137
        private List<Pair<String, String>> formData = new ArrayList<>();
137
        private Map<String, String> formStringData = new LinkedHashMap<>();
138
        private List<Pair<String, String>> formStringData = new ArrayList<>();
138
        private Set<String> dnsServers = new HashSet<>();
139
        private Set<String> dnsServers = new HashSet<>();
139
        private boolean isKeepAlive = true;
140
        private boolean isKeepAlive = true;
140
        private double maxTime = -1;
141
        private double maxTime = -1;
Lines 201-207 public class BasicCurlParser { Link Here
201
            if ("COOKIE".equalsIgnoreCase(name)) {
202
            if ("COOKIE".equalsIgnoreCase(name)) {
202
                this.cookieInHeaders = value;
203
                this.cookieInHeaders = value;
203
            } else if (!HEADERS_TO_IGNORE.contains(name)) {
204
            } else if (!HEADERS_TO_IGNORE.contains(name)) {
204
                headers.put(name, value);
205
                headers.add(Pair.of(name, value));
205
            }
206
            }
206
        }
207
        }
207
208
Lines 239-246 public class BasicCurlParser { Link Here
239
        /**
240
        /**
240
         * @return the headers
241
         * @return the headers
241
         */
242
         */
242
        public Map<String, String> getHeaders() {
243
        public List<Pair<String, String>> getHeaders() {
243
            return Collections.unmodifiableMap(this.headers);
244
            return Collections.unmodifiableList(this.headers);
244
        }
245
        }
245
246
246
        /**
247
        /**
Lines 406-413 public class BasicCurlParser { Link Here
406
        /**
407
        /**
407
         * @return the map of form data
408
         * @return the map of form data
408
         */
409
         */
409
        public Map<String, String> getFormStringData() {
410
        public List<Pair<String,String>> getFormStringData() {
410
            return Collections.unmodifiableMap(this.formStringData);
411
            return Collections.unmodifiableList(this.formStringData);
411
        }
412
        }
412
413
413
        /**
414
        /**
Lines 415-428 public class BasicCurlParser { Link Here
415
         * @param value the value of form data
416
         * @param value the value of form data
416
         */
417
         */
417
        public void addFormStringData(String key, String value) {
418
        public void addFormStringData(String key, String value) {
418
            formStringData.put(key, value);
419
            formStringData.add(Pair.of(key, value));
419
        }
420
        }
420
421
421
        /**
422
        /**
422
         * @return the map of form data
423
         * @return the map of form data
423
         */
424
         */
424
        public Map<String, String> getFormData() {
425
        public List<Pair<String,String>> getFormData() {
425
            return Collections.unmodifiableMap(this.formData);
426
            return Collections.unmodifiableList(this.formData);
426
        }
427
        }
427
428
428
        /**
429
        /**
Lines 430-436 public class BasicCurlParser { Link Here
430
         * @param value the value of form data
431
         * @param value the value of form data
431
         */
432
         */
432
        public void addFormData(String key, String value) {
433
        public void addFormData(String key, String value) {
433
            formData.put(key, value);
434
            formData.add(Pair.of(key, value));
434
        }
435
        }
435
436
436
        /**
437
        /**
(-)a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java (-7 / +13 lines)
Lines 38-44 import java.util.List; Link Here
38
import java.util.Map;
38
import java.util.Map;
39
import java.util.Set;
39
import java.util.Set;
40
40
41
import javax.activation.MimetypesFileTypeMap;
42
import javax.swing.JButton;
41
import javax.swing.JButton;
43
import javax.swing.JCheckBox;
42
import javax.swing.JCheckBox;
44
import javax.swing.JLabel;
43
import javax.swing.JLabel;
Lines 52-57 import javax.swing.tree.TreePath; Link Here
52
51
53
import org.apache.commons.io.FileUtils;
52
import org.apache.commons.io.FileUtils;
54
import org.apache.commons.lang3.StringUtils;
53
import org.apache.commons.lang3.StringUtils;
54
import org.apache.commons.lang3.tuple.Pair;
55
import org.apache.jmeter.config.Arguments;
55
import org.apache.jmeter.config.Arguments;
56
import org.apache.jmeter.config.KeystoreConfig;
56
import org.apache.jmeter.config.KeystoreConfig;
57
import org.apache.jmeter.control.Controller;
57
import org.apache.jmeter.control.Controller;
Lines 101-106 import org.apache.jmeter.visualizers.ViewResultsFullVisualizer; Link Here
101
import org.apache.jorphan.collections.HashTree;
101
import org.apache.jorphan.collections.HashTree;
102
import org.apache.jorphan.gui.ComponentUtil;
102
import org.apache.jorphan.gui.ComponentUtil;
103
import org.apache.jorphan.gui.JMeterUIDefaults;
103
import org.apache.jorphan.gui.JMeterUIDefaults;
104
import org.apache.tika.Tika;
104
import org.slf4j.Logger;
105
import org.slf4j.Logger;
105
import org.slf4j.LoggerFactory;
106
import org.slf4j.LoggerFactory;
106
107
Lines 118-123 public class ParseCurlCommandAction extends AbstractAction implements MenuCreato Link Here
118
    private static final String CREATE_REQUEST = "CREATE_REQUEST";
119
    private static final String CREATE_REQUEST = "CREATE_REQUEST";
119
    private static final String TYPE_FORM = ";type=";
120
    private static final String TYPE_FORM = ";type=";
120
    private static final String CERT = "cert";
121
    private static final String CERT = "cert";
122
    private Logger log = LoggerFactory.getLogger(getClass());
121
    /** A panel allowing results to be saved. */
123
    /** A panel allowing results to be saved. */
122
    private FilePanel filePanel = null;
124
    private FilePanel filePanel = null;
123
    static {
125
    static {
Lines 126-131 public class ParseCurlCommandAction extends AbstractAction implements MenuCreato Link Here
126
    private JSyntaxTextArea cURLCommandTA;
128
    private JSyntaxTextArea cURLCommandTA;
127
    private JLabel statusText;
129
    private JLabel statusText;
128
    private JCheckBox uploadCookiesCheckBox;
130
    private JCheckBox uploadCookiesCheckBox;
131
    private final Tika tika = new Tika();
129
    public ParseCurlCommandAction() {
132
    public ParseCurlCommandAction() {
130
        super();
133
        super();
131
    }
134
    }
Lines 344-352 public class ParseCurlCommandAction extends AbstractAction implements MenuCreato Link Here
344
        headerManager.setProperty(TestElement.GUI_CLASS, HeaderPanel.class.getName());
347
        headerManager.setProperty(TestElement.GUI_CLASS, HeaderPanel.class.getName());
345
        headerManager.setProperty(TestElement.NAME, "HTTP HeaderManager");
348
        headerManager.setProperty(TestElement.NAME, "HTTP HeaderManager");
346
        headerManager.setProperty(TestElement.COMMENTS, getDefaultComment());
349
        headerManager.setProperty(TestElement.COMMENTS, getDefaultComment());
347
        Map<String, String> map = request.getHeaders();
348
        boolean hasAcceptEncoding = false;
350
        boolean hasAcceptEncoding = false;
349
        for (Map.Entry<String, String> header : map.entrySet()) {
351
        for (Pair<String, String> header : request.getHeaders()) {
350
            String key = header.getKey();
352
            String key = header.getKey();
351
            hasAcceptEncoding = hasAcceptEncoding || key.equalsIgnoreCase(ACCEPT_ENCODING);
353
            hasAcceptEncoding = hasAcceptEncoding || key.equalsIgnoreCase(ACCEPT_ENCODING);
352
            headerManager.getHeaders().addItem(new Header(key, header.getValue()));
354
            headerManager.getHeaders().addItem(new Header(key, header.getValue()));
Lines 515-526 public class ParseCurlCommandAction extends AbstractAction implements MenuCreato Link Here
515
            throw new IllegalArgumentException("--form and --data can't appear in the same command");
517
            throw new IllegalArgumentException("--form and --data can't appear in the same command");
516
        }
518
        }
517
        List<HTTPFileArg> httpFileArgs = new ArrayList<>();
519
        List<HTTPFileArg> httpFileArgs = new ArrayList<>();
518
        for (Map.Entry<String, String> entry : request.getFormStringData().entrySet()) {
520
        for (Pair<String, String> entry : request.getFormStringData()) {
519
            String formName = entry.getKey();
521
            String formName = entry.getKey();
520
            String formValue = entry.getValue();
522
            String formValue = entry.getValue();
521
            httpSampler.addNonEncodedArgument(formName, formValue, "");
523
            httpSampler.addNonEncodedArgument(formName, formValue, "");
522
        }
524
        }
523
        for (Map.Entry<String, String> entry : request.getFormData().entrySet()) {
525
        for (Pair<String, String> entry : request.getFormData()) {
524
            String formName = entry.getKey();
526
            String formName = entry.getKey();
525
            String formValue = entry.getValue();
527
            String formValue = entry.getValue();
526
            boolean isContainsFile = "@".equals(formValue.substring(0, 1));
528
            boolean isContainsFile = "@".equals(formValue.substring(0, 1));
Lines 533-539 public class ParseCurlCommandAction extends AbstractAction implements MenuCreato Link Here
533
                    formValue = formValueWithType[0];
535
                    formValue = formValueWithType[0];
534
                    contentType = formValueWithType[1];
536
                    contentType = formValueWithType[1];
535
                } else {
537
                } else {
536
                    contentType = new MimetypesFileTypeMap().getContentType(formValue);
538
                    try {
539
                        contentType = tika.detect(new File(formValue));
540
                    } catch (IOException e) {
541
                        log.info("Could not detect contentType for file {} by content, so falling back to detection by filename");
542
                        contentType = tika.detect(formValue);
543
                    }
537
                }
544
                }
538
                httpFileArgs.add(new HTTPFileArg(formValue, formName, contentType));
545
                httpFileArgs.add(new HTTPFileArg(formValue, formName, contentType));
539
            } else {
546
            } else {
540
- 

Return to bug 65013