CallResultsImpl.java
2.11 KB
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
75
76
77
78
79
80
81
82
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.httpclient.Header
* org.apache.commons.httpclient.HttpMethod
* org.apache.commons.httpclient.URI
* org.apache.commons.httpclient.URIException
*/
package com.day.cq.mcm.campaign.impl;
import com.day.cq.mcm.campaign.CallResults;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.URIException;
public class CallResultsImpl
implements CallResults {
private final HttpMethod method;
private boolean isUsed;
CallResultsImpl(HttpMethod method) {
this.method = method;
this.isUsed = false;
}
@Override
public int getStatus() {
return this.method.getStatusCode();
}
@Override
public Map<String, String> getResponseHeaders() {
Header[] headerArray;
LinkedHashMap<String, String> headers = new LinkedHashMap<String, String>();
for (Header header : headerArray = this.method.getResponseHeaders()) {
headers.put(header.getName(), header.getValue());
}
return headers;
}
@Override
public InputStream bodyAsStream() throws IOException {
this.isUsed = true;
return this.method.getResponseBodyAsStream();
}
@Override
public String bodyAsString() throws IOException {
this.isUsed = true;
return this.method.getResponseBodyAsString();
}
@Override
public void destroy() {
if (!this.isUsed) {
try {
this.method.getResponseBody();
}
catch (IOException ioe) {
// empty catch block
}
}
this.method.releaseConnection();
}
@Override
public String getCompleteURL() {
try {
return this.method.getURI().toString();
}
catch (URIException ue) {
return "<URL not available>";
}
}
}