diff options
Diffstat (limited to 'aai-rest/src')
12 files changed, 140 insertions, 131 deletions
diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java b/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java index 652f399a..b9fe87f1 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java @@ -17,72 +17,74 @@ * 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; + } } diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/ClientType.java b/aai-rest/src/main/java/org/onap/aai/restclient/ClientType.java index 855bab71..4633b425 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/ClientType.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/ClientType.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.restclient; public class ClientType { diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/JettyPasswordDecoder.java b/aai-rest/src/main/java/org/onap/aai/restclient/JettyPasswordDecoder.java index 552aef96..7a1bc110 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/JettyPasswordDecoder.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/JettyPasswordDecoder.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.restclient; import org.eclipse.jetty.util.security.Password; diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/NoAuthRestClient.java b/aai-rest/src/main/java/org/onap/aai/restclient/NoAuthRestClient.java index 47fe99d8..b5a0101d 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/NoAuthRestClient.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/NoAuthRestClient.java @@ -17,37 +17,38 @@ * 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; + } } diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/OneWaySSLRestClient.java b/aai-rest/src/main/java/org/onap/aai/restclient/OneWaySSLRestClient.java index 96cd51e8..30545dba 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/OneWaySSLRestClient.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/OneWaySSLRestClient.java @@ -17,10 +17,20 @@ * 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(); diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/PasswordDecoder.java b/aai-rest/src/main/java/org/onap/aai/restclient/PasswordDecoder.java index 51c11181..a11e2b6c 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/PasswordDecoder.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/PasswordDecoder.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.restclient; public interface PasswordDecoder { diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/PropertyPasswordConfiguration.java b/aai-rest/src/main/java/org/onap/aai/restclient/PropertyPasswordConfiguration.java index 97ae7bc6..3160469a 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/PropertyPasswordConfiguration.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/PropertyPasswordConfiguration.java @@ -17,8 +17,14 @@ * 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()) { diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/RestClient.java b/aai-rest/src/main/java/org/onap/aai/restclient/RestClient.java index 6ac51b2f..130cb6ef 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/RestClient.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/RestClient.java @@ -19,10 +19,16 @@ * 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); } diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/RestClientFactory.java b/aai-rest/src/main/java/org/onap/aai/restclient/RestClientFactory.java index 3a19f2de..d41c29ae 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/RestClientFactory.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/RestClientFactory.java @@ -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); diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/RestClientResponseErrorHandler.java b/aai-rest/src/main/java/org/onap/aai/restclient/RestClientResponseErrorHandler.java index 2271a1f5..9c4876d4 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/RestClientResponseErrorHandler.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/RestClientResponseErrorHandler.java @@ -17,16 +17,18 @@ * 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); diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/TwoWaySSLRestClient.java b/aai-rest/src/main/java/org/onap/aai/restclient/TwoWaySSLRestClient.java index dd5deaa6..a69977ff 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/TwoWaySSLRestClient.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/TwoWaySSLRestClient.java @@ -17,10 +17,20 @@ * 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()); diff --git a/aai-rest/src/test/java/org/onap/aai/restclient/RestClientTest.java b/aai-rest/src/test/java/org/onap/aai/restclient/RestClientTest.java index 4c3b0fcf..36b8fb3e 100644 --- a/aai-rest/src/test/java/org/onap/aai/restclient/RestClientTest.java +++ b/aai-rest/src/test/java/org/onap/aai/restclient/RestClientTest.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.restclient; public class RestClientTest { |