summaryrefslogtreecommitdiffstats
path: root/openstack-client/src/main
diff options
context:
space:
mode:
authorseshukm <seshu.kumar.m@huawei.com>2018-07-25 16:27:02 +0800
committerSeshu Kumar M <seshu.kumar.m@huawei.com>2018-07-25 09:33:51 +0000
commit20395f507c119f2efbec6ab98537807279524fd2 (patch)
tree2135a73cc34e7912c87a0b4badbdca7741b372a0 /openstack-client/src/main
parenta1d8ec78ffd781dfc0ed22bae02b89840a812b8d (diff)
fix for the null throw
Issue-ID: SO-729 Change-Id: I8de79ead36e7d7385ee44920198c89777e466fc7 Signed-off-by: seshukm <seshu.kumar.m@huawei.com>
Diffstat (limited to 'openstack-client/src/main')
-rw-r--r--openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java160
1 files changed, 81 insertions, 79 deletions
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 7d5f14f..89c7840 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
@@ -24,83 +24,85 @@ import java.util.Properties;
import java.util.ServiceLoader;
public class OpenStackClient {
-
- protected String endpoint;
-
- protected OpenStackTokenProvider tokenProvider;
-
- protected static int AUTHENTICATION_RETRIES = 1;
-
- protected OpenStackClientConnector connector;
-
- protected Properties properties = new Properties();
-
- protected static OpenStackClientConnector DEFAULT_CONNECTOR;
-
- static {
- ServiceLoader<OpenStackClientConnector> connectorLoader;
- connectorLoader = ServiceLoader.load(OpenStackClientConnector.class);
-
- for (OpenStackClientConnector clientConnector : connectorLoader) {
- DEFAULT_CONNECTOR = clientConnector;
- break;
- }
- }
-
- public OpenStackClient(String endpoint) {
- this.endpoint = endpoint;
- this.connector = DEFAULT_CONNECTOR;
- }
-
- public OpenStackClient(String endpoint, OpenStackClientConnector connector) {
- this.endpoint = endpoint;
- this.connector = (connector == null) ? DEFAULT_CONNECTOR : connector;
- }
-
- public <T> OpenStackResponse request(OpenStackRequest<T> request) {
- OpenStackResponseException authException = null;
- System.out.println("Openstack query:"+request.toString());
- for (int i = 0; i <= AUTHENTICATION_RETRIES; i++) {
- request.endpoint(endpoint);
-
- if (tokenProvider != null) {
- request.header("X-Auth-Token", tokenProvider.getToken());
- }
-
- try {
- return connector.request(request);
- } catch (OpenStackResponseException e) {
- if (e.getStatus() != OpenStackResponseStatus.NOT_AUTHORIZED
- || tokenProvider == null) {
- throw e;
- }
- authException = e;
- tokenProvider.expireToken();
- }
- }
-
- throw authException;
- }
-
- public <T> T execute(OpenStackRequest<T> request) {
- OpenStackResponse response = request(request);
- return (request.returnType() != null && request.returnType() != Void.class) ? response.getEntity(request.returnType()) : null;
- }
-
- public void property(String property, String value) {
- properties.put(property, value);
- }
-
- public void setTokenProvider(OpenStackTokenProvider tokenProvider) {
- this.tokenProvider = tokenProvider;
- }
-
- public void token(String token) {
- setTokenProvider(new OpenStackSimpleTokenProvider(token));
- }
-
- public <R> OpenStackRequest<R> get(String path, Class<R> returnType) {
- return new OpenStackRequest<>(this, HttpMethod.GET, path, null, returnType);
- }
-
+
+ protected String endpoint;
+
+ protected OpenStackTokenProvider tokenProvider;
+
+ protected static int AUTHENTICATION_RETRIES = 1;
+
+ protected OpenStackClientConnector connector;
+
+ protected Properties properties = new Properties();
+
+ protected static OpenStackClientConnector DEFAULT_CONNECTOR;
+
+ static {
+ ServiceLoader<OpenStackClientConnector> connectorLoader;
+ connectorLoader = ServiceLoader.load(OpenStackClientConnector.class);
+
+ for (OpenStackClientConnector clientConnector : connectorLoader) {
+ DEFAULT_CONNECTOR = clientConnector;
+ break;
+ }
+ }
+
+ public OpenStackClient(String endpoint) {
+ this.endpoint = endpoint;
+ this.connector = DEFAULT_CONNECTOR;
+ }
+
+ public OpenStackClient(String endpoint, OpenStackClientConnector connector) {
+ this.endpoint = endpoint;
+ this.connector = (connector == null) ? DEFAULT_CONNECTOR : connector;
+ }
+
+ public <T> OpenStackResponse request(OpenStackRequest<T> request) {
+ OpenStackResponseException authException = null;
+ System.out.println("Openstack query:"+request.toString());
+ for (int i = 0; i <= AUTHENTICATION_RETRIES; i++) {
+ request.endpoint(endpoint);
+
+ if (tokenProvider != null) {
+ request.header("X-Auth-Token", tokenProvider.getToken());
+ }
+
+ try {
+ return connector.request(request);
+ } catch (OpenStackResponseException e) {
+ if (e.getStatus() != OpenStackResponseStatus.NOT_AUTHORIZED
+ || tokenProvider == null) {
+ throw e;
+ }
+ authException = e;
+ tokenProvider.expireToken();
+ }
+ }
+ if(null == authException){
+ authException = new OpenStackResponseException("Unknown issue",500);
+ }
+ throw authException;
+ }
+
+ public <T> T execute(OpenStackRequest<T> request) {
+ OpenStackResponse response = request(request);
+ return (request.returnType() != null && request.returnType() != Void.class) ? response.getEntity(request.returnType()) : null;
+ }
+
+ public void property(String property, String value) {
+ properties.put(property, value);
+ }
+
+ public void setTokenProvider(OpenStackTokenProvider tokenProvider) {
+ this.tokenProvider = tokenProvider;
+ }
+
+ public void token(String token) {
+ setTokenProvider(new OpenStackSimpleTokenProvider(token));
+ }
+
+ public <R> OpenStackRequest<R> get(String path, Class<R> returnType) {
+ return new OpenStackRequest<>(this, HttpMethod.GET, path, null, returnType);
+ }
+
}