Skip to content

Commit cb85b7e

Browse files
committed
CLOUDSTACK-9265 cleanup around httpclient versions
1 parent e762e27 commit cb85b7e

5 files changed

Lines changed: 103 additions & 105 deletions

File tree

engine/storage/integration-test/test/org/apache/cloudstack/storage/test/TestHttp.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
import java.io.IOException;
2525
import java.io.OutputStream;
2626

27-
import junit.framework.Assert;
28-
29-
import org.apache.commons.httpclient.HttpException;
3027
import org.apache.http.HttpEntity;
3128
import org.apache.http.HttpResponse;
29+
import org.apache.http.client.ClientProtocolException;
3230
import org.apache.http.client.methods.HttpGet;
3331
import org.apache.http.client.methods.HttpHead;
3432
import org.apache.http.impl.client.DefaultHttpClient;
@@ -37,48 +35,51 @@
3735
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
3836
import org.testng.annotations.Parameters;
3937

38+
import junit.framework.Assert;
39+
4040
@ContextConfiguration(locations = "classpath:/storageContext.xml")
4141
public class TestHttp extends AbstractTestNGSpringContextTests {
4242
@Test
4343
@Parameters("template-url")
4444
public void testHttpclient(String templateUrl) {
45-
HttpHead method = new HttpHead(templateUrl);
46-
DefaultHttpClient client = new DefaultHttpClient();
45+
final HttpHead method = new HttpHead(templateUrl);
46+
final DefaultHttpClient client = new DefaultHttpClient();
4747

4848
OutputStream output = null;
4949
long length = 0;
5050
try {
5151
HttpResponse response = client.execute(method);
5252
length = Long.parseLong(response.getFirstHeader("Content-Length").getValue());
5353
System.out.println(response.getFirstHeader("Content-Length").getValue());
54-
File localFile = new File("/tmp/test");
54+
final File localFile = new File("/tmp/test");
5555
if (!localFile.exists()) {
5656
localFile.createNewFile();
5757
}
5858

59-
HttpGet getMethod = new HttpGet(templateUrl);
59+
final HttpGet getMethod = new HttpGet(templateUrl);
6060
response = client.execute(getMethod);
61-
HttpEntity entity = response.getEntity();
61+
final HttpEntity entity = response.getEntity();
6262

6363
output = new BufferedOutputStream(new FileOutputStream(localFile));
6464
entity.writeTo(output);
65-
} catch (HttpException e) {
65+
} catch (final ClientProtocolException e) {
6666
// TODO Auto-generated catch block
6767
e.printStackTrace();
68-
} catch (IOException e) {
68+
} catch (final IOException e) {
6969
// TODO Auto-generated catch block
7070
e.printStackTrace();
7171
} finally {
7272
try {
73-
if (output != null)
73+
if (output != null) {
7474
output.close();
75-
} catch (IOException e) {
75+
}
76+
} catch (final IOException e) {
7677
// TODO Auto-generated catch block
7778
e.printStackTrace();
7879
}
7980
}
8081

81-
File f = new File("/tmp/test");
82+
final File f = new File("/tmp/test");
8283
Assert.assertEquals(f.length(), length);
8384
}
8485
}

framework/cluster/src/com/cloud/cluster/ClusterServiceServletHttpHandler.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import java.io.IOException;
2121
import java.net.URLDecoder;
2222

23-
import org.apache.commons.httpclient.HttpStatus;
2423
import org.apache.http.HttpEntityEnclosingRequest;
2524
import org.apache.http.HttpException;
2625
import org.apache.http.HttpRequest;
2726
import org.apache.http.HttpResponse;
27+
import org.apache.http.HttpStatus;
2828
import org.apache.http.entity.BasicHttpEntity;
2929
import org.apache.http.protocol.HttpContext;
3030
import org.apache.http.protocol.HttpRequestHandler;
@@ -55,14 +55,14 @@ public void handle(HttpRequest request, HttpResponse response, HttpContext conte
5555
s_logger.trace("Handle cluster HTTP request done");
5656
}
5757

