AAI-1523 Batch reformat aai-rest 86/82886/2
authorKeong Lim <keong.lim@huawei.com>
Thu, 21 Mar 2019 04:33:15 +0000 (15:33 +1100)
committerKeong Lim <keong.lim@huawei.com>
Thu, 11 Apr 2019 03:43:41 +0000 (13:43 +1000)
Use maven plugins from AAI-2198 to do batch reformat of aai-rest
to consistent code style.

Change-Id: I7eba1928cbc0958e2dae369547cba262e019d4d0
Issue-ID: AAI-1523
Signed-off-by: Keong Lim <keong.lim@huawei.com>
12 files changed:
aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java
aai-rest/src/main/java/org/onap/aai/restclient/ClientType.java
aai-rest/src/main/java/org/onap/aai/restclient/JettyPasswordDecoder.java
aai-rest/src/main/java/org/onap/aai/restclient/NoAuthRestClient.java
aai-rest/src/main/java/org/onap/aai/restclient/OneWaySSLRestClient.java
aai-rest/src/main/java/org/onap/aai/restclient/PasswordDecoder.java
aai-rest/src/main/java/org/onap/aai/restclient/PropertyPasswordConfiguration.java
aai-rest/src/main/java/org/onap/aai/restclient/RestClient.java
aai-rest/src/main/java/org/onap/aai/restclient/RestClientFactory.java
aai-rest/src/main/java/org/onap/aai/restclient/RestClientResponseErrorHandler.java
aai-rest/src/main/java/org/onap/aai/restclient/TwoWaySSLRestClient.java
aai-rest/src/test/java/org/onap/aai/restclient/RestClientTest.java

index 652f399..b9fe87f 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
+
+import java.util.Collections;
+import java.util.Map;
+
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Component;
 import org.springframework.util.MultiValueMap;
 
