From a2c59f3f843d75a5fd87bc322d5340ed115da1d2 Mon Sep 17 00:00:00 2001 From: seshukm Date: Wed, 25 Jul 2018 19:30:51 +0800 Subject: Basic code refactoring base client Issue-ID: SO-729 Change-Id: Ife12f0bc1670733fca76058f33d567f266ab2f7b Signed-off-by: seshukm --- .../com/woorea/openstack/base/client/Entity.java | 84 ++++---- .../woorea/openstack/base/client/HttpMethod.java | 2 +- .../base/client/OpenStackBaseException.java | 24 +-- .../base/client/OpenStackClientConnector.java | 2 +- .../openstack/base/client/OpenStackCommand.java | 2 +- .../base/client/OpenStackConnectException.java | 14 +- .../openstack/base/client/OpenStackRequest.java | 240 ++++++++++----------- .../openstack/base/client/OpenStackResponse.java | 14 +- .../base/client/OpenStackResponseException.java | 66 +++--- 9 files changed, 224 insertions(+), 224 deletions(-) (limited to 'openstack-client') 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 { - - private T entity; - - private String contentType; - - public static Entity json(T entity) { - return new Entity(entity, "application/json"); - } - - public static Entity stream(T entity) { - return new Entity(entity, "application/octet-stream"); - } + + private T entity; + + private String contentType; + + public static Entity json(T entity) { + return new Entity(entity, "application/json"); + } + + public static Entity stream(T entity) { + return new Entity(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 OpenStackResponse request(OpenStackRequest request); + public OpenStackResponse request(OpenStackRequest 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 { // -// 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 { - - private OpenStackClient client; - - 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"); - } - - private String endpoint; - - private HttpMethod method; - - private StringBuilder path = new StringBuilder(); - - private Map> headers = new HashMap<>(); - - private Entity entity; - - private Class returnType; - - public OpenStackRequest 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 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> headers = new HashMap<>(); + + private Entity entity; + + private Class returnType; + + 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 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); - } + 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 + "]"; - } + /* (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<>(); + private Map > queryParams = new LinkedHashMap<>(); - public Map > queryParams() { - return queryParams; - } + public Map > queryParams() { + return queryParams; + } - public OpenStackRequest queryParam(String key, Object value) { - if (queryParams.containsKey(key)) { - List values = queryParams.get(key); - values.add(value); - } else { - List values = new ArrayList<>(); - values.add(value); - queryParams.put(key, values); - } + public OpenStackRequest queryParam(String key, Object value) { + 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; + 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 getEntity(Class returnType); + public T getEntity(Class returnType); - public T getErrorEntity(Class returnType); + public T getErrorEntity(Class returnType); - public InputStream getInputStream(); + public InputStream getInputStream(); - public String header(String name); - - public Map headers(); - + 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 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; + } } -- cgit 1.2.3-korg