-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathHttpPostTriad.java
74 lines (61 loc) · 2.19 KB
/
HttpPostTriad.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package net.adkitech;
import java.io.IOException;
import java.util.Formatter;
import java.util.Locale;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.util.EntityUtils;
public class HttpPostTriad {
private HttpPost httpPost; // url, headers, request entity
private int responseStatusCode;
private String responseString;
public HttpPostTriad()
{
responseStatusCode = 0;
}
public HttpPost getHttpPost() {
return httpPost;
}
public void setHttpPost(HttpPost httpPost) {
this.httpPost = httpPost;
}
public int getResponseStatusCode() {
return responseStatusCode;
}
public void setResponseStatusCode(int responseStatusCode) {
this.responseStatusCode = responseStatusCode;
}
public String getResponseString() {
return responseString;
}
public void setResponseString(String responseString) {
this.responseString = responseString;
}
public String stringify(String prefix, boolean includeRequestString)
{
String returnString = "";
String requestUrl = null;
String requestString = null;
String responseStatusCodeString = null;
String responseString = null;
if(this.httpPost != null)
{
try {
requestString = EntityUtils.toString(this.httpPost.getEntity());
} catch (IOException e) {
requestString = "IOException inside HttpPostTriad.stringify(prefix)(company,triad) e.getMessage()=" + e.getMessage();
}
requestUrl = this.httpPost.getURI().toString();
}
responseStatusCodeString = (new Integer(this.responseStatusCode).toString());
if(this.responseString != null)
responseString = this.responseString;
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb, Locale.US);
if(includeRequestString)
returnString = returnString + formatter.format("%1$40s: %2$s%n %1$40s: %3$s%n %1$40s: %4$s%n %1$40s: %5$s%n", prefix, requestUrl, requestString, responseStatusCodeString, responseString).toString();
else
returnString = returnString + formatter.format("%1$40s: %2$s%n %1$40s: %3$s%n %1$40s: %4$s%n %1$40s: %5$s%n", prefix, requestUrl, "(request string suppressed for brevity)", responseStatusCodeString, responseString).toString();
formatter.close();
return returnString;
}
}