diff options
author | seshukm <seshu.kumar.m@huawei.com> | 2018-07-25 19:30:51 +0800 |
---|---|---|
committer | seshukm <seshu.kumar.m@huawei.com> | 2018-07-25 19:30:51 +0800 |
commit | a2c59f3f843d75a5fd87bc322d5340ed115da1d2 (patch) | |
tree | 8daccbd183d1552b6eb863021ba30c32a52f7eb3 /openstack-client/src/main | |
parent | 92253f30556016a54e03c0476e94f234b362c6b2 (diff) |
Basic code refactoring base client
Issue-ID: SO-729
Change-Id: Ife12f0bc1670733fca76058f33d567f266ab2f7b
Signed-off-by: seshukm <seshu.kumar.m@huawei.com>
Diffstat (limited to 'openstack-client/src/main')
9 files changed, 224 insertions, 224 deletions
diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/Entity.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/Entity.java index 66130df..58ba733 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/Entity.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/Entity.java @@ -20,51 +20,51 @@ import java.io.InputStream; public class Entity<T> { - - private T entity; - - private String contentType; - - public static <T> Entity<T> json(T entity) { - return new Entity<T>(entity, "application/json"); - } - - public static <T> Entity<T> stream(T entity) { - return new Entity<T>(entity, "application/octet-stream"); - } + + private T entity; + + private String contentType; + + public static <T> Entity<T> json(T entity) { + return new Entity<T>(entity, "application/json"); + } + + public static <T> Entity<T> stream(T entity) { + return new Entity<T>(entity, "application/octet-stream"); + } - public Entity(T entity, String contentType) { - super(); - this.entity = entity; - this.contentType = contentType; - } + public Entity(T entity, String contentType) { + super(); + this.entity = entity; + this.contentType = contentType; + } - /** - * @return the entity - */ - public T getEntity() { - return entity; - } + /** + * @return the entity + */ + public T getEntity() { + return entity; + } - /** - * @param entity the entity to set - */ - public void setEntity(T entity) { - this.entity = entity; - } + /** + * @param entity the entity to set + */ + public void setEntity(T entity) { + this.entity = entity; + } - /** - * @return the contentType - */ - public String getContentType() { - return contentType; - } + /** + * @return the contentType + */ + public String getContentType() { + return contentType; + } - /** - * @param contentType the contentType to set - */ - public void setContentType(String contentType) { - this.contentType = contentType; - } - + /** + * @param contentType the contentType to set + */ + public void setContentType(String contentType) { + this.contentType = contentType; + } + } diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/HttpMethod.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/HttpMethod.java index 200aaa9..dec8c3f 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/HttpMethod.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/HttpMethod.java @@ -17,5 +17,5 @@ package com.woorea.openstack.base.client; public enum HttpMethod { - HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE + HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE } 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 656c50b..c852ecf 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 @@ -45,18 +45,18 @@ package com.woorea.openstack.base.client; */
public abstract class OpenStackBaseException extends RuntimeException
{
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- /*
- * Implement only the basic constructors
- */
- public OpenStackBaseException () {}
-
- public OpenStackBaseException(String message) {
- super(message);
- }
+ /*
+ * Implement only the basic constructors
+ */
+ public OpenStackBaseException () {}
+
+ public OpenStackBaseException(String message) {
+ super(message);
+ }
- public OpenStackBaseException(String message, Throwable cause) {
- super(message, cause);
- }
+ public OpenStackBaseException(String message, Throwable cause) {
+ super(message, cause);
+ }
}
diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClientConnector.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClientConnector.java index 5b98440..0e4ae55 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClientConnector.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClientConnector.java @@ -19,6 +19,6 @@ package com.woorea.openstack.base.client; public interface OpenStackClientConnector { - public <T> OpenStackResponse request(OpenStackRequest<T> request); + public <T> OpenStackResponse request(OpenStackRequest<T> request); } diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackCommand.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackCommand.java index 24f34ea..c66b548 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackCommand.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackCommand.java @@ -19,6 +19,6 @@ package com.woorea.openstack.base.client; // //public interface OpenStackCommand<R> { // -// OpenStackRequest createRequest(OpenStackClient connector); +// OpenStackRequest createRequest(OpenStackClient connector); // //} 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 aaf47cc..21c58f8 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 @@ -46,13 +46,13 @@ package com.woorea.openstack.base.client; */ public class OpenStackConnectException extends OpenStackBaseException { - private static final long serialVersionUID = 7294957362769575271L; + private static final long serialVersionUID = 7294957362769575271L; - public OpenStackConnectException(String message) { - super(message); - } + public OpenStackConnectException(String message) { + super(message); + } - public OpenStackConnectException(String message, Throwable cause) { - super(message, cause); - } + public OpenStackConnectException(String message, Throwable cause) { + super(message, cause); + } } 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 fabd9db..3a082a2 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 @@ -24,135 +24,135 @@ import java.util.ArrayList; import java.util.Map; public class OpenStackRequest<R> { - - private OpenStackClient client; - - public OpenStackRequest() { - - } - - public OpenStackRequest(OpenStackClient client, HttpMethod method, CharSequence path, Entity<?> entity, Class<R> returnType) { - this.client = client; - this.method = method; - this.path = new StringBuilder(path); - this.entity = entity; - this.returnType = returnType; - header("Accept", "application/json"); - } - - private String endpoint; - - private HttpMethod method; - - private StringBuilder path = new StringBuilder(); - - private Map<String, List<Object>> headers = new HashMap<>(); - - private Entity<?> entity; - - private Class<R> returnType; - - public OpenStackRequest<R> endpoint(String endpoint) { - this.endpoint = endpoint; - return this; - } - - public String endpoint() { - return endpoint; - } + + private OpenStackClient client; + + public OpenStackRequest() { + + } + + public OpenStackRequest(OpenStackClient client, HttpMethod method, CharSequence path, Entity<?> entity, Class<R> returnType) { + this.client = client; + this.method = method; + this.path = new StringBuilder(path); + this.entity = entity; + this.returnType = returnType; + header("Accept", "application/json"); + } + + private String endpoint; + + private HttpMethod method; + + private StringBuilder path = new StringBuilder(); + + private Map<String, List<Object>> headers = new HashMap<>(); + + private Entity<?> entity; + + private Class<R> returnType; + + public OpenStackRequest<R> endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + public String endpoint() { + return endpoint; + } - public OpenStackRequest<R> method(HttpMethod method) { - this.method = method; - return this; - } - - public HttpMethod method() { - return method; - } - - public OpenStackRequest<R> path(String path) { - this.path.append(path); - return this; - } - - public String path() { - return path.toString(); - } + public OpenStackRequest<R> method(HttpMethod method) { + this.method = method; + return this; + } + + public HttpMethod method() { + return method; + } + + public OpenStackRequest<R> path(String path) { + this.path.append(path); + return this; + } + + public String path() { + return path.toString(); + } - public OpenStackRequest<R> header(String name, Object value) { - if(value != null) { - headers.put(name, Arrays.asList(value)); - } - return this; - } - - public Map<String, List<Object>> headers() { - return headers; - } - - public <T> Entity<T> entity(T entity, String contentType) { - return new Entity<>(entity, contentType); - } - - public Entity<?> entity() { - return entity; - } - - public <T> Entity<T> json(T entity) { - return entity(entity, "application/json"); - } - - public void returnType(Class<R> returnType) { - this.returnType = returnType; - } - - public Class<R> returnType() { - return returnType; - } - - public R execute() { - return client.execute(this); - } - - public OpenStackResponse request() { - return client.request(this); - } + public OpenStackRequest<R> header(String name, Object value) { + if(value != null) { + headers.put(name, Arrays.asList(value)); + } + return this; + } + + public Map<String, List<Object>> headers() { + return headers; + } + + public <T> Entity<T> entity(T entity, String contentType) { + return new Entity<>(entity, contentType); + } + + public Entity<?> entity() { + return entity; + } + + public <T> Entity<T> json(T entity) { + return entity(entity, "application/json"); + } + + public void returnType(Class<R> returnType) { + this.returnType = returnType; + } + + public Class<R> 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 + "]"; - } + /* (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<String, List<Object> > queryParams = new LinkedHashMap<>(); + private Map<String, List<Object> > queryParams = new LinkedHashMap<>(); - public Map<String, List<Object> > queryParams() { - return queryParams; - } + public Map<String, List<Object> > queryParams() { + return queryParams; + } - public OpenStackRequest<R> queryParam(String key, Object value) { - if (queryParams.containsKey(key)) { - List<Object> values = queryParams.get(key); - values.add(value); - } else { - List<Object> values = new ArrayList<>(); - values.add(value); - queryParams.put(key, values); - } + public OpenStackRequest<R> queryParam(String key, Object value) { + if (queryParams.containsKey(key)) { + List<Object> values = queryParams.get(key); + values.add(value); + } else { + List<Object> values = new ArrayList<>(); + values.add(value); + queryParams.put(key, values); + } - return this; + return this; } - - protected static String buildPath(String ... elements) { - StringBuilder stringBuilder = new StringBuilder(); - for (String element : elements) { + + protected static String buildPath(String ... elements) { + StringBuilder stringBuilder = new StringBuilder(); + for (String element : elements) { stringBuilder.append(element); } - return stringBuilder.toString(); - } + 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 1a2f4cb..0add524 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 @@ -25,14 +25,14 @@ import java.util.Map; public interface OpenStackResponse { - public <T> T getEntity(Class<T> returnType); + public <T> T getEntity(Class<T> returnType); - public <T> T getErrorEntity(Class<T> returnType); + public <T> T getErrorEntity(Class<T> returnType); - public InputStream getInputStream(); + public InputStream getInputStream(); - public String header(String name); - - public Map<String, String> headers(); - + public String header(String name); + + public Map<String, String> 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 edc7ec0..bbe0c6f 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 @@ -22,38 +22,38 @@ package com.woorea.openstack.base.client; public class OpenStackResponseException extends OpenStackBaseException { - private static final long serialVersionUID = 7294957362769575271L; - - protected String message; - - protected int status; - - // Make the response available for exception handling (includes body) - protected OpenStackResponse response; - - public OpenStackResponseException(String message, int status) { - this.message = message; - this.status = status; - this.response = null; - } - - public OpenStackResponseException(String message, int status, OpenStackResponse response) { - this.message = message; - this.status = status; - this.response = response; - } - - @Override - public String getMessage() { - return message; - } - - public int getStatus() { - return status; - } - - public OpenStackResponse getResponse() { - return response; - } + private static final long serialVersionUID = 7294957362769575271L; + + protected String message; + + protected int status; + + // Make the response available for exception handling (includes body) + protected OpenStackResponse response; + + public OpenStackResponseException(String message, int status) { + this.message = message; + this.status = status; + this.response = null; + } + + public OpenStackResponseException(String message, int status, OpenStackResponse response) { + this.message = message; + this.status = status; + this.response = response; + } + + @Override + public String getMessage() { + return message; + } + + public int getStatus() { + return status; + } + + public OpenStackResponse getResponse() { + return response; + } } |