summaryrefslogtreecommitdiffstats
path: root/openstack-client-connectors/http-connector
diff options
context:
space:
mode:
authorIsaac Manuel Raj <isaac.manuelraj@huawei.com>2019-04-17 14:22:59 +0530
committerIsaac Manuel Raj <isaac.manuelraj@huawei.com>2019-04-17 08:56:09 +0000
commit1f26e77e0911c520f60e45a879365e471331bff4 (patch)
treeea079001353da35a4d95b159efd41b0b03e1e364 /openstack-client-connectors/http-connector
parent226c37657808fa22336940e9be49147809f41710 (diff)
The Cyclomatic Complexity of this method "request"
The Cyclomatic Complexity of this method "request" Issue-ID: SO-1490 Change-Id: Ie075744b8af0b816bafd2196e1536316bf7de07a Signed-off-by: Isaac Manuel Raj <isaac.manuelraj@huawei.com>
Diffstat (limited to 'openstack-client-connectors/http-connector')
-rw-r--r--openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientConnector.java68
1 files changed, 39 insertions, 29 deletions
diff --git a/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientConnector.java b/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientConnector.java
index 9b2f2e2..c266f20 100644
--- a/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientConnector.java
+++ b/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientConnector.java
@@ -102,11 +102,7 @@ public class HttpClientConnector implements OpenStackClientConnector {
try {
URIBuilder uriBuilder = new URIBuilder(request.endpoint() + request.path());
- for(Map.Entry<String, List<Object> > entry : request.queryParams().entrySet()) {
- for (Object o : entry.getValue()) {
- uriBuilder.setParameter(entry.getKey(), String.valueOf(o));
- }
- }
+ setUriBuilderParams(request, uriBuilder);
uri = uriBuilder.build();
} catch (URISyntaxException e) {
@@ -136,30 +132,7 @@ public class HttpClientConnector implements OpenStackClientConnector {
// Determine the HttpRequest class based on the method
HttpUriRequest httpRequest;
- switch (request.method()) {
- case POST:
- HttpPost post = new HttpPost(uri);
- post.setEntity (entity);
- httpRequest = post;
- break;
-
- case GET:
- httpRequest = new HttpGet(uri);
- break;
-
- case PUT:
- HttpPut put = new HttpPut(uri);
- put.setEntity (entity);
- httpRequest = put;
- break;
-
- case DELETE:
- httpRequest = new HttpDelete(uri);
- break;
-
- default:
- throw new HttpClientException ("Unrecognized HTTP Method: " + request.method());
- }
+ httpRequest = getHttpUriRequest(request, uri, entity);
for (Entry<String, List<Object>> h : request.headers().entrySet()) {
StringBuilder sb = new StringBuilder();
@@ -226,4 +199,41 @@ public class HttpClientConnector implements OpenStackClientConnector {
httpClientResponse);
}
+ private <T> HttpUriRequest getHttpUriRequest(OpenStackRequest<T> request, URI uri, HttpEntity entity) {
+ HttpUriRequest httpRequest;
+ switch (request.method()) {
+ case POST:
+ HttpPost post = new HttpPost(uri);
+ post.setEntity (entity);
+ httpRequest = post;
+ break;
+
+ case GET:
+ httpRequest = new HttpGet(uri);
+ break;
+
+ case PUT:
+ HttpPut put = new HttpPut(uri);
+ put.setEntity (entity);
+ httpRequest = put;
+ break;
+
+ case DELETE:
+ httpRequest = new HttpDelete(uri);
+ break;
+
+ default:
+ throw new HttpClientException("Unrecognized HTTP Method: " + request.method());
+ }
+ return httpRequest;
+ }
+
+ private <T> void setUriBuilderParams(OpenStackRequest<T> request, URIBuilder uriBuilder) {
+ for(Entry<String, List<Object>> entry : request.queryParams().entrySet()) {
+ for (Object o : entry.getValue()) {
+ uriBuilder.setParameter(entry.getKey(), String.valueOf(o));
+ }
+ }
+ }
+
} \ No newline at end of file