From 3f9a0c3183480d150089c0d5a6e507c877f7d121 Mon Sep 17 00:00:00 2001 From: "Smokowski, Steve (ss835w)" Date: Thu, 2 May 2019 09:42:55 -0400 Subject: Enhance Openstack Client Update Openstack Client to support additional fields Updat all formatting issues Issue-ID: SO-1844 Change-Id: I1369e0c18cc25274db8df7e12855a020b8da38da Signed-off-by: Smokowski, Steve (ss835w) --- .../base/client/OpenStackBaseException.java | 79 ++++--- .../openstack/base/client/OpenStackClient.java | 15 +- .../base/client/OpenStackConnectException.java | 7 +- .../openstack/base/client/OpenStackRequest.java | 254 ++++++++++----------- .../openstack/base/client/OpenStackResponse.java | 4 +- .../base/client/OpenStackResponseException.java | 2 +- .../base/client/OpenStackResponseStatus.java | 4 +- .../base/client/OpenStackSimpleTokenProvider.java | 3 +- .../openstack/common/session/OpenStackSession.java | 2 +- .../common/session/OpenStackSessionHolder.java | 2 +- 10 files changed, 185 insertions(+), 187 deletions(-) (limited to 'openstack-client/src/main/java/com/woorea/openstack') diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java index 53d2595..bcb7d51 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java @@ -1,40 +1,39 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - - -package com.woorea.openstack.base.client; - -/** - * A common abstract parent of all Openstack Exception types, allowing - * calling classes the choice to catch all error exceptions together. - */ -public abstract class OpenStackBaseException extends RuntimeException -{ - private static final long serialVersionUID = 1L; - - /* - * Implement only the basic constructors - */ - public OpenStackBaseException () {} - - public OpenStackBaseException(String message) { - super(message); - } - - public OpenStackBaseException(String message, Throwable cause) { - super(message, cause); - } -} \ No newline at end of file +/*- + * ============LICENSE_START======================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package com.woorea.openstack.base.client; + +/** + * A common abstract parent of all Openstack Exception types, allowing calling classes the choice to catch all error + * exceptions together. + */ +public abstract class OpenStackBaseException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /* + * Implement only the basic constructors + */ + public OpenStackBaseException() {} + + public OpenStackBaseException(String message) { + super(message); + } + + public OpenStackBaseException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java index a111975..8c61b30 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java @@ -70,23 +70,24 @@ public class OpenStackClient { try { return connector.request(request); } catch (OpenStackResponseException e) { - if (e.getStatus() != OpenStackResponseStatus.NOT_AUTHORIZED - || tokenProvider == null) { + if (e.getStatus() != OpenStackResponseStatus.NOT_AUTHORIZED || tokenProvider == null) { throw e; } authException = e; tokenProvider.expireToken(); } } - if(null == authException){ - authException = new OpenStackResponseException("Unknown issue",500); + if (null == authException) { + authException = new OpenStackResponseException("Unknown issue", 500); } throw authException; } public T execute(OpenStackRequest request) { - OpenStackResponse response = request(request); - return (request.returnType() != null && request.returnType() != Void.class) ? response.getEntity(request.returnType()) : null; + OpenStackResponse response = request(request); + return (request.returnType() != null && request.returnType() != Void.class) + ? response.getEntity(request.returnType()) + : null; } public void property(String property, String value) { @@ -105,4 +106,4 @@ public class OpenStackClient { return new OpenStackRequest<>(this, HttpMethod.GET, path, null, returnType); } -} \ No newline at end of file +} diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java index 0e29335..30d6722 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java @@ -18,9 +18,8 @@ package com.woorea.openstack.base.client; /** - * Custom RuntimeException to report connection errors to Openstack endpoints. - * Must be a RuntimeException to conform with OpenstackClient interface, which - * does not declare specific Exceptions. + * Custom RuntimeException to report connection errors to Openstack endpoints. Must be a RuntimeException to conform + * with OpenstackClient interface, which does not declare specific Exceptions. */ public class OpenStackConnectException extends OpenStackBaseException { @@ -33,4 +32,4 @@ public class OpenStackConnectException extends OpenStackBaseException { public OpenStackConnectException(String message, Throwable cause) { super(message, cause); } -} \ No newline at end of file +} diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java index 07b6f70..d896837 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java @@ -25,137 +25,137 @@ import java.util.Map; public class OpenStackRequest { - private OpenStackClient client; + private OpenStackClient client; - private String endpoint; - - private HttpMethod method; + private String endpoint; + + private HttpMethod method; - private StringBuilder path = new StringBuilder(); + private StringBuilder path = new StringBuilder(); - private Map> headers = new HashMap<>(); + private Map> headers = new HashMap<>(); - private Entity entity; + private Entity entity; - private Class returnType; + private Class returnType; - public OpenStackRequest() { - - } - - public OpenStackRequest(OpenStackClient client, HttpMethod method, CharSequence path, Entity entity, - Class returnType) { - this.client = client; - this.method = method; - this.path = new StringBuilder(path); - this.entity = entity; - this.returnType = returnType; - header("Accept", "application/json"); - } - - public OpenStackRequest endpoint(String endpoint) { - this.endpoint = endpoint; - return this; - } - - public String endpoint() { - return endpoint; - } - - public OpenStackRequest method(HttpMethod method) { - this.method = method; - return this; - } - - public HttpMethod method() { - return method; - } - - public OpenStackRequest path(String path) { - this.path.append(path); - return this; - } - - public String path() { - return path.toString(); - } - - public OpenStackRequest header(String name, Object value) { - if (value != null) { - headers.put(name, Arrays.asList(value)); - } - return this; - } - - public Map> headers() { - return headers; - } - - public Entity entity(T entity, String contentType) { - return new Entity<>(entity, contentType); - } - - public Entity entity() { - return entity; - } - - public Entity json(T entity) { - return entity(entity, "application/json"); - } - - public void returnType(Class returnType) { - this.returnType = returnType; - } - - public Class returnType() { - return returnType; - } - - public R execute() { - return client.execute(this); - } - - public OpenStackResponse request() { - return client.request(this); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "OpenStackRequest [endpoint=" + endpoint + ", method=" + method + ", path=" + path + ", headers=" - + headers + ", entity=" + entity + ", returnType=" + returnType + "]"; - } - - private Map> queryParams = new LinkedHashMap<>(); - - public Map> queryParams() { - return queryParams; - } - - public OpenStackRequest queryParam(String key, Object value) { - if (value != null) { - if (queryParams.containsKey(key)) { - List values = queryParams.get(key); - values.add(value); - } else { - List values = new ArrayList<>(); - values.add(value); - queryParams.put(key, values); - } - } - return this; - } - - protected static String buildPath(String... elements) { - StringBuilder stringBuilder = new StringBuilder(); - for (String element : elements) { - stringBuilder.append(element); - } - - return stringBuilder.toString(); - } + public OpenStackRequest() { + + } + + public OpenStackRequest(OpenStackClient client, HttpMethod method, CharSequence path, Entity entity, + Class returnType) { + this.client = client; + this.method = method; + this.path = new StringBuilder(path); + this.entity = entity; + this.returnType = returnType; + header("Accept", "application/json"); + } + + public OpenStackRequest endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + public String endpoint() { + return endpoint; + } + + public OpenStackRequest method(HttpMethod method) { + this.method = method; + return this; + } + + public HttpMethod method() { + return method; + } + + public OpenStackRequest path(String path) { + this.path.append(path); + return this; + } + + public String path() { + return path.toString(); + } + + public OpenStackRequest header(String name, Object value) { + if (value != null) { + headers.put(name, Arrays.asList(value)); + } + return this; + } + + public Map> headers() { + return headers; + } + + public Entity entity(T entity, String contentType) { + return new Entity<>(entity, contentType); + } + + public Entity entity() { + return entity; + } + + public Entity json(T entity) { + return entity(entity, "application/json"); + } + + public void returnType(Class returnType) { + this.returnType = returnType; + } + + public Class returnType() { + return returnType; + } + + public R execute() { + return client.execute(this); + } + + public OpenStackResponse request() { + return client.request(this); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "OpenStackRequest [endpoint=" + endpoint + ", method=" + method + ", path=" + path + ", headers=" + + headers + ", entity=" + entity + ", returnType=" + returnType + "]"; + } + + private Map> queryParams = new LinkedHashMap<>(); + + public Map> queryParams() { + return queryParams; + } + + public OpenStackRequest queryParam(String key, Object value) { + if (value != null) { + if (queryParams.containsKey(key)) { + List values = queryParams.get(key); + values.add(value); + } else { + List values = new ArrayList<>(); + values.add(value); + queryParams.put(key, values); + } + } + return this; + } + + protected static String buildPath(String... elements) { + StringBuilder stringBuilder = new StringBuilder(); + for (String element : elements) { + stringBuilder.append(element); + } + + return stringBuilder.toString(); + } } diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java index 0add524..dfc1d13 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java @@ -32,7 +32,7 @@ public interface OpenStackResponse { public InputStream getInputStream(); public String header(String name); - + public Map headers(); - + } diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java index e8b1e87..1d7f29b 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java @@ -56,4 +56,4 @@ public class OpenStackResponseException extends OpenStackBaseException { return response; } -} \ No newline at end of file +} diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java index 73204e9..aa552ad 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java @@ -18,7 +18,7 @@ package com.woorea.openstack.base.client; public class OpenStackResponseStatus { - private OpenStackResponseStatus(){ + private OpenStackResponseStatus() { } @@ -28,4 +28,4 @@ public class OpenStackResponseStatus { public static final int CONFLICT = 409; -} \ No newline at end of file +} diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java index a7dd2e5..74b92a1 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java @@ -30,7 +30,6 @@ public class OpenStackSimpleTokenProvider implements OpenStackTokenProvider { } @Override - public void expireToken() { - } + public void expireToken() {} } diff --git a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java index 618adb5..edef0a9 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java +++ b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java @@ -14,4 +14,4 @@ * ============LICENSE_END========================================================= */ -package com.woorea.openstack.common.session; \ No newline at end of file +package com.woorea.openstack.common.session; diff --git a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java index 618adb5..edef0a9 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java +++ b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java @@ -14,4 +14,4 @@ * ============LICENSE_END========================================================= */ -package com.woorea.openstack.common.session; \ No newline at end of file +package com.woorea.openstack.common.session; -- cgit 1.2.3-korg