summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2019-04-17 12:08:32 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-17 12:08:32 +0000
commite8e3627f001e1c82f961a7f2fc491855cb2d621f (patch)
treee27d2e19762835c7fb7015fe442a3a286c069566
parent93f480949c9b0babd4f10d7b0e47f5c23b9b6b88 (diff)
parent1f26e77e0911c520f60e45a879365e471331bff4 (diff)
Merge "The Cyclomatic Complexity of this method "request""
-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