58-
} catch (Throwable e) {
58+
} catch (final Throwable e) {
5959
if (s_logger.isDebugEnabled()) {
6060
s_logger.debug("Exception " + e.toString());
6161
}
6262

6363
try {
6464
writeResponse(response, HttpStatus.SC_INTERNAL_SERVER_ERROR, null);
65-
} catch (Throwable e2) {
65+
} catch (final Throwable e2) {
6666
if (s_logger.isDebugEnabled()) {
6767
s_logger.debug("Exception " + e2.toString());
6868
}
@@ -73,20 +73,20 @@ public void handle(HttpRequest request, HttpResponse response, HttpContext conte
7373
@SuppressWarnings("deprecation")
7474
private void parseRequest(HttpRequest request) throws IOException {
7575
if (request instanceof HttpEntityEnclosingRequest) {
76-
HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest)request;
76+
final HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest)request;
7777

78-
String body = EntityUtils.toString(entityRequest.getEntity());
78+
final String body = EntityUtils.toString(entityRequest.getEntity());
7979
if (body != null) {
80-
String[] paramArray = body.split("&");
80+
final String[] paramArray = body.split("&");
8181
if (paramArray != null) {
82-
for (String paramEntry : paramArray) {
83-
String[] paramValue = paramEntry.split("=");
82+
for (final String paramEntry : paramArray) {
83+
final String[] paramValue = paramEntry.split("=");
8484
if (paramValue.length != 2) {
8585
continue;
8686
}
8787

88-
String name = URLDecoder.decode(paramValue[0]);
89-
String value = URLDecoder.decode(paramValue[1]);
88+
final String name = URLDecoder.decode(paramValue[0]);
89+
final String value = URLDecoder.decode(paramValue[1]);
9090

9191
if (s_logger.isTraceEnabled()) {
9292
s_logger.trace("Parsed request parameter " + name + "=" + value);
@@ -103,17 +103,17 @@ private void writeResponse(HttpResponse response, int statusCode, String content
103103
content = "";
104104
}
105105
response.setStatusCode(statusCode);
106-
BasicHttpEntity body = new BasicHttpEntity();
106+
final BasicHttpEntity body = new BasicHttpEntity();
107107
body.setContentType("text/html; charset=UTF-8");
108108

109-
byte[] bodyData = content.getBytes();
109+
final byte[] bodyData = content.getBytes();
110110
body.setContent(new ByteArrayInputStream(bodyData));
111111
body.setContentLength(bodyData.length);
112112
response.setEntity(body);
113113
}
114114

115115
protected void handleRequest(HttpRequest req, HttpResponse response) {
116-
String method = (String)req.getParams().getParameter("method");
116+
final String method = (String)req.getParams().getParameter("method");
117117

118118
int nMethod = RemoteMethodConstants.METHOD_UNKNOWN;
119119
String responseContent = null;
@@ -133,39 +133,41 @@ protected void handleRequest(HttpRequest req, HttpResponse response) {
133133

134134
case RemoteMethodConstants.METHOD_UNKNOWN:
135135
default:
136-
assert (false);
136+
assert false;
137137
s_logger.error("unrecognized method " + nMethod);
138138
break;
139139
}
140-
} catch (Throwable e) {
140+
} catch (final Throwable e) {
141141
s_logger.error("Unexpected exception when processing cluster service request : ", e);
142142
}
143143

144144
if (responseContent != null) {
145-
if (s_logger.isTraceEnabled())
145+
if (s_logger.isTraceEnabled()) {
146146
s_logger.trace("Write reponse with HTTP OK " + responseContent);
147+
}
147148

148149
writeResponse(response, HttpStatus.SC_OK, responseContent);
149150
} else {
150-
if (s_logger.isTraceEnabled())
151+
if (s_logger.isTraceEnabled()) {
151152
s_logger.trace("Write reponse with HTTP Bad request");
153+
}
152154

153155
writeResponse(response, HttpStatus.SC_BAD_REQUEST, null);
154156
}
155157
}
156158

157159
private String handleDeliverPduMethodCall(HttpRequest req) {
158160

159-
String pduSeq = (String)req.getParams().getParameter("pduSeq");
160-
String pduAckSeq = (String)req.getParams().getParameter("pduAckSeq");
161-
String sourcePeer = (String)req.getParams().getParameter("sourcePeer");
162-
String destPeer = (String)req.getParams().getParameter("destPeer");
163-
String agentId = (String)req.getParams().getParameter("agentId");
164-
String gsonPackage = (String)req.getParams().getParameter("gsonPackage");
165-
String stopOnError = (String)req.getParams().getParameter("stopOnError");
166-
String pduType = (String)req.getParams().getParameter("pduType");
161+
final String pduSeq = (String)req.getParams().getParameter("pduSeq");
162+
final String pduAckSeq = (String)req.getParams().getParameter("pduAckSeq");
163+
final String sourcePeer = (String)req.getParams().getParameter("sourcePeer");
164+
final String destPeer = (String)req.getParams().getParameter("destPeer");
165+
final String agentId = (String)req.getParams().getParameter("agentId");
166+
final String gsonPackage = (String)req.getParams().getParameter("gsonPackage");
167+
final String stopOnError = (String)req.getParams().getParameter("stopOnError");
168+
final String pduType = (String)req.getParams().getParameter("pduType");
167169

168-
ClusterServicePdu pdu = new ClusterServicePdu();
170+
final ClusterServicePdu pdu = new ClusterServicePdu();
169171
pdu.setSourcePeer(sourcePeer);
170172
pdu.setDestPeer(destPeer);
171173
pdu.setAgentId(Long.parseLong(agentId));
@@ -180,7 +182,7 @@ private String handleDeliverPduMethodCall(HttpRequest req) {
180182
}
181183

182184
private String handlePingMethodCall(HttpRequest req) {
183-
String callingPeer = (String)req.getParams().getParameter("callingPeer");
185+
final String callingPeer = (String)req.getParams().getParameter("callingPeer");
184186

185187
if (s_logger.isDebugEnabled()) {
186188
s_logger.debug("Handle ping request from " + callingPeer);

0 commit comments

Comments
 (0)