Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix npe problem when encounter invalid request with null url #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.loadium.postman2jmx.builder;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.loadium.postman2jmx.config.Postman2JmxConfig;
import com.loadium.postman2jmx.exception.NoPostmanCollectionItemException;
import com.loadium.postman2jmx.exception.NullPostmanCollectionException;
Expand All @@ -13,13 +15,19 @@
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.ThreadGroup;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.collections.ListedHashTree;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.*;

public abstract class AbstractJmxFileBuilder implements IJmxFileBuilder {
private static final Logger log = LoggerFactory.getLogger(AbstractJmxFileBuilder.class);

private ObjectMapper objectMapper = new ObjectMapper();

protected JmxFile buildJmxFile(PostmanCollection postmanCollection, String jmxOutputFilePath) throws Exception {
if (postmanCollection == null) {
Expand Down Expand Up @@ -117,6 +125,16 @@ protected JmxFile buildJmxFile(PostmanCollection postmanCollection, String jmxOu
}

private void removeEmptyQueries(PostmanItem item) {
if (item.getRequest().getUrl() == null){
String s = null;
try {
s = objectMapper.writeValueAsString(item);
} catch (Throwable e) {
log.error("error:",e);
}
log.error("invalid postman request,url is null.item:{}",s);
throw new RuntimeException();
}
item.getRequest().getUrl().getQueries().removeIf(query -> Objects.equals(query.getKey(), "")
|| Objects.equals(query.getValue(), "") || Objects.equals(query.getKey(), null)
|| Objects.equals(query.getValue(), null) || Objects.equals(query.getKey(), " ")
Expand Down