As latest comment in JIRA - 68154 :
-
I’m encountering an issue with the round-trip tests in the HTTP Request plugin. When I run the tests, they fail with a 500 server error during the configSubmit phase (for example, for URLs like http://localhost:36357/jenkins/job/test2/configSubmit).
-
However, when I tried it on my local Jenkins instance, the pipeline runs successfully without any errors.
-
Additionally, I wanted to ask about adding the following pipelines and updating the code:
-
Pipelines :
def response = httpRequest(
url: 'https://httpbin.org/headers',
customHeaders: [[name: 'foo', value: 'bar']]
)
def headerName1 = 'header'
def varName1 = 'abc'
def headerName2 = 'another-header'
def varName2 = 'xyz'
def headers = [
"${headerName1}": "${varName1}",
"${headerName2}": "${varName2}"
]
def response = httpRequest(url: 'https://httpbin.org/headers', customHeaders:
headers)
- Updated Code for HttpRequestStep.java and HttpRequest.java :
@DataBoundSetter
public void setCustomHeaders(Object customHeaders) {
if (customHeaders instanceof List) {
List<?> list = (List<?>) customHeaders;
if (!list.isEmpty() && list.get(0) instanceof Map) {
this.customHeaders = list.stream()
.map(entry -> {
Map<String, String> map = (Map<String, String>) entry;
return new HttpRequestNameValuePair(map.get("name"), map.get("value"));
})
.collect(Collectors.toList());
} else {
this.customHeaders = (List<HttpRequestNameValuePair>) customHeaders;
}
} else if (customHeaders instanceof Map) {
this.customHeaders = ((Map<String, String>) customHeaders)
.entrySet()
.stream()
.map(entry -> new HttpRequestNameValuePair(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
} else {
throw new IllegalArgumentException("Unsupported type for customHeaders: " + customHeaders.getClass());
}
}
- Test for customHeaders in HttpRequestRoundTripTest.java & HttpRequestStepRoundTripTest.java
@Test
public void configRoundtripGroup3() throws Exception {
configRoundTrip(before);
List<HttpRequestNameValuePair> params = new ArrayList<>();
params.add(new HttpRequestNameValuePair("param1","value1"));
params.add(new HttpRequestNameValuePair("param2","value2"));
RequestAction action = new RequestAction(new URL("http://www.domain.com/"),HttpMode.GET,null,params);
List<RequestAction> actions = new ArrayList<>();
actions.add(action);
FormAuthentication formAuth = new FormAuthentication("keyname",actions);
List<FormAuthentication> formAuthList = new ArrayList<>();
formAuthList.add(formAuth);
HttpRequestGlobalConfig.get().setFormAuthentications(formAuthList);
configRoundTrip(before);
List<HttpRequestNameValuePair> customHeaders = new ArrayList<>();
customHeaders.add(new HttpRequestNameValuePair("param1","value1"));
before.setCustomHeaders(customHeaders);
configRoundTrip(before);
}
private void configRoundTrip(HttpRequest before) throws Exception {
HttpRequest after = j.configRoundtrip(before);
j.assertEqualBeans(before, after, "httpMode,passBuildParameters");
j.assertEqualBeans(before, after, "url");
j.assertEqualBeans(before, after, "validResponseCodes,validResponseContent");
j.assertEqualBeans(before, after, "acceptType,contentType");
j.assertEqualBeans(before, after, "uploadFile,multipartName");
j.assertEqualBeans(before, after, "outputFile,timeout");
j.assertEqualBeans(before, after, "consoleLogResponseBody");
j.assertEqualBeans(before, after, "authentication");
// Custom header check
assertEquals(before.getCustomHeaders().size(),after.getCustomHeaders().size());
for (int idx = 0; idx < before.getCustomHeaders().size(); idx++) {
HttpRequestNameValuePair bnvp = before.getCustomHeaders().get(idx);
HttpRequestNameValuePair anvp = after.getCustomHeaders().get(idx);
assertEquals(bnvp.getName(),anvp.getName());
assertEquals(bnvp.getValue(),anvp.getValue());
}
// Form authentication check
List<FormAuthentication> beforeFas = HttpRequestGlobalConfig.get().getFormAuthentications();
List<FormAuthentication> afterFas = HttpRequestGlobalConfig.get().getFormAuthentications();
assertEquals(beforeFas.size(), afterFas.size());
for (int idx = 0; idx < beforeFas.size(); idx++) {
FormAuthentication beforeFa = beforeFas.get(idx);
FormAuthentication afterFa = afterFas.get(idx);
assertEquals(beforeFa.getKeyName(), afterFa.getKeyName());
List<RequestAction> beforeActions = beforeFa.getActions();
List<RequestAction> afterActions = afterFa.getActions();
assertEquals(beforeActions.size(), afterActions.size());
for (int jdx = 0; jdx < beforeActions.size(); jdx ++) {
RequestAction beforeAction = beforeActions.get(jdx);
RequestAction afterAction = afterActions.get(jdx);
assertEquals(beforeAction.getUrl(), afterAction.getUrl());
assertEquals(beforeAction.getMode(), afterAction.getMode());
List<HttpRequestNameValuePair> beforeParams = beforeAction.getParams();
List<HttpRequestNameValuePair> afterParams = afterAction.getParams();
assertEquals(beforeParams.size(), afterParams.size());
for (int kdx = 0; kdx < beforeParams.size(); kdx++) {
HttpRequestNameValuePair beforeNvp = beforeParams.get(kdx);
HttpRequestNameValuePair afterNvp = afterParams.get(kdx);
assertEquals(beforeNvp.getName(), afterNvp.getName());
assertEquals(beforeNvp.getValue(), afterNvp.getValue());
}
}
}
}
}
I wanted to know how I can integrate these updates properly. Do you think the issue could be related to the testing environment, or is there something else I should investigate further?" Anyone can help !!!