- do not create the ClientBuilder inside the classes but rather constructor inject it
- this way instrumentation of the client could be possible when tracing is enabled
Issue-ID: AAI-3817
Change-Id: I4c6d1faf8da98283e8bbae66bd0b3207786a4ce5
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
<parent>
<groupId>org.onap.aai.aai-common</groupId>
<artifactId>aai-parent</artifactId>
<parent>
<groupId>org.onap.aai.aai-common</groupId>
<artifactId>aai-parent</artifactId>
- <version>1.9.4</version>
+ <version>1.11.0</version>
</parent>
<groupId>org.onap.aai</groupId>
<artifactId>rest-client</artifactId>
</parent>
<groupId>org.onap.aai</groupId>
<artifactId>rest-client</artifactId>
- <version>1.9.0-SNAPSHOT</version>
+ <version>1.11.0-SNAPSHOT</version>
<name>aai-rest-client</name>
<properties>
<name>aai-rest-client</name>
<properties>
- <aai.common.version>1.9.3</aai.common.version>
<checkstyle.config.location>google_checks.xml</checkstyle.config.location>
<jacoco.report.directory>${project.build.directory}/code-coverage</jacoco.report.directory>
<jacoco.line.coverage.limit>0.80</jacoco.line.coverage.limit>
<checkstyle.config.location>google_checks.xml</checkstyle.config.location>
<jacoco.report.directory>${project.build.directory}/code-coverage</jacoco.report.directory>
<jacoco.line.coverage.limit>0.80</jacoco.line.coverage.limit>
import java.util.stream.Collectors;
import javax.ws.rs.client.Client;
import java.util.stream.Collectors;
import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
/**
* Creates a new instance of the {@link RestClient}.
*/
/**
* Creates a new instance of the {@link RestClient}.
*/
- public RestClient() {
- clientBuilder = new RestClientBuilder();
+ public RestClient(ClientBuilder builder) {
+ clientBuilder = new RestClientBuilder(builder);
private static final String KEYSTORE_TYPE = "PKCS12";\r
private static final String TRUST_STORE_PROPERTY = "javax.net.ssl.trustStore";\r
\r
private static final String KEYSTORE_TYPE = "PKCS12";\r
private static final String TRUST_STORE_PROPERTY = "javax.net.ssl.trustStore";\r
\r
+ private final ClientBuilder builder;\r
+\r
private boolean validateServerHostname;\r
private boolean validateServerCertChain;\r
private String clientCertFileName;\r
private boolean validateServerHostname;\r
private boolean validateServerCertChain;\r
private String clientCertFileName;\r
/**\r
* Rest Client Builder.\r
*/\r
/**\r
* Rest Client Builder.\r
*/\r
- public RestClientBuilder() {\r
+ public RestClientBuilder(ClientBuilder builder) {\r
+ this.builder = builder;\r
validateServerHostname = DEFAULT_VALIDATE_SERVER_HOST;\r
validateServerCertChain = DEFAULT_VALIDATE_CERT_CHAIN;\r
clientCertFileName = DEFAULT_CLIENT_CERT_FILENAME;\r
validateServerHostname = DEFAULT_VALIDATE_SERVER_HOST;\r
validateServerCertChain = DEFAULT_VALIDATE_CERT_CHAIN;\r
clientCertFileName = DEFAULT_CLIENT_CERT_FILENAME;\r
protected Client getClient(boolean useSsl) throws Exception {\r
\r
// Finally, create and initialize our client...\r
protected Client getClient(boolean useSsl) throws Exception {\r
\r
// Finally, create and initialize our client...\r
- ClientBuilder builder = ClientBuilder.newBuilder();\r
if (useSsl) {\r
setupSecureSocketLayerClientConfig(builder);\r
}\r
if (useSsl) {\r
setupSecureSocketLayerClientConfig(builder);\r
}\r
import javax.ws.rs.ProcessingException;
import javax.ws.rs.client.Client;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
private static final String TEST_URL = "http://localhost:9000/aai/v7";
private final MultivaluedMap<String, String> emptyMap = new MultivaluedHashMap<>();
private static final String TEST_URL = "http://localhost:9000/aai/v7";
private final MultivaluedMap<String, String> emptyMap = new MultivaluedHashMap<>();
+ private final ClientBuilder clientBuilder = ClientBuilder.newBuilder();
private RestClientBuilder mockClientBuilder;
private Client mockedClient;
private RestClientBuilder mockClientBuilder;
private Client mockedClient;
@Test
public void validateConstructors() {
@Test
public void validateConstructors() {
- RestClient restClient = new RestClient();
+ RestClient restClient = new RestClient(clientBuilder);
assertNotNull(restClient);
restClient = new RestClient(mockClientBuilder);
assertNotNull(restClient);
assertNotNull(restClient);
restClient = new RestClient(mockClientBuilder);
assertNotNull(restClient);
@Test
public void testGetClient() throws Exception {
@Test
public void testGetClient() throws Exception {
- RestClientBuilder restClientBuilder = new RestClientBuilder();
+ RestClientBuilder restClientBuilder = new RestClientBuilder(clientBuilder);
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_BASIC);
restClientBuilder.setTruststoreFilename("truststore");
assertTrue(restClientBuilder.getClient() instanceof Client);
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_BASIC);
restClientBuilder.setTruststoreFilename("truststore");
assertTrue(restClientBuilder.getClient() instanceof Client);
import static org.junit.Assert.assertTrue;\r
\r
import javax.ws.rs.client.Client;\r
import static org.junit.Assert.assertTrue;\r
\r
import javax.ws.rs.client.Client;\r
+import javax.ws.rs.client.ClientBuilder;\r
+\r
import org.junit.Before;\r
import org.junit.Test;\r
import org.onap.aai.restclient.enums.RestAuthenticationMode;\r
import org.junit.Before;\r
import org.junit.Test;\r
import org.onap.aai.restclient.enums.RestAuthenticationMode;\r
*/\r
public class RestClientBuilderTest {\r
\r
*/\r
public class RestClientBuilderTest {\r
\r
+ private final ClientBuilder clientBuilder = ClientBuilder.newBuilder();\r
+\r
/**\r
* Test case initialization\r
*\r
/**\r
* Test case initialization\r
*\r
@Test\r
public void validateAccesors() {\r
\r
@Test\r
public void validateAccesors() {\r
\r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder(clientBuilder);\r
\r
// test defaults\r
assertEquals(restClientBuilder.isValidateServerHostname(), RestClientBuilder.DEFAULT_VALIDATE_SERVER_HOST);\r
\r
// test defaults\r
assertEquals(restClientBuilder.isValidateServerHostname(), RestClientBuilder.DEFAULT_VALIDATE_SERVER_HOST);\r
@Test\r
public void validateNoAuthClientCreation() throws Exception {\r
\r
@Test\r
public void validateNoAuthClientCreation() throws Exception {\r
\r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder(clientBuilder);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.HTTP_NOAUTH);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.HTTP_NOAUTH);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
@Test\r
public void validateUnknownModeCreateNoAuthClient() throws Exception {\r
\r
@Test\r
public void validateUnknownModeCreateNoAuthClient() throws Exception {\r
\r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder(clientBuilder);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
@Test\r
public void validateBasicAuthSslClient() throws Exception {\r
\r
@Test\r
public void validateBasicAuthSslClient() throws Exception {\r
\r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder(clientBuilder);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_BASIC);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_BASIC);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
@Test(expected = IllegalArgumentException.class)\r
public void validateSslCertClient_noHostOrCertChainValidation() throws Exception {\r
\r
@Test(expected = IllegalArgumentException.class)\r
public void validateSslCertClient_noHostOrCertChainValidation() throws Exception {\r
\r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder(clientBuilder);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
@Test(expected = IllegalArgumentException.class)\r
public void validateSslCertClient_hostOnlyValidation() throws Exception {\r
\r
@Test(expected = IllegalArgumentException.class)\r
public void validateSslCertClient_hostOnlyValidation() throws Exception {\r
\r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder(clientBuilder);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
@Test\r
public void validateSslCertClient_certChainOnlyValidation() throws Exception {\r
\r
@Test\r
public void validateSslCertClient_certChainOnlyValidation() throws Exception {\r
\r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder(clientBuilder);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
@Test\r
public void validateSslCertClient_withHostAndCertChainValidation() throws Exception {\r
\r
@Test\r
public void validateSslCertClient_withHostAndCertChainValidation() throws Exception {\r
\r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder(clientBuilder);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
@Test(expected = IllegalArgumentException.class)\r
public void validateSslCertClient_illegalArgumentExceptionWhenTruststoreIsNull() throws Exception {\r
\r
@Test(expected = IllegalArgumentException.class)\r
public void validateSslCertClient_illegalArgumentExceptionWhenTruststoreIsNull() throws Exception {\r
\r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder(clientBuilder);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
\r
restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
restClientBuilder.setConnectTimeoutInMs(12345);\r
@Test\r
public void validateSslProtocolConfiguration() throws Exception {\r
\r
@Test\r
public void validateSslProtocolConfiguration() throws Exception {\r
\r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder(clientBuilder);\r
assertEquals(RestClientBuilder.DEFAULT_SSL_PROTOCOL, restClientBuilder.getSslProtocol());\r
\r
restClientBuilder.setSslProtocol("TLSv1.2");\r
assertEquals(RestClientBuilder.DEFAULT_SSL_PROTOCOL, restClientBuilder.getSslProtocol());\r
\r
restClientBuilder.setSslProtocol("TLSv1.2");\r
# because they are used in Jenkins, whose plug-in doesn't support
major=1
# because they are used in Jenkins, whose plug-in doesn't support
major=1
patch=0
base_version=${major}.${minor}.${patch}
patch=0
base_version=${major}.${minor}.${patch}