Skip to content

Commit

Permalink
Stop using Commons HttpClient 3.x in tests (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Nov 25, 2022
1 parent 27de9e6 commit abee89f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions rest-api/src/test/java/com/cloudbees/workflow/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import hudson.model.Result;
import hudson.util.RunList;
import jenkins.model.Jenkins;
import org.apache.commons.httpclient.NameValuePair;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Assert;
Expand All @@ -41,7 +40,9 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.AbstractMap;
import java.util.Iterator;
import java.util.Map;

/**
* @author <a href="mailto:[email protected]">[email protected]</a>
Expand All @@ -65,8 +66,8 @@ public static int postToJenkins(Jenkins jenkins, String url, String content, Str
conn.setRequestMethod("POST");

// Set the crumb header, otherwise the POST may be rejected.
NameValuePair crumbHeader = getCrumbHeaderNVP(jenkins);
conn.setRequestProperty(crumbHeader.getName(), crumbHeader.getValue());
Map.Entry<String, String> crumbHeader = getCrumbHeaderNVP(jenkins);
conn.setRequestProperty(crumbHeader.getKey(), crumbHeader.getValue());

if (contentType != null) {
conn.setRequestProperty("Content-Type", contentType);
Expand Down Expand Up @@ -156,8 +157,8 @@ public static <T> T getJSON(String url, Class<T> to, JenkinsRule jenkinsRule) th
return jsonReadWrite.fromString(jsonResponse, to);
}

private static NameValuePair getCrumbHeaderNVP(Jenkins jenkins) {
return new NameValuePair(jenkins.getCrumbIssuer().getDescriptor().getCrumbRequestField(),
private static Map.Entry<String, String> getCrumbHeaderNVP(Jenkins jenkins) {
return new AbstractMap.SimpleEntry<>(jenkins.getCrumbIssuer().getDescriptor().getCrumbRequestField(),
jenkins.getCrumbIssuer().getCrumb( null ));
}
}

0 comments on commit abee89f

Please sign in to comment.