Skip to content

Commit

Permalink
Merge pull request #20 from rundeck-plugins/add-print-response-code
Browse files Browse the repository at this point in the history
RUN-1302: Add option to print HTTP response code and status
  • Loading branch information
qualman authored Oct 31, 2022
2 parents 86f519b + c30d51d commit 8447869
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/main/java/edu/ohio/ais/rundeck/HttpBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ protected void doRequest(Map<String, Object> options, HttpUriRequest request, In
try {
response = this.getHttpClient(options).execute(request);

if(options.containsKey("printResponseCode") && Boolean.parseBoolean(options.get("printResponseCode").toString())) {

String responseCode = response.getStatusLine().toString();
log.log(2, "Response Code: " + responseCode);
}

//print the response content
if(options.containsKey("printResponse") && Boolean.parseBoolean(options.get("printResponse").toString()) ||
options.containsKey("printResponseToFile") && Boolean.parseBoolean(options.get("printResponseToFile").toString())) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/edu/ohio/ais/rundeck/HttpDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ public Description getDescription() {
.renderingOption(StringRenderingConstants.GROUP_NAME,"Proxy Settings")
.required(false)
.build())
.property(PropertyBuilder.builder()
.booleanType("printResponseCode")
.title("Print Response Code?")
.description("Select to print the HTTP response code and status.")
.defaultValue("false")
.renderingOption(StringRenderingConstants.GROUP_NAME,"Print")
.build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package edu.ohio.ais.rundeck;

import com.dtolabs.rundeck.core.common.INodeEntry;
import com.dtolabs.rundeck.core.execution.ExecutionContext;
import com.dtolabs.rundeck.core.execution.ExecutionLogger;
import com.dtolabs.rundeck.core.execution.workflow.steps.StepFailureReason;
import com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException;
import com.dtolabs.rundeck.core.plugins.configuration.Description;
Expand All @@ -17,8 +19,8 @@
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
import static org.mockito.Mockito.when;

public class HttpWorkflowNodeStepPluginTest {
protected static final String REMOTE_URL = "/trigger";
Expand Down Expand Up @@ -154,10 +156,10 @@ public void setUp() {
node = Mockito.mock(INodeEntry.class);
pluginContext = Mockito.mock(PluginStepContext.class);
pluginLogger = Mockito.mock(PluginLogger.class);
Mockito.when(pluginContext.getLogger()).thenReturn(pluginLogger);
when(pluginContext.getLogger()).thenReturn(pluginLogger);

dataContext =new HashMap<>();
Mockito.when(pluginContext.getDataContext()).thenReturn(dataContext);
when(pluginContext.getDataContext()).thenReturn(dataContext);

}

Expand All @@ -182,6 +184,7 @@ public void canValidateConfiguration() {
options.put("remoteUrl", REMOTE_URL);
options.put("method", "GET");
options.put("authentication", HttpBuilder.AUTH_BASIC);
options.put("printResponseCode", "true");

try {
this.plugin.executeNodeStep(pluginContext, options, node );
Expand Down Expand Up @@ -232,6 +235,7 @@ public void canCallBasicEndpoint() throws NodeStepException {
for(String method : HttpBuilder.HTTP_METHODS) {
Map<String, Object> options = this.getBasicOptions(method);
options.put("remoteUrl", OAuthClientTest.BASE_URI + REMOTE_BASIC_URL);
options.put("printResponseCode", "true");

this.plugin.executeNodeStep(pluginContext, options, node );
}
Expand All @@ -242,6 +246,7 @@ public void canHandle500Error() throws NodeStepException {
Map<String, Object> options = new HashMap<>();

options.put("remoteUrl", OAuthClientTest.BASE_URI + ERROR_URL_500);
options.put("printResponseCode", "true");
options.put("method", "GET");

this.plugin.executeNodeStep(pluginContext, options, node );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public void canValidateConfiguration() {
options.put("remoteUrl", REMOTE_URL);
options.put("method", "GET");
options.put("authentication", HttpBuilder.AUTH_BASIC);
options.put("printResponseCode", "true");

try {
this.plugin.executeStep(pluginContext, options);
Expand Down Expand Up @@ -231,6 +232,7 @@ public void canCallBasicEndpoint() throws StepException {
for(String method : HttpBuilder.HTTP_METHODS) {
Map<String, Object> options = this.getBasicOptions(method);
options.put("remoteUrl", OAuthClientTest.BASE_URI + REMOTE_BASIC_URL);
options.put("printResponseCode", "true");

this.plugin.executeStep(pluginContext, options);
}
Expand All @@ -242,6 +244,7 @@ public void canHandle500Error() throws StepException {

options.put("remoteUrl", OAuthClientTest.BASE_URI + ERROR_URL_500);
options.put("method", "GET");
options.put("printResponseCode", "true");

this.plugin.executeStep(pluginContext, options);
}
Expand Down

0 comments on commit 8447869

Please sign in to comment.