-import java.util.Collections;
-import java.util.Map;
-
-@Component(value=ClientType.AAI)
-public class AAIRestClient extends TwoWaySSLRestClient{
+@Component(value = ClientType.AAI)
+public class AAIRestClient extends TwoWaySSLRestClient {
 
-       private static EELFLogger logger = EELFManager.getInstance().getLogger(AAIRestClient.class);
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(AAIRestClient.class);
 
-       @Value("${aai.base.url}")
-       private String baseUrl;
+    @Value("${aai.base.url}")
+    private String baseUrl;
 
-       @Value("${aai.ssl.key-store}")
-       private String keystorePath;
+    @Value("${aai.ssl.key-store}")
+    private String keystorePath;
 
-       @Value("${aai.ssl.trust-store}")
-       private String truststorePath;
+    @Value("${aai.ssl.trust-store}")
+    private String truststorePath;
 
-       @Value("${aai.ssl.key-store-password}")
-       private String keystorePassword;
+    @Value("${aai.ssl.key-store-password}")
+    private String keystorePassword;
 
-       @Value("${aai.ssl.trust-store-password}")
-       private String truststorePassword;
+    @Value("${aai.ssl.trust-store-password}")
+    private String truststorePassword;
 
-       @Override
-       public String getBaseUrl() {
-               return baseUrl;
-       }
+    @Override
+    public String getBaseUrl() {
+        return baseUrl;
+    }
 
-       @Override
-       protected String getKeystorePath() {
-               return keystorePath;
-       }
+    @Override
+    protected String getKeystorePath() {
+        return keystorePath;
+    }
 
-       @Override
-       protected String getTruststorePath() {
-               return truststorePath;
-       }
+    @Override
+    protected String getTruststorePath() {
+        return truststorePath;
+    }
 
-       @Override
-       protected char[] getKeystorePassword() {
-               return keystorePassword.toCharArray();
-       }
+    @Override
+    protected char[] getKeystorePassword() {
+        return keystorePassword.toCharArray();
+    }
 
-       @Override
-       protected char[] getTruststorePassword() {
-               return truststorePassword.toCharArray();
-       }
+    @Override
+    protected char[] getTruststorePassword() {
+        return truststorePassword.toCharArray();
+    }
 
-       @Override
-       public MultiValueMap<String, String> getHeaders(Map<String, String> headers) {
-               HttpHeaders httpHeaders = new HttpHeaders();
-               httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
-               httpHeaders.setContentType(MediaType.APPLICATION_JSON);
-               httpHeaders.add("Real-Time", "true");
-               headers.forEach(httpHeaders::add);
-               return httpHeaders;
-       }
+    @Override
+    public MultiValueMap<String, String> getHeaders(Map<String, String> headers) {
+        HttpHeaders httpHeaders = new HttpHeaders();
+        httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
+        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+        httpHeaders.add("Real-Time", "true");
+        headers.forEach(httpHeaders::add);
+        return httpHeaders;
+    }
 
 }
index 855bab7..4633b42 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
 public class ClientType {
index 552aef9..7a1bc11 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
 import org.eclipse.jetty.util.security.Password;
index 47fe99d..b5a0101 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
+
+import javax.annotation.PostConstruct;
+
 import org.apache.http.client.HttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.springframework.boot.web.client.RestTemplateBuilder;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.web.client.RestTemplate;
 
-import javax.annotation.PostConstruct;
-
-public abstract class NoAuthRestClient extends RestClient{
+public abstract class NoAuthRestClient extends RestClient {
 
-       private static EELFLogger logger = EELFManager.getInstance().getLogger(NoAuthRestClient.class);
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(NoAuthRestClient.class);
 
-       protected RestTemplate restTemplate;
+    protected RestTemplate restTemplate;
 
-       @PostConstruct
-       public void init () throws Exception {
-               HttpClient client = HttpClients.createDefault();
-               restTemplate = new RestTemplateBuilder()
-                               .requestFactory(new HttpComponentsClientHttpRequestFactory(client))
-                               .build();
+    @PostConstruct
+    public void init() throws Exception {
+        HttpClient client = HttpClients.createDefault();
+        restTemplate =
+                new RestTemplateBuilder().requestFactory(new HttpComponentsClientHttpRequestFactory(client)).build();
 
-               restTemplate.setErrorHandler(new RestClientResponseErrorHandler());
-       }
+        restTemplate.setErrorHandler(new RestClientResponseErrorHandler());
+    }
 
-       @Override
-       public RestTemplate getRestTemplate() {
-               return restTemplate;
-       }
+    @Override
+    public RestTemplate getRestTemplate() {
+        return restTemplate;
+    }
 
 }
index 96cd51e..30545db 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.security.KeyStore;
+
+import javax.annotation.PostConstruct;
+import javax.net.ssl.SSLContext;
+
 import org.apache.http.client.HttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.ssl.SSLContextBuilder;
@@ -29,13 +39,6 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.util.ResourceUtils;
 import org.springframework.web.client.RestTemplate;
 
-import javax.annotation.PostConstruct;
-import javax.net.ssl.SSLContext;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.security.KeyStore;
-
 public abstract class OneWaySSLRestClient extends RestClient {
 
     private static EELFLogger logger = EELFManager.getInstance().getLogger(OneWaySSLRestClient.class);
@@ -49,25 +52,19 @@ public abstract class OneWaySSLRestClient extends RestClient {
 
         String trustStore = getTruststorePath();
 
-        SSLContext sslContext = SSLContextBuilder
-            .create()
-            .loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword)
-            .build();
+        SSLContext sslContext = SSLContextBuilder.create()
+                .loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword).build();
 
-        HttpClient client = HttpClients.custom()
-            .setSSLContext(sslContext)
-            .setSSLHostnameVerifier((s, sslSession) -> true)
-            .build();
+        HttpClient client =
+                HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier((s, sslSession) -> true).build();
 
-        restTemplate = new RestTemplateBuilder()
-            .requestFactory(new HttpComponentsClientHttpRequestFactory(client))
-            .build();
+        restTemplate =
+                new RestTemplateBuilder().requestFactory(new HttpComponentsClientHttpRequestFactory(client)).build();
 
         restTemplate.setErrorHandler(new RestClientResponseErrorHandler());
 
     }
 
-
     protected abstract String getTruststorePath();
 
     protected abstract char[] getTruststorePassword();
index 51c1118..a11e2b6 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
 public interface PasswordDecoder {
index 97ae7bc..3160469 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 import org.springframework.context.ApplicationContextInitializer;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.core.env.ConfigurableEnvironment;
@@ -26,11 +32,6 @@ import org.springframework.core.env.EnumerablePropertySource;
 import org.springframework.core.env.MapPropertySource;
 import org.springframework.core.env.PropertySource;
 
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 public class PropertyPasswordConfiguration implements ApplicationContextInitializer<ConfigurableApplicationContext> {
 
     private static final Pattern decodePasswordPattern = Pattern.compile("password\\((.*?)\\)");
@@ -44,7 +45,8 @@ public class PropertyPasswordConfiguration implements ApplicationContextInitiali
             Map<String, Object> propertyOverrides = new LinkedHashMap<>();
             decodePasswords(propertySource, propertyOverrides);
             if (!propertyOverrides.isEmpty()) {
-                PropertySource<?> decodedProperties = new MapPropertySource("decoded " + propertySource.getName(), propertyOverrides);
+                PropertySource<?> decodedProperties =
+                        new MapPropertySource("decoded " + propertySource.getName(), propertyOverrides);
                 environment.getPropertySources().addBefore(propertySource.getName(), decodedProperties);
             }
         }
@@ -64,7 +66,8 @@ public class PropertyPasswordConfiguration implements ApplicationContextInitiali
     }
 
     private String decodePasswordsInString(String input) {
-        if (input == null) return null;
+        if (input == null)
+            return null;
         StringBuffer output = new StringBuffer();
         Matcher matcher = decodePasswordPattern.matcher(input);
         while (matcher.find()) {
index 6ac51b2..130cb6e 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.io.Resource;
 import org.springframework.http.HttpEntity;
@@ -32,19 +38,15 @@ import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestClientException;
 import org.springframework.web.client.RestTemplate;
 
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Map;
-
 public abstract class RestClient {
 
     private static EELFLogger log = EELFManager.getInstance().getLogger(RestClient.class);
     @Value("${spring.application.name}")
     protected String appName;
 
-
     /**
      * Execute the given http method against the uri with passed headers
+     * 
      * @param uri properly encoded, can include query params also properly encoded
      * @param method http method of the request
      * @param headers headers for the request
@@ -52,10 +54,11 @@ public abstract class RestClient {
      * @return response of request
      * @throws RestClientException on internal rest template exception or invalid url
      */
-    public ResponseEntity execute(String uri, HttpMethod method, Map<String,String> headers, String body) throws RestClientException {
+    public ResponseEntity execute(String uri, HttpMethod method, Map<String, String> headers, String body)
+            throws RestClientException {
 
         HttpEntity<String> httpEntity;
-        log.debug ("Headers: {}", headers);
+        log.debug("Headers: {}", headers);
         if (body == null) {
             httpEntity = new HttpEntity<>(getHeaders(headers));
         } else {
@@ -85,6 +88,7 @@ public abstract class RestClient {
 
     /**
      * Execute the given http method against the uri with passed headers
+     * 
      * @param uri properly encoded, can include query params also properly encoded
      * @param method http method of the request
      * @param headers headers for the request
@@ -92,35 +96,40 @@ public abstract class RestClient {
      * @return response of request
      * @throws RestClientException on internal rest template exception or invalid url
      */
-    public ResponseEntity execute(String uri, String method, Map<String,String> headers, String body) throws RestClientException{
+    public ResponseEntity execute(String uri, String method, Map<String, String> headers, String body)
+            throws RestClientException {
         return execute(uri, HttpMethod.valueOf(method), headers, body);
     }
 
     /**
      * Execute the given http method against the uri with passed headers
+     * 
      * @param uri properly encoded, can include query params also properly encoded
      * @param method http method of the request
      * @param headers headers for the request
      * @return response of request
      * @throws RestClientException on internal rest template exception or invalid url
      */
-    public ResponseEntity execute(String uri, HttpMethod method, Map<String,String> headers) throws RestClientException{
+    public ResponseEntity execute(String uri, HttpMethod method, Map<String, String> headers)
+            throws RestClientException {
         return execute(uri, method, headers, null);
     }
 
     /**
      * Execute the given http method against the uri with passed headers
+     * 
      * @param uri properly encoded, can include query params also properly encoded
      * @param method http method of the request
      * @param headers headers for the request
      * @return response of request
      * @throws RestClientException on internal rest template exception or invalid url
      */
-    public ResponseEntity execute(String uri, String method, Map<String,String> headers) throws RestClientException{
+    public ResponseEntity execute(String uri, String method, Map<String, String> headers) throws RestClientException {
         return execute(uri, HttpMethod.valueOf(method), headers, null);
     }
 
-    public ResponseEntity executeResource(String uri, HttpMethod method, Map<String, String> headers, String body) throws RestClientException {
+    public ResponseEntity executeResource(String uri, HttpMethod method, Map<String, String> headers, String body)
+            throws RestClientException {
 
         HttpEntity httpEntity;
         log.debug("Headers: " + headers.toString());
@@ -134,20 +143,12 @@ public abstract class RestClient {
     }
 
     public ResponseEntity getGetRequest(String content, String uri, Map<String, String> headersMap) {
-        return this.execute(
-            uri,
-            HttpMethod.GET,
-            headersMap,
-            content);
+        return this.execute(uri, HttpMethod.GET, headersMap, content);
 
     }
 
     public ResponseEntity getGetResource(String content, String uri, Map<String, String> headersMap) {
-        return this.executeResource(
-            uri,
-            HttpMethod.GET,
-            headersMap,
-            content);
+        return this.executeResource(uri, HttpMethod.GET, headersMap, content);
 
     }
 
index 3a19f2d..d41c29a 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
 /**
@@ -27,7 +28,7 @@ public interface RestClientFactory {
     /**
      *
      * @param clientType
-     *                 type of client to return
+     *        type of client to return
      * @return
      */
     RestClient getRestClient(String clientType);
index 2271a1f..9c4876d 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
+
+import java.io.IOException;
+
 import org.springframework.http.HttpStatus;
 import org.springframework.http.client.ClientHttpResponse;
 import org.springframework.web.client.ResponseErrorHandler;
 
-import java.io.IOException;
-
 public class RestClientResponseErrorHandler implements ResponseErrorHandler {
 
     private static EELFLogger logger = EELFManager.getInstance().getLogger(RestClientResponseErrorHandler.class);
index dd5deaa..a69977f 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.security.KeyStore;
+
+import javax.annotation.PostConstruct;
+import javax.net.ssl.SSLContext;
+
 import org.apache.http.client.HttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.ssl.SSLContextBuilder;
@@ -29,13 +39,6 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.util.ResourceUtils;
 import org.springframework.web.client.RestTemplate;
 
-import javax.annotation.PostConstruct;
-import javax.net.ssl.SSLContext;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.security.KeyStore;
-
 public abstract class TwoWaySSLRestClient extends RestClient {
 
     private static EELFLogger logger = EELFManager.getInstance().getLogger(TwoWaySSLRestClient.class);
@@ -51,20 +54,15 @@ public abstract class TwoWaySSLRestClient extends RestClient {
         String keyStore = getKeystorePath();
         String trustStore = getTruststorePath();
 
-        SSLContext sslContext = SSLContextBuilder
-            .create()
-            .loadKeyMaterial(loadPfx(keyStore, keyStorePassword), keyStorePassword)
-            .loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword)
-            .build();
+        SSLContext sslContext =
+                SSLContextBuilder.create().loadKeyMaterial(loadPfx(keyStore, keyStorePassword), keyStorePassword)
+                        .loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword).build();
 
-        HttpClient client = HttpClients.custom()
-            .setSSLContext(sslContext)
-            .setSSLHostnameVerifier((s, sslSession) -> true)
-            .build();
+        HttpClient client =
+                HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier((s, sslSession) -> true).build();
 
-        restTemplate = new RestTemplateBuilder()
-            .requestFactory(new HttpComponentsClientHttpRequestFactory(client))
-            .build();
+        restTemplate =
+                new RestTemplateBuilder().requestFactory(new HttpComponentsClientHttpRequestFactory(client)).build();
 
         restTemplate.setErrorHandler(new RestClientResponseErrorHandler());
 
index 4c3b0fc..36b8fb3 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.restclient;
 
 public class RestClientTest {