Skip to content

Commit

Permalink
Merge pull request #16 from ikyrannas/develop
Browse files Browse the repository at this point in the history
Add Lombok, refactor and remove vulnerable dependencies
  • Loading branch information
iskitsas authored Mar 31, 2021
2 parents d908a3f + 811c42c commit 95f0cb9
Show file tree
Hide file tree
Showing 60 changed files with 450 additions and 1,899 deletions.
5 changes: 5 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
<artifactId>spring-retry</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
108 changes: 54 additions & 54 deletions client/src/main/java/com/sastix/cms/client/impl/CmsClient.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.mockito.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -39,12 +37,15 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ActiveProfiles;

import lombok.extern.slf4j.Slf4j;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.IOException;
import java.net.URISyntaxException;

@Slf4j
@TestInstance(Lifecycle.PER_CLASS)
@SpringBootTest(classes = {CmsClient.class, CmsClient.class,VersionAPITest.class, RestTemplateConfiguration.class, ApiClientConfig.class},
properties = {
Expand All @@ -56,8 +57,6 @@

public class VersionAPITest {

private Logger LOG = (Logger) LoggerFactory.getLogger(VersionAPITest.class);

static VersionDTO TEST_VERSION = new VersionDTO()
.withMinVersion(1.0)
.withMaxVersion(1.0)
Expand All @@ -83,7 +82,7 @@ public void getApiVersion() {
VersionDTO apiVersion = cmsClient.getApiVersion();
assertEquals(apiVersion, TEST_VERSION, "DTO should be the same");

LOG.info("DTO returned by api call : {} ", apiVersion);
log.info("DTO returned by api call : {} ", apiVersion);
}
}

Expand Down
5 changes: 5 additions & 0 deletions common/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@
<artifactId>hazelcast-spring</artifactId>
<version>${hazelcast.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,50 @@

package com.sastix.cms.common.client;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.web.client.RequestCallback;
import org.springframework.web.client.ResponseExtractor;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import lombok.extern.slf4j.Slf4j;

import java.net.URI;
import java.util.Map;

/**
* Extension for RestTemplate to support retries transparently.
*/
@Slf4j
public class RetryRestTemplate extends RestTemplate {

private Logger LOG = (Logger) LoggerFactory.getLogger(RetryRestTemplate.class);

private RetryTemplate retryTemplate;

@Override
public <T> T execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Map<String, ?> urlVariables) throws RestClientException {
LOG.trace("Injecting execute(String, HttpMethod, RequestCallback, ResponseExtractor, Map) method. Applying retry template.");
log.trace("Injecting execute(String, HttpMethod, RequestCallback, ResponseExtractor, Map) method. Applying retry template.");
final long start = System.currentTimeMillis();
T t = retryTemplate.execute(retryContext -> super.execute(url, method, requestCallback, responseExtractor, urlVariables));
LOG.info("[API]:" + url + " took\t" + (System.currentTimeMillis() - start) + "ms");
log.info("[API]:" + url + " took\t" + (System.currentTimeMillis() - start) + "ms");
return t;
}

@Override
public <T> T execute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException {
LOG.trace("Injecting execute(URI, HttpMethod, RequestCallback, ResponseExtractor) method. Applying retry template.");
log.trace("Injecting execute(URI, HttpMethod, RequestCallback, ResponseExtractor) method. Applying retry template.");
final long start = System.currentTimeMillis();
T t = retryTemplate.execute(retryContext -> super.execute(url, method, requestCallback, responseExtractor));
LOG.info("[API]:" + url + " took\t" + (System.currentTimeMillis() - start) + "ms");
log.info("[API]:" + url + " took\t" + (System.currentTimeMillis() - start) + "ms");
return t;
}

@Override
public <T> T execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Object... urlVariables) throws RestClientException {
LOG.trace("Injecting execute(String, HttpMethod, RequestCallback, ResponseExtractor, Object) method. Applying retry template.");
log.trace("Injecting execute(String, HttpMethod, RequestCallback, ResponseExtractor, Object) method. Applying retry template.");
final long start = System.currentTimeMillis();
T t = retryTemplate.execute(retryContext -> super.execute(url, method, requestCallback, responseExtractor, urlVariables));
LOG.info("[API]:" + url + " took\t" + (System.currentTimeMillis() - start) + "ms");
log.info("[API]:" + url + " took\t" + (System.currentTimeMillis() - start) + "ms");
return t;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,28 @@

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.spring.cache.HazelcastCacheManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
@EnableCaching
@ConditionalOnBean(name = "hazelcastConfiguration")
public class CacheManagerConfiguration {

private Logger LOG = (Logger) LoggerFactory.getLogger(CacheManagerConfiguration.class);

@Autowired
@Qualifier(value = "hazelcastInstance")
HazelcastInstance hazelcastInstance;

@Bean
HazelcastCacheManager hazelcastcacheManager() throws Exception {
LOG.info("Hazelcast Instance was found. Configuring HazelcastCacheManager");
log.info("Hazelcast Instance was found. Configuring HazelcastCacheManager");
return new HazelcastCacheManager(hazelcastInstance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sastix.cms.common.dataobjects.RestErrorDTO;
import com.sastix.cms.common.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.client.*;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
Expand All @@ -37,11 +37,9 @@
/**
* RestTemplate Custom Exception Handler.
*/
@Slf4j
public class CommonExceptionHandler implements ResponseErrorHandler {

private Logger LOG = LoggerFactory
.getLogger(CommonExceptionHandler.class);

/**
* Json factory instance.
*/
Expand Down Expand Up @@ -115,13 +113,13 @@ public void handleError(ClientHttpResponse response) throws IOException, RestCli

try {
errorDTO = objectMapper.readValue(new String(responseBody, charset), RestErrorDTO.class);
LOG.error("Exception: " + errorDTO.toString());
log.error("Exception: " + errorDTO.toString());
} catch (final Exception e) {
//Wasn't able to map String on ErrorDTO.
//It is an Unknown Exception
//Throw Default Exception
final HttpClientErrorException clientErrorException = new HttpClientErrorException(statusCode, statusText, httpHeaders, responseBody, charset);
LOG.error("Unknown Exception: " + clientErrorException.getMessage());
log.error("Unknown Exception: " + clientErrorException.getMessage());
throw clientErrorException;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
import com.sastix.cms.common.client.ApiVersionClient;
import com.sastix.cms.common.client.RetryRestTemplate;
import com.sastix.cms.common.exception.VersionNotSupportedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;

public class ApiVersionClientImpl implements ApiVersionClient {
import lombok.extern.slf4j.Slf4j;

private Logger LOG = (Logger) LoggerFactory.getLogger(ApiVersionClient.class);
@Slf4j
public class ApiVersionClientImpl implements ApiVersionClient {

private String host;
private String port;
Expand Down Expand Up @@ -74,9 +73,9 @@ public ApiVersionClientImpl(final String host, final String port, final String a
@Override
public VersionDTO getApiVersion() {
String url = getUrlRoot() + "/" + Constants.GET_API_VERSION;
LOG.trace("API call: " + url);
log.trace("API call: " + url);
VersionDTO versionDTO = retryRestTemplate.getForObject(url, VersionDTO.class);
LOG.trace("Response: " + versionDTO.toString());
log.trace("Response: " + versionDTO.toString());
return versionDTO;
}

Expand Down
6 changes: 6 additions & 0 deletions common/dataobjects/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,11 @@
<version>2.0.1.Final</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.joda.time.DateTime;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.*;

/**
* The specific object holds all the information related to a CacheDTO.
*/
@Getter @Setter @NoArgsConstructor
public class CacheDTO implements Serializable {

/**
Expand Down Expand Up @@ -59,12 +64,6 @@ public class CacheDTO implements Serializable {
*/
DateTime cacheExpirationTime;

/**
* Default Constructor.
*/
public CacheDTO() {
}

/**
* Constructor with mandatory fields
*
Expand Down Expand Up @@ -132,34 +131,6 @@ public CacheDTO(String cacheKey, String cacheBlobURI) {
this.cacheBlobURI = cacheBlobURI;
}

/**
* Returns the cache key
*
* @return a String with the cache key
*/
public String getCacheKey() {
return cacheKey;
}

/**
* Set the cache key
*
* @param cacheKey
*/
public void setCacheKey(String cacheKey) {
this.cacheKey = cacheKey;
}

/**
* Returns the cache blob binary
*
* @return byte array of the blob
*/
public byte[] getCacheBlobBinary() {
return cacheBlobBinary;
}


/**
* A more generic method to retrieve the object directly from the carrier byte[]
*
Expand Down Expand Up @@ -193,67 +164,4 @@ public <T> T getCacheBlobBinaryObject() {
}
}

/**
* Set the cache blob binary
*
* @param cacheBlobBinary a byte array object
*/
public void setCacheBlobBinary(byte[] cacheBlobBinary) {
this.cacheBlobBinary = cacheBlobBinary;
}

/**
* Returns the uri of the cache blob
*
* @return a String with the uri
*/
public String getCacheBlobURI() {
return cacheBlobURI;
}

/**
* Set the uri of the blob to be cached
*
* @param cacheBlobURI a String with the uri
*/
public void setCacheBlobURI(String cacheBlobURI) {
this.cacheBlobURI = cacheBlobURI;
}

/**
* Returns the cache region
*
* @return a String with the cache region value
*/
public String getCacheRegion() {
return cacheRegion;
}

/**
* Set the cache region
*
* @param cacheRegion a String with the region
*/
public void setCacheRegion(String cacheRegion) {
this.cacheRegion = cacheRegion;
}

/**
* Returns the cache expiration time
*
* @return a DateTime with the cache expiration time
*/
public DateTime getCacheExpirationTime() {
return cacheExpirationTime;
}

/**
* Set the cache expiration time
*
* @param cacheExpirationTime a DateTime with the cache expiration time
*/
public void setCacheExpirationTime(DateTime cacheExpirationTime) {
this.cacheExpirationTime = cacheExpirationTime;
}
}

Loading

0 comments on commit 95f0cb9

Please sign in to comment.