diff --git a/src/main/java/edu/ohio/ais/rundeck/HttpBuilder.java b/src/main/java/edu/ohio/ais/rundeck/HttpBuilder.java index fe7a064..e69d013 100644 --- a/src/main/java/edu/ohio/ais/rundeck/HttpBuilder.java +++ b/src/main/java/edu/ohio/ais/rundeck/HttpBuilder.java @@ -127,6 +127,12 @@ protected void doRequest(Map 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())) { diff --git a/src/main/java/edu/ohio/ais/rundeck/HttpDescription.java b/src/main/java/edu/ohio/ais/rundeck/HttpDescription.java index 38319e2..db1034f 100644 --- a/src/main/java/edu/ohio/ais/rundeck/HttpDescription.java +++ b/src/main/java/edu/ohio/ais/rundeck/HttpDescription.java @@ -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(); } } diff --git a/src/test/java/edu/ohio/ais/rundeck/HttpWorkflowNodeStepPluginTest.java b/src/test/java/edu/ohio/ais/rundeck/HttpWorkflowNodeStepPluginTest.java index c629cde..7987184 100644 --- a/src/test/java/edu/ohio/ais/rundeck/HttpWorkflowNodeStepPluginTest.java +++ b/src/test/java/edu/ohio/ais/rundeck/HttpWorkflowNodeStepPluginTest.java @@ -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; @@ -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"; @@ -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); } @@ -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 ); @@ -232,6 +235,7 @@ public void canCallBasicEndpoint() throws NodeStepException { for(String method : HttpBuilder.HTTP_METHODS) { Map options = this.getBasicOptions(method); options.put("remoteUrl", OAuthClientTest.BASE_URI + REMOTE_BASIC_URL); + options.put("printResponseCode", "true"); this.plugin.executeNodeStep(pluginContext, options, node ); } @@ -242,6 +246,7 @@ public void canHandle500Error() throws NodeStepException { Map 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 ); diff --git a/src/test/java/edu/ohio/ais/rundeck/HttpWorkflowStepPluginTest.java b/src/test/java/edu/ohio/ais/rundeck/HttpWorkflowStepPluginTest.java index da98f0a..ce8a213 100644 --- a/src/test/java/edu/ohio/ais/rundeck/HttpWorkflowStepPluginTest.java +++ b/src/test/java/edu/ohio/ais/rundeck/HttpWorkflowStepPluginTest.java @@ -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); @@ -231,6 +232,7 @@ public void canCallBasicEndpoint() throws StepException { for(String method : HttpBuilder.HTTP_METHODS) { Map options = this.getBasicOptions(method); options.put("remoteUrl", OAuthClientTest.BASE_URI + REMOTE_BASIC_URL); + options.put("printResponseCode", "true"); this.plugin.executeStep(pluginContext, options); } @@ -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); }