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

address issue with pretty print and status code >= 400 #11

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
21 changes: 12 additions & 9 deletions src/main/java/edu/ohio/ais/rundeck/HttpWorkflowStepPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.dtolabs.rundeck.plugins.util.DescriptionBuilder;
import com.dtolabs.rundeck.plugins.util.PropertyBuilder;
import com.esotericsoftware.yamlbeans.YamlReader;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;
import edu.ohio.ais.rundeck.util.OAuthClient;
Expand All @@ -23,7 +24,6 @@
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
Expand All @@ -36,6 +36,9 @@
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

import java.io.*;
import java.security.GeneralSecurityException;
Expand All @@ -44,10 +47,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.Gson;
import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;


/**
Expand Down Expand Up @@ -281,24 +280,25 @@ protected void doRequest(Map<String, Object> options, HttpUriRequest request, In
}
CloseableHttpResponse response = null;
try {
String body = null;
response = this.getHttpClient(options).execute(request);

//print the response content
if(options.containsKey("printResponse") && Boolean.parseBoolean(options.get("printResponse").toString()) ||
options.containsKey("printResponseToFile") && Boolean.parseBoolean(options.get("printResponseToFile").toString())) {

String output = this.prettyPrint(response);
body = this.prettyPrint(response);

if(Boolean.parseBoolean(options.get("printResponse").toString())) {
//print response
System.out.println(output);
System.out.println(body);
}

if(Boolean.parseBoolean(options.get("printResponseToFile").toString())) {

File file = new File(options.get("file").toString());
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write (output);
writer.write (body);

//Close writer
writer.close();
Expand Down Expand Up @@ -374,7 +374,10 @@ protected void doRequest(Map<String, Object> options, HttpUriRequest request, In
message += ": " + Integer.toString(response.getStatusLine().getStatusCode()) + " Error";
}

String body = EntityUtils.toString(response.getEntity());
if(body == null){
body = EntityUtils.toString(response.getEntity());
}

if(body.length() > 0) {
message += ": " + body;
}
Expand Down