refactor deps, rm unused libs versions, reordered, apply checkstyle formatting (#142)

Co-authored-by: ElenaKushchenko <e.kushchenko@rbkmoney.com>
This commit is contained in:
Anatoly Karlov 2021-03-25 21:02:32 +07:00 committed by GitHub
parent c31b6440bd
commit ed4d71b23f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 285 additions and 323 deletions

1
Jenkinsfile vendored
View File

@ -11,7 +11,6 @@ build('hooker', 'java-maven') {
def serviceName = env.REPO_NAME def serviceName = env.REPO_NAME
def mvnArgs = '-DjvmArgs="-Xmx256m"' def mvnArgs = '-DjvmArgs="-Xmx256m"'
def useJava11 = true def useJava11 = true
def registry = 'dr2.rbkmoney.com'
javaServicePipeline(serviceName, useJava11, mvnArgs) javaServicePipeline(serviceName, useJava11, mvnArgs)
} }

201
pom.xml
View File

@ -21,7 +21,6 @@
<server.port>8022</server.port> <server.port>8022</server.port>
<management.port>8023</management.port> <management.port>8023</management.port>
<exposed.ports>${server.port} ${management.port}</exposed.ports> <exposed.ports>${server.port} ${management.port}</exposed.ports>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dockerfile.base.service.tag>c0612d6052ac049496b72a23a04acb142035f249</dockerfile.base.service.tag> <dockerfile.base.service.tag>c0612d6052ac049496b72a23a04acb142035f249</dockerfile.base.service.tag>
<dockerfile.registry>${env.REGISTRY}</dockerfile.registry> <dockerfile.registry>${env.REGISTRY}</dockerfile.registry>
@ -37,48 +36,6 @@
</properties> </properties>
<dependencies> <dependencies>
<!--Thirdparty libs-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.22</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${hikaricp.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.3</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flyway.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<!--Spring libs--> <!--Spring libs-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -94,23 +51,9 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>com.rbkmoney.woody</groupId>
<artifactId>woody-thrift</artifactId>
<version>1.1.18</version>
</dependency>
<dependency>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>common</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>filter</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.kafka</groupId> <groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId> <artifactId>spring-kafka</artifactId>
<version>${spring-kafka.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -135,21 +78,48 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId> <artifactId>spring-boot-starter-cache</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.3</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<!--RBK libs--> <!--RBK libs-->
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>damsel</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney.logback</groupId>
<artifactId>nop-rolling</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>shared-resources</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>serializer</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>kafka-common-lib</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>custom-metrics-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>custom-actuator-endpoints</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney.woody</groupId>
<artifactId>woody-thrift</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>common</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>filter</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.rbkmoney</groupId> <groupId>com.rbkmoney</groupId>
<artifactId>eventstock-client</artifactId> <artifactId>eventstock-client</artifactId>
@ -160,38 +130,6 @@
<artifactId>sink-common-lib</artifactId> <artifactId>sink-common-lib</artifactId>
<version>0.0.4</version> <version>0.0.4</version>
</dependency> </dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>damsel</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>swag-webhook-events</artifactId>
<version>1.89-39660bc-client</version>
</dependency>
<dependency>
<groupId>com.rbkmoney.logback</groupId>
<artifactId>nop-rolling</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>shared-resources</artifactId>
</dependency>
<dependency>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>serializer</artifactId>
<version>0.6.9</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>kafka-common-lib</artifactId>
<version>0.1.2</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>custom-metrics-spring-boot-starter</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.rbkmoney</groupId> <groupId>com.rbkmoney</groupId>
<artifactId>machinegun-proto</artifactId> <artifactId>machinegun-proto</artifactId>
@ -204,9 +142,60 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.rbkmoney</groupId> <groupId>com.rbkmoney</groupId>
<artifactId>custom-actuator-endpoints</artifactId> <artifactId>swag-webhook-events</artifactId>
<version>0.0.4</version> <version>1.89-39660bc-client</version>
</dependency> </dependency>
<!--Thirdparty libs-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.3</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<!--Test libs--> <!--Test libs-->
<dependency> <dependency>
<groupId>org.hamcrest</groupId> <groupId>org.hamcrest</groupId>
@ -233,7 +222,6 @@
<dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId> <groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId> <artifactId>mockwebserver</artifactId>
<version>3.14.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -251,7 +239,6 @@
<dependency> <dependency>
<groupId>org.apache.kafka</groupId> <groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams-test-utils</artifactId> <artifactId>kafka-streams-test-utils</artifactId>
<version>2.1.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -39,6 +39,8 @@ import java.util.Map;
@RequiredArgsConstructor @RequiredArgsConstructor
public class KafkaConfig { public class KafkaConfig {
private final KafkaSslProperties kafkaSslProperties;
@Value("${kafka.consumer.auto-offset-reset}") @Value("${kafka.consumer.auto-offset-reset}")
private String autoOffsetReset; private String autoOffsetReset;
@Value("${kafka.consumer.enable-auto-commit}") @Value("${kafka.consumer.enable-auto-commit}")
@ -49,7 +51,6 @@ public class KafkaConfig {
private String clientId; private String clientId;
@Value("${kafka.consumer.max-poll-records}") @Value("${kafka.consumer.max-poll-records}")
private int maxPollRecords; private int maxPollRecords;
@Value("${kafka.bootstrap-servers}") @Value("${kafka.bootstrap-servers}")
private String bootstrapServers; private String bootstrapServers;
@Value("${kafka.topics.invoice.concurrency}") @Value("${kafka.topics.invoice.concurrency}")
@ -57,8 +58,6 @@ public class KafkaConfig {
@Value("${kafka.topics.customer.concurrency}") @Value("${kafka.topics.customer.concurrency}")
private int customerConcurrency; private int customerConcurrency;
private final KafkaSslProperties kafkaSslProperties;
@Bean @Bean
public Map<String, Object> consumerConfigs() { public Map<String, Object> consumerConfigs() {
Map<String, Object> props = new HashMap<>(); Map<String, Object> props = new HashMap<>();

View File

@ -20,10 +20,9 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
public abstract class AbstractTaskDao implements TaskDao { public abstract class AbstractTaskDao implements TaskDao {
protected final NamedParameterJdbcTemplate jdbcTemplate;
public static RowMapper<Task> taskRowMapper = (rs, i) -> public static RowMapper<Task> taskRowMapper = (rs, i) ->
new Task(rs.getLong("message_id"), rs.getLong("queue_id")); new Task(rs.getLong("message_id"), rs.getLong("queue_id"));
protected final NamedParameterJdbcTemplate jdbcTemplate;
protected abstract String getMessageTopic(); protected abstract String getMessageTopic();

View File

@ -28,8 +28,6 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class CustomerDaoImpl implements CustomerDao { public class CustomerDaoImpl implements CustomerDao {
private final NamedParameterJdbcTemplate jdbcTemplate;
public static final String ID = "id"; public static final String ID = "id";
public static final String EVENT_ID = "event_id"; public static final String EVENT_ID = "event_id";
public static final String TYPE = "type"; public static final String TYPE = "type";
@ -41,7 +39,6 @@ public class CustomerDaoImpl implements CustomerDao {
public static final String CUSTOMER_ID = "customer_id"; public static final String CUSTOMER_ID = "customer_id";
public static final String CUSTOMER_SHOP_ID = "customer_shop_id"; public static final String CUSTOMER_SHOP_ID = "customer_shop_id";
public static final String BINDING_ID = "binding_id"; public static final String BINDING_ID = "binding_id";
private static RowMapper<CustomerMessage> messageRowMapper = (rs, i) -> { private static RowMapper<CustomerMessage> messageRowMapper = (rs, i) -> {
CustomerMessage message = new CustomerMessage(); CustomerMessage message = new CustomerMessage();
message.setId(rs.getLong(ID)); message.setId(rs.getLong(ID));
@ -57,6 +54,7 @@ public class CustomerDaoImpl implements CustomerDao {
message.setBindingId(rs.getString(BINDING_ID)); message.setBindingId(rs.getString(BINDING_ID));
return message; return message;
}; };
private final NamedParameterJdbcTemplate jdbcTemplate;
@Override @Override
public CustomerMessage getAny(String customerId, CustomerMessageEnum type) throws DaoException { public CustomerMessage getAny(String customerId, CustomerMessageEnum type) throws DaoException {

View File

@ -25,8 +25,6 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class CustomerQueueDao implements QueueDao<CustomerQueue> { public class CustomerQueueDao implements QueueDao<CustomerQueue> {
private final NamedParameterJdbcTemplate jdbcTemplate;
public static RowMapper<CustomerQueue> queueWithPolicyRowMapper = (rs, i) -> { public static RowMapper<CustomerQueue> queueWithPolicyRowMapper = (rs, i) -> {
CustomerQueue queue = new CustomerQueue(); CustomerQueue queue = new CustomerQueue();
queue.setId(rs.getLong("id")); queue.setId(rs.getLong("id"));
@ -45,6 +43,7 @@ public class CustomerQueueDao implements QueueDao<CustomerQueue> {
queue.setRetryPolicyRecord(retryPolicyType.build(rs)); queue.setRetryPolicyRecord(retryPolicyType.build(rs));
return queue; return queue;
}; };
private final NamedParameterJdbcTemplate jdbcTemplate;
public void createWithPolicy(long messageId) throws DaoException { public void createWithPolicy(long messageId) throws DaoException {
final String sql = "with queue as ( " + final String sql = "with queue as ( " +

View File

@ -36,6 +36,19 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
public class HookDaoImpl implements HookDao { public class HookDaoImpl implements HookDao {
private static RowMapper<AllHookTablesRow> allHookTablesRowRowMapper =
(rs, i) -> new AllHookTablesRow(rs.getLong("id"),
rs.getString("party_id"),
rs.getString("topic"),
rs.getString("url"),
rs.getString("pub_key"),
rs.getBoolean("enabled"),
rs.getDouble("availability"),
new WebhookAdditionalFilter(EventType.valueOf(rs.getString("event_type")),
rs.getString("invoice_shop_id"),
rs.getString("invoice_status"),
rs.getString("invoice_payment_status"),
rs.getString("invoice_payment_refund_status")));
private final Signer signer; private final Signer signer;
private final NamedParameterJdbcTemplate jdbcTemplate; private final NamedParameterJdbcTemplate jdbcTemplate;
private final PartyMetadataRowMapper partyMetadataRowMapper; private final PartyMetadataRowMapper partyMetadataRowMapper;
@ -297,18 +310,4 @@ public class HookDaoImpl implements HookDao {
} }
return pubKey; return pubKey;
} }
private static RowMapper<AllHookTablesRow> allHookTablesRowRowMapper =
(rs, i) -> new AllHookTablesRow(rs.getLong("id"),
rs.getString("party_id"),
rs.getString("topic"),
rs.getString("url"),
rs.getString("pub_key"),
rs.getBoolean("enabled"),
rs.getDouble("availability"),
new WebhookAdditionalFilter(EventType.valueOf(rs.getString("event_type")),
rs.getString("invoice_shop_id"),
rs.getString("invoice_status"),
rs.getString("invoice_payment_status"),
rs.getString("invoice_payment_refund_status")));
} }

View File

@ -42,11 +42,9 @@ import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.TYPE;
@RequiredArgsConstructor @RequiredArgsConstructor
public class InvoicingMessageDaoImpl implements InvoicingMessageDao { public class InvoicingMessageDaoImpl implements InvoicingMessageDao {
private final NamedParameterJdbcTemplate jdbcTemplate;
private final Cache<InvoicingMessageKey, InvoicingMessage> invoicingCache;
private static RowMapper<InvoicingMessage> messageRowMapper = new InvoicingMessageRowMapper(); private static RowMapper<InvoicingMessage> messageRowMapper = new InvoicingMessageRowMapper();
private final NamedParameterJdbcTemplate jdbcTemplate;
private final Cache<InvoicingMessageKey, InvoicingMessage> invoicingCache;
public void saveBatch(List<InvoicingMessage> messages) throws DaoException { public void saveBatch(List<InvoicingMessage> messages) throws DaoException {
int[] batchMessagesResult = saveBatchMessages(messages); int[] batchMessagesResult = saveBatchMessages(messages);

View File

@ -23,8 +23,6 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class InvoicingQueueDao implements QueueDao<InvoicingQueue> { public class InvoicingQueueDao implements QueueDao<InvoicingQueue> {
private final NamedParameterJdbcTemplate jdbcTemplate;
public static RowMapper<InvoicingQueue> queueWithPolicyRowMapper = (rs, i) -> { public static RowMapper<InvoicingQueue> queueWithPolicyRowMapper = (rs, i) -> {
InvoicingQueue queue = new InvoicingQueue(); InvoicingQueue queue = new InvoicingQueue();
queue.setId(rs.getLong("id")); queue.setId(rs.getLong("id"));
@ -43,6 +41,7 @@ public class InvoicingQueueDao implements QueueDao<InvoicingQueue> {
queue.setRetryPolicyRecord(retryPolicyType.build(rs)); queue.setRetryPolicyRecord(retryPolicyType.build(rs));
return queue; return queue;
}; };
private final NamedParameterJdbcTemplate jdbcTemplate;
public int[] saveBatchWithPolicies(List<Long> messageIds) throws DaoException { public int[] saveBatchWithPolicies(List<Long> messageIds) throws DaoException {
final String sql = "with queue as ( " + final String sql = "with queue as ( " +

View File

@ -23,9 +23,8 @@ import java.io.IOException;
@RequiredArgsConstructor @RequiredArgsConstructor
public class WebhookManagerServlet extends GenericServlet { public class WebhookManagerServlet extends GenericServlet {
private Servlet thriftServlet;
private final WebhookManagerSrv.Iface requestHandler; private final WebhookManagerSrv.Iface requestHandler;
private Servlet thriftServlet;
@Override @Override
public void init(ServletConfig config) throws ServletException { public void init(ServletConfig config) throws ServletException {

View File

@ -23,9 +23,8 @@ import java.io.IOException;
@RequiredArgsConstructor @RequiredArgsConstructor
public class WebhookMessageServiceServlet extends GenericServlet { public class WebhookMessageServiceServlet extends GenericServlet {
private Servlet thriftServlet;
private final WebhookMessageServiceSrv.Iface requestHandler; private final WebhookMessageServiceSrv.Iface requestHandler;
private Servlet thriftServlet;
@Override @Override
public void init(ServletConfig config) throws ServletException { public void init(ServletConfig config) throws ServletException {

View File

@ -23,17 +23,13 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor @RequiredArgsConstructor
public class CustomerCreatedHandler extends AbstractCustomerEventHandler { public class CustomerCreatedHandler extends AbstractCustomerEventHandler {
private final CustomerDaoImpl customerDao;
private final CustomerQueueDao customerQueueDao;
private final CustomerTaskDao customerTaskDao;
private EventType eventType = EventType.CUSTOMER_CREATED; private EventType eventType = EventType.CUSTOMER_CREATED;
private Filter filter = private Filter filter =
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not())); new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
private final CustomerDaoImpl customerDao;
private final CustomerQueueDao customerQueueDao;
private final CustomerTaskDao customerTaskDao;
@Override @Override
public Filter getFilter() { public Filter getFilter() {
return filter; return filter;

View File

@ -18,17 +18,14 @@ import org.springframework.stereotype.Component;
@Component @Component
public class AdjustmentStatusChangedMapper extends NeedReadInvoiceEventMapper { public class AdjustmentStatusChangedMapper extends NeedReadInvoiceEventMapper {
private final HellgateInvoicingService<InvoicingMessage> invoicingEventService;
private static final EventType EVENT_TYPE = EventType.INVOICE_PAYMENT_STATUS_CHANGED; private static final EventType EVENT_TYPE = EventType.INVOICE_PAYMENT_STATUS_CHANGED;
private static final String ADJUSTMENT_STATUS_CHANGED_PATH = "invoice_payment_change.payload." + private static final String ADJUSTMENT_STATUS_CHANGED_PATH = "invoice_payment_change.payload." +
"invoice_payment_adjustment_change.payload.invoice_payment_adjustment_status_changed." + "invoice_payment_adjustment_change.payload.invoice_payment_adjustment_status_changed." +
"status.captured"; "status.captured";
private static final Filter FILTER = new PathConditionFilter( private static final Filter FILTER = new PathConditionFilter(
new PathConditionRule(ADJUSTMENT_STATUS_CHANGED_PATH, new IsNullCondition().not()) new PathConditionRule(ADJUSTMENT_STATUS_CHANGED_PATH, new IsNullCondition().not())
); );
private final HellgateInvoicingService<InvoicingMessage> invoicingEventService;
public AdjustmentStatusChangedMapper(InvoicingMessageDao messageDao, public AdjustmentStatusChangedMapper(InvoicingMessageDao messageDao,
HellgateInvoicingService<InvoicingMessage> invoicingEventService) { HellgateInvoicingService<InvoicingMessage> invoicingEventService) {

View File

@ -29,73 +29,8 @@ import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
public final class HttpLoggingInterceptor implements Interceptor { public final class HttpLoggingInterceptor implements Interceptor {
private static final Charset UTF8 = Charset.forName("UTF-8"); private static final Charset UTF8 = Charset.forName("UTF-8");
private final Logger logger;
public enum Level { private volatile Level level = Level.BASIC;
/**
* No logs.
*/
NONE,
/**
* Logs request and response lines.
* <p>
* <p>Example:
* <pre>{@code
* --> POST /greeting http/1.1 (3-byte body)
*
* <-- 200 OK (22ms, 6-byte body)
* }</pre>
*/
BASIC,
/**
* Logs request and response lines and their respective headers.
* <p>
* <p>Example:
* <pre>{@code
* --> POST /greeting http/1.1
* Host: example.com
* Content-Type: plain/text
* Content-Length: 3
* --> END POST
*
* <-- 200 OK (22ms)
* Content-Type: plain/text
* Content-Length: 6
* <-- END HTTP
* }</pre>
*/
HEADERS,
/**
* Logs request and response lines and their respective headers and bodies (if present).
* <p>
* <p>Example:
* <pre>{@code
* --> POST /greeting http/1.1
* Host: example.com
* Content-Type: plain/text
* Content-Length: 3
*
* Hi?
* --> END POST
*
* <-- 200 OK (22ms)
* Content-Type: plain/text
* Content-Length: 6
*
* Hello!
* <-- END HTTP
* }</pre>
*/
BODY
}
public interface Logger {
void log(String message);
/**
* A {@link Logger} defaults output appropriate for the current platform.
*/
Logger DEFAULT = log::info;
}
public HttpLoggingInterceptor() { public HttpLoggingInterceptor() {
this(Logger.DEFAULT); this(Logger.DEFAULT);
@ -105,9 +40,33 @@ public final class HttpLoggingInterceptor implements Interceptor {
this.logger = logger; this.logger = logger;
} }
private final Logger logger; /**
* Returns true if the body in question probably contains human readable text. Uses a small sample
* of code points to detect unicode control characters commonly used in binary file signatures.
*/
static boolean isPlaintext(Buffer buffer) {
try {
Buffer prefix = new Buffer();
long byteCount = buffer.size() < 64 ? buffer.size() : 64;
buffer.copyTo(prefix, 0, byteCount);
for (int i = 0; i < 16; i++) {
if (prefix.exhausted()) {
break;
}
int codePoint = prefix.readUtf8CodePoint();
if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) {
return false;
}
}
return true;
} catch (EOFException e) {
return false; // Truncated UTF-8 sequence.
}
}
private volatile Level level = Level.BASIC; public Level getLevel() {
return level;
}
/** /**
* Change the level at which this interceptor logs. * Change the level at which this interceptor logs.
@ -120,10 +79,6 @@ public final class HttpLoggingInterceptor implements Interceptor {
return this; return this;
} }
public Level getLevel() {
return level;
}
@Override @Override
public Response intercept(Chain chain) throws IOException { public Response intercept(Chain chain) throws IOException {
Level level = this.level; Level level = this.level;
@ -255,33 +210,76 @@ public final class HttpLoggingInterceptor implements Interceptor {
return response; return response;
} }
/**
* Returns true if the body in question probably contains human readable text. Uses a small sample
* of code points to detect unicode control characters commonly used in binary file signatures.
*/
static boolean isPlaintext(Buffer buffer) {
try {
Buffer prefix = new Buffer();
long byteCount = buffer.size() < 64 ? buffer.size() : 64;
buffer.copyTo(prefix, 0, byteCount);
for (int i = 0; i < 16; i++) {
if (prefix.exhausted()) {
break;
}
int codePoint = prefix.readUtf8CodePoint();
if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) {
return false;
}
}
return true;
} catch (EOFException e) {
return false; // Truncated UTF-8 sequence.
}
}
private boolean bodyEncoded(Headers headers) { private boolean bodyEncoded(Headers headers) {
String contentEncoding = headers.get("Content-Encoding"); String contentEncoding = headers.get("Content-Encoding");
return contentEncoding != null && !contentEncoding.equalsIgnoreCase("identity"); return contentEncoding != null && !contentEncoding.equalsIgnoreCase("identity");
} }
public enum Level {
/**
* No logs.
*/
NONE,
/**
* Logs request and response lines.
* <p>
* <p>Example:
* <pre>{@code
* --> POST /greeting http/1.1 (3-byte body)
*
* <-- 200 OK (22ms, 6-byte body)
* }</pre>
*/
BASIC,
/**
* Logs request and response lines and their respective headers.
* <p>
* <p>Example:
* <pre>{@code
* --> POST /greeting http/1.1
* Host: example.com
* Content-Type: plain/text
* Content-Length: 3
* --> END POST
*
* <-- 200 OK (22ms)
* Content-Type: plain/text
* Content-Length: 6
* <-- END HTTP
* }</pre>
*/
HEADERS,
/**
* Logs request and response lines and their respective headers and bodies (if present).
* <p>
* <p>Example:
* <pre>{@code
* --> POST /greeting http/1.1
* Host: example.com
* Content-Type: plain/text
* Content-Length: 3
*
* Hi?
* --> END POST
*
* <-- 200 OK (22ms)
* Content-Type: plain/text
* Content-Length: 6
*
* Hello!
* <-- END HTTP
* }</pre>
*/
BODY
}
public interface Logger {
/**
* A {@link Logger} defaults output appropriate for the current platform.
*/
Logger DEFAULT = log::info;
void log(String message);
}
} }

View File

@ -11,8 +11,10 @@ public enum EventType {
INVOICE_STATUS_CHANGED("invoice_status_changed"), INVOICE_STATUS_CHANGED("invoice_status_changed"),
INVOICE_PAYMENT_STARTED("invoice_payment_change.payload.invoice_payment_started"), INVOICE_PAYMENT_STARTED("invoice_payment_change.payload.invoice_payment_started"),
INVOICE_PAYMENT_STATUS_CHANGED("invoice_payment_change.payload.invoice_payment_status_changed"), INVOICE_PAYMENT_STATUS_CHANGED("invoice_payment_change.payload.invoice_payment_status_changed"),
INVOICE_PAYMENT_REFUND_STARTED("invoice_payment_change.payload.invoice_payment_refund_change.payload.invoice_payment_refund_created"), INVOICE_PAYMENT_REFUND_STARTED(
INVOICE_PAYMENT_REFUND_STATUS_CHANGED("invoice_payment_change.payload.invoice_payment_refund_change.payload.invoice_payment_refund_status_changed"), "invoice_payment_change.payload.invoice_payment_refund_change.payload.invoice_payment_refund_created"),
INVOICE_PAYMENT_REFUND_STATUS_CHANGED(
"invoice_payment_change.payload.invoice_payment_refund_change.payload.invoice_payment_refund_status_changed"),
INVOICE_PAYMENT_CASH_FLOW_CHANGED("invoice_payment_change.payload.invoice_payment_cash_flow_changed"), INVOICE_PAYMENT_CASH_FLOW_CHANGED("invoice_payment_change.payload.invoice_payment_cash_flow_changed"),
CUSTOMER_CREATED("customer_created"), CUSTOMER_CREATED("customer_created"),

View File

@ -15,10 +15,10 @@ import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
public class PostSender { public class PostSender {
private final OkHttpClient httpClient;
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public static final String SIGNATURE_HEADER = "Content-Signature"; public static final String SIGNATURE_HEADER = "Content-Signature";
public static final long RESPONSE_MAX_LENGTH = 4096L; public static final long RESPONSE_MAX_LENGTH = 4096L;
private final OkHttpClient httpClient;
public PostSender(int connectionPoolSize, int timeout) { public PostSender(int connectionPoolSize, int timeout) {
OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder(); OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder();

View File

@ -23,7 +23,7 @@ public class WebhookMessageService implements WebhookMessageServiceSrv.Iface {
private final CustomerTaskDao customerTaskDao; private final CustomerTaskDao customerTaskDao;
@Override @Override
public void send(long hookId, String sourceId) throws WebhookNotFound, SourceNotFound, TException { public void send(long hookId, String sourceId) throws TException {
log.info("Start creating tasks for sending hooks for hookId={}, invoiceId={}", hookId, sourceId); log.info("Start creating tasks for sending hooks for hookId={}, invoiceId={}", hookId, sourceId);
Hook hook = hookDao.getHookById(hookId); Hook hook = hookDao.getHookById(hookId);
if (hook == null) { if (hook == null) {

View File

@ -1,12 +1,16 @@
server: server:
port: '@server.port@' port: '@server.port@'
management: management:
security:
flag: false
server: server:
port: '@management.port@' port: '@management.port@'
metrics: metrics:
export: export:
statsd: statsd:
flavor: etsy flavor: etsy
enabled: false
prometheus: prometheus:
enabled: false enabled: false
endpoint: endpoint:

View File

@ -27,6 +27,8 @@ public abstract class AbstractIntegrationTest {
@ClassRule @ClassRule
public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer("postgres:9.6") public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer("postgres:9.6")
.withStartupTimeout(Duration.ofMinutes(5)); .withStartupTimeout(Duration.ofMinutes(5));
@Value("${local.server.port}")
protected int port;
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override @Override
@ -43,7 +45,4 @@ public abstract class AbstractIntegrationTest {
.applyTo(configurableApplicationContext); .applyTo(configurableApplicationContext);
} }
} }
@Value("${local.server.port}")
protected int port;
} }

View File

@ -35,6 +35,8 @@ public abstract class AbstractKafkaIntegrationTest {
@ClassRule @ClassRule
public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer("postgres:9.6") public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer("postgres:9.6")
.withStartupTimeout(Duration.ofMinutes(5)); .withStartupTimeout(Duration.ofMinutes(5));
@Value("${local.server.port}")
protected int port;
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override @Override
@ -59,7 +61,4 @@ public abstract class AbstractKafkaIntegrationTest {
.applyTo(configurableApplicationContext); .applyTo(configurableApplicationContext);
} }
} }
@Value("${local.server.port}")
protected int port;
} }

View File

@ -26,12 +26,10 @@ import static org.junit.Assert.assertEquals;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class CustomerMessageDaoImplTest extends AbstractIntegrationTest { public class CustomerMessageDaoImplTest extends AbstractIntegrationTest {
private static Logger log = LoggerFactory.getLogger(CustomerMessageDaoImplTest.class); private static Logger log = LoggerFactory.getLogger(CustomerMessageDaoImplTest.class);
private static boolean messagesCreated = false;
@Autowired @Autowired
CustomerDaoImpl messageDao; CustomerDaoImpl messageDao;
private static boolean messagesCreated = false;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
if (!messagesCreated) { if (!messagesCreated) {

View File

@ -37,13 +37,40 @@ import static org.junit.Assert.assertNull;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class HookDaoImplTest extends AbstractIntegrationTest { public class HookDaoImplTest extends AbstractIntegrationTest {
List<Long> ids = new ArrayList<>();
@Autowired @Autowired
private NamedParameterJdbcTemplate jdbcTemplate; private NamedParameterJdbcTemplate jdbcTemplate;
@Autowired @Autowired
private HookDao hookDao; private HookDao hookDao;
List<Long> ids = new ArrayList<>(); public static Hook buildHook(String partyId, String url) {
Hook hook = new Hook();
hook.setPartyId(partyId);
hook.setUrl(url);
hook.setTopic(Event.TopicEnum.INVOICESTOPIC.getValue());
Set<WebhookAdditionalFilter> webhookAdditionalFilters = new HashSet<>();
webhookAdditionalFilters
.add(new WebhookAdditionalFilter(EventType.INVOICE_PAYMENT_STATUS_CHANGED, "34", null, "cancelled",
"failed"));
webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_CREATED).build());
hook.setFilters(webhookAdditionalFilters);
return hook;
}
public static Hook buildCustomerHook(String partyId, String url) {
Hook hook = new Hook();
hook.setPartyId(partyId);
hook.setUrl(url);
hook.setTopic(Event.TopicEnum.CUSTOMERSTOPIC.getValue());
Set<WebhookAdditionalFilter> webhookAdditionalFilters = new HashSet<>();
webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_CREATED).build());
hook.setFilters(webhookAdditionalFilters);
return hook;
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -154,39 +181,10 @@ public class HookDaoImplTest extends AbstractIntegrationTest {
assertEquals(0, hookDao.getPartyHooksCount("keke")); assertEquals(0, hookDao.getPartyHooksCount("keke"));
} }
public static Hook buildHook(String partyId, String url) {
Hook hook = new Hook();
hook.setPartyId(partyId);
hook.setUrl(url);
hook.setTopic(Event.TopicEnum.INVOICESTOPIC.getValue());
Set<WebhookAdditionalFilter> webhookAdditionalFilters = new HashSet<>();
webhookAdditionalFilters
.add(new WebhookAdditionalFilter(EventType.INVOICE_PAYMENT_STATUS_CHANGED, "34", null, "cancelled",
"failed"));
webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.INVOICE_CREATED).build());
hook.setFilters(webhookAdditionalFilters);
return hook;
}
@Test @Test
public void updateAvailabilityTest() { public void updateAvailabilityTest() {
double availability = 0.1; double availability = 0.1;
hookDao.getPartyHooks("123").forEach(h -> hookDao.updateAvailability(h.getId(), availability)); hookDao.getPartyHooks("123").forEach(h -> hookDao.updateAvailability(h.getId(), availability));
hookDao.getPartyHooks("123").forEach(h -> assertEquals(availability, h.getAvailability(), 0.000000000001)); hookDao.getPartyHooks("123").forEach(h -> assertEquals(availability, h.getAvailability(), 0.000000000001));
} }
public static Hook buildCustomerHook(String partyId, String url) {
Hook hook = new Hook();
hook.setPartyId(partyId);
hook.setUrl(url);
hook.setTopic(Event.TopicEnum.CUSTOMERSTOPIC.getValue());
Set<WebhookAdditionalFilter> webhookAdditionalFilters = new HashSet<>();
webhookAdditionalFilters.add(WebhookAdditionalFilter.builder().eventType(EventType.CUSTOMER_CREATED).build());
hook.setFilters(webhookAdditionalFilters);
return hook;
}
} }

View File

@ -32,12 +32,10 @@ import static org.junit.Assert.assertEquals;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class InvoicingMessageDaoImplTest extends AbstractIntegrationTest { public class InvoicingMessageDaoImplTest extends AbstractIntegrationTest {
private static Logger log = LoggerFactory.getLogger(InvoicingMessageDaoImplTest.class); private static Logger log = LoggerFactory.getLogger(InvoicingMessageDaoImplTest.class);
private static boolean messagesCreated = false;
@Autowired @Autowired
InvoicingMessageDaoImpl messageDao; InvoicingMessageDaoImpl messageDao;
private static boolean messagesCreated = false;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
if (!messagesCreated) { if (!messagesCreated) {

View File

@ -55,12 +55,10 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
@Autowired @Autowired
InvoicingMessageDaoImpl messageDao; InvoicingMessageDaoImpl messageDao;
@Autowired
private TransactionTemplate transactionTemplate;
Long messageId; Long messageId;
Long hookId; Long hookId;
@Autowired
private TransactionTemplate transactionTemplate;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {

View File

@ -53,6 +53,15 @@ public class KafkaMachineEventListenerKafkaTest extends AbstractKafkaIntegration
@MockBean @MockBean
private MachineEventParser<EventPayload> eventParser; private MachineEventParser<EventPayload> eventParser;
public static Producer<String, SinkEvent> createProducer() {
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers());
props.put(ProducerConfig.CLIENT_ID_CONFIG, "client_id");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, new ThriftSerializer<SinkEvent>().getClass());
return new KafkaProducer<>(props);
}
@Test @Test
public void listenInvoiceEmptyChanges() { public void listenInvoiceEmptyChanges() {
Mockito.when(eventParser.parse(any())).thenReturn(EventPayload.invoice_changes(emptyList())); Mockito.when(eventParser.parse(any())).thenReturn(EventPayload.invoice_changes(emptyList()));
@ -99,13 +108,4 @@ public class KafkaMachineEventListenerKafkaTest extends AbstractKafkaIntegration
message.setData(data); message.setData(data);
return message; return message;
} }
public static Producer<String, SinkEvent> createProducer() {
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers());
props.put(ProducerConfig.CLIENT_ID_CONFIG, "client_id");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, new ThriftSerializer<SinkEvent>().getClass());
return new KafkaProducer<>(props);
}
} }

View File

@ -37,18 +37,6 @@ public class CustomerMachineEventHandlerTest extends AbstractIntegrationTest {
@MockBean @MockBean
private MachineEventParser<EventPayload> paymentEventPayloadMachineEventParser; private MachineEventParser<EventPayload> paymentEventPayloadMachineEventParser;
@Test
public void saveEventTest() {
String customerId = "CID";
MachineEvent machineEvent = createTestMachineEvent();
Mockito.when(paymentEventPayloadMachineEventParser.parse(any(MachineEvent.class)))
.thenReturn(createTestCusomerEventPayload(customerId));
customerMachineEventHandler.handle(Arrays.asList(machineEvent), new TestAcknowledgment());
CustomerMessage message = customerDao.getAny(customerId, CustomerMessageEnum.CUSTOMER);
assertTrue("The message should not be empty", message != null);
}
private static MachineEvent createTestMachineEvent() { private static MachineEvent createTestMachineEvent() {
MachineEvent machineEvent = new MachineEvent(); MachineEvent machineEvent = new MachineEvent();
machineEvent.setSourceId("sourceId-1"); machineEvent.setSourceId("sourceId-1");
@ -89,6 +77,18 @@ public class CustomerMachineEventHandlerTest extends AbstractIntegrationTest {
return changes; return changes;
} }
@Test
public void saveEventTest() {
String customerId = "CID";
MachineEvent machineEvent = createTestMachineEvent();
Mockito.when(paymentEventPayloadMachineEventParser.parse(any(MachineEvent.class)))
.thenReturn(createTestCusomerEventPayload(customerId));
customerMachineEventHandler.handle(Arrays.asList(machineEvent), new TestAcknowledgment());
CustomerMessage message = customerDao.getAny(customerId, CustomerMessageEnum.CUSTOMER);
assertTrue("The message should not be empty", message != null);
}
private static class TestAcknowledgment implements Acknowledgment { private static class TestAcknowledgment implements Acknowledgment {
@Override @Override

View File

@ -98,7 +98,7 @@ public class BatchProcessingTest extends AbstractIntegrationTest {
storage.put(KeyUtils.key(invoiceCreated), invoiceCreated); storage.put(KeyUtils.key(invoiceCreated), invoiceCreated);
InvoiceChange icPaymentStarted = getInvoicePaymentStarted(); InvoiceChange icPaymentStarted = getInvoicePaymentStarted();
EventInfo eventInfoPaymentStarted = new EventInfo(null, "2016-03-22T06:12:27Z", "invoiceId",1L,2); EventInfo eventInfoPaymentStarted = new EventInfo(null, "2016-03-22T06:12:27Z", "invoiceId", 1L, 2);
Optional<AbstractInvoiceEventMapper> eventMapperPaymentStartedOptional = Optional<AbstractInvoiceEventMapper> eventMapperPaymentStartedOptional =
handlerManager.getHandler(icPaymentStarted); handlerManager.getHandler(icPaymentStarted);
assertTrue(eventMapperPaymentStartedOptional.isPresent()); assertTrue(eventMapperPaymentStartedOptional.isPresent());