mirror of
https://github.com/valitydev/hooker.git
synced 2024-11-06 00:05:17 +00:00
refactor deps, rm unused libs versions, reordered, apply checkstyle formatting (#142)
Co-authored-by: ElenaKushchenko <e.kushchenko@rbkmoney.com>
This commit is contained in:
parent
c31b6440bd
commit
ed4d71b23f
1
Jenkinsfile
vendored
1
Jenkinsfile
vendored
@ -11,7 +11,6 @@ build('hooker', 'java-maven') {
|
||||
def serviceName = env.REPO_NAME
|
||||
def mvnArgs = '-DjvmArgs="-Xmx256m"'
|
||||
def useJava11 = true
|
||||
def registry = 'dr2.rbkmoney.com'
|
||||
|
||||
javaServicePipeline(serviceName, useJava11, mvnArgs)
|
||||
}
|
||||
|
201
pom.xml
201
pom.xml
@ -21,7 +21,6 @@
|
||||
<server.port>8022</server.port>
|
||||
<management.port>8023</management.port>
|
||||
<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.registry>${env.REGISTRY}</dockerfile.registry>
|
||||
|
||||
@ -37,48 +36,6 @@
|
||||
</properties>
|
||||
|
||||
<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-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -94,23 +51,9 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</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>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
<version>${spring-kafka.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -135,21 +78,48 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</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-->
|
||||
<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>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>eventstock-client</artifactId>
|
||||
@ -160,38 +130,6 @@
|
||||
<artifactId>sink-common-lib</artifactId>
|
||||
<version>0.0.4</version>
|
||||
</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>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>machinegun-proto</artifactId>
|
||||
@ -204,9 +142,60 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>custom-actuator-endpoints</artifactId>
|
||||
<version>0.0.4</version>
|
||||
<artifactId>swag-webhook-events</artifactId>
|
||||
<version>1.89-39660bc-client</version>
|
||||
</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-->
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
@ -233,7 +222,6 @@
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>mockwebserver</artifactId>
|
||||
<version>3.14.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -251,7 +239,6 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.kafka</groupId>
|
||||
<artifactId>kafka-streams-test-utils</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -39,6 +39,8 @@ import java.util.Map;
|
||||
@RequiredArgsConstructor
|
||||
public class KafkaConfig {
|
||||
|
||||
private final KafkaSslProperties kafkaSslProperties;
|
||||
|
||||
@Value("${kafka.consumer.auto-offset-reset}")
|
||||
private String autoOffsetReset;
|
||||
@Value("${kafka.consumer.enable-auto-commit}")
|
||||
@ -49,7 +51,6 @@ public class KafkaConfig {
|
||||
private String clientId;
|
||||
@Value("${kafka.consumer.max-poll-records}")
|
||||
private int maxPollRecords;
|
||||
|
||||
@Value("${kafka.bootstrap-servers}")
|
||||
private String bootstrapServers;
|
||||
@Value("${kafka.topics.invoice.concurrency}")
|
||||
@ -57,8 +58,6 @@ public class KafkaConfig {
|
||||
@Value("${kafka.topics.customer.concurrency}")
|
||||
private int customerConcurrency;
|
||||
|
||||
private final KafkaSslProperties kafkaSslProperties;
|
||||
|
||||
@Bean
|
||||
public Map<String, Object> consumerConfigs() {
|
||||
Map<String, Object> props = new HashMap<>();
|
||||
|
@ -20,10 +20,9 @@ import java.util.stream.Collectors;
|
||||
@RequiredArgsConstructor
|
||||
public abstract class AbstractTaskDao implements TaskDao {
|
||||
|
||||
protected final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
public static RowMapper<Task> taskRowMapper = (rs, i) ->
|
||||
new Task(rs.getLong("message_id"), rs.getLong("queue_id"));
|
||||
protected final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
protected abstract String getMessageTopic();
|
||||
|
||||
|
@ -28,8 +28,6 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerDaoImpl implements CustomerDao {
|
||||
|
||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
public static final String ID = "id";
|
||||
public static final String EVENT_ID = "event_id";
|
||||
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_SHOP_ID = "customer_shop_id";
|
||||
public static final String BINDING_ID = "binding_id";
|
||||
|
||||
private static RowMapper<CustomerMessage> messageRowMapper = (rs, i) -> {
|
||||
CustomerMessage message = new CustomerMessage();
|
||||
message.setId(rs.getLong(ID));
|
||||
@ -57,6 +54,7 @@ public class CustomerDaoImpl implements CustomerDao {
|
||||
message.setBindingId(rs.getString(BINDING_ID));
|
||||
return message;
|
||||
};
|
||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
@Override
|
||||
public CustomerMessage getAny(String customerId, CustomerMessageEnum type) throws DaoException {
|
||||
|
@ -25,8 +25,6 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerQueueDao implements QueueDao<CustomerQueue> {
|
||||
|
||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
public static RowMapper<CustomerQueue> queueWithPolicyRowMapper = (rs, i) -> {
|
||||
CustomerQueue queue = new CustomerQueue();
|
||||
queue.setId(rs.getLong("id"));
|
||||
@ -45,6 +43,7 @@ public class CustomerQueueDao implements QueueDao<CustomerQueue> {
|
||||
queue.setRetryPolicyRecord(retryPolicyType.build(rs));
|
||||
return queue;
|
||||
};
|
||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
public void createWithPolicy(long messageId) throws DaoException {
|
||||
final String sql = "with queue as ( " +
|
||||
|
@ -36,6 +36,19 @@ import java.util.stream.Collectors;
|
||||
@RequiredArgsConstructor
|
||||
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 NamedParameterJdbcTemplate jdbcTemplate;
|
||||
private final PartyMetadataRowMapper partyMetadataRowMapper;
|
||||
@ -297,18 +310,4 @@ public class HookDaoImpl implements HookDao {
|
||||
}
|
||||
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")));
|
||||
}
|
||||
|
@ -42,11 +42,9 @@ import static com.rbkmoney.hooker.dao.impl.InvoicingMessageRowMapper.TYPE;
|
||||
@RequiredArgsConstructor
|
||||
public class InvoicingMessageDaoImpl implements InvoicingMessageDao {
|
||||
|
||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
private final Cache<InvoicingMessageKey, InvoicingMessage> invoicingCache;
|
||||
|
||||
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 {
|
||||
int[] batchMessagesResult = saveBatchMessages(messages);
|
||||
|
@ -23,8 +23,6 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class InvoicingQueueDao implements QueueDao<InvoicingQueue> {
|
||||
|
||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
public static RowMapper<InvoicingQueue> queueWithPolicyRowMapper = (rs, i) -> {
|
||||
InvoicingQueue queue = new InvoicingQueue();
|
||||
queue.setId(rs.getLong("id"));
|
||||
@ -43,6 +41,7 @@ public class InvoicingQueueDao implements QueueDao<InvoicingQueue> {
|
||||
queue.setRetryPolicyRecord(retryPolicyType.build(rs));
|
||||
return queue;
|
||||
};
|
||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
public int[] saveBatchWithPolicies(List<Long> messageIds) throws DaoException {
|
||||
final String sql = "with queue as ( " +
|
||||
|
@ -23,9 +23,8 @@ import java.io.IOException;
|
||||
@RequiredArgsConstructor
|
||||
public class WebhookManagerServlet extends GenericServlet {
|
||||
|
||||
private Servlet thriftServlet;
|
||||
|
||||
private final WebhookManagerSrv.Iface requestHandler;
|
||||
private Servlet thriftServlet;
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
|
@ -23,9 +23,8 @@ import java.io.IOException;
|
||||
@RequiredArgsConstructor
|
||||
public class WebhookMessageServiceServlet extends GenericServlet {
|
||||
|
||||
private Servlet thriftServlet;
|
||||
|
||||
private final WebhookMessageServiceSrv.Iface requestHandler;
|
||||
private Servlet thriftServlet;
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
|
@ -23,17 +23,13 @@ import org.springframework.stereotype.Component;
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerCreatedHandler extends AbstractCustomerEventHandler {
|
||||
|
||||
private final CustomerDaoImpl customerDao;
|
||||
private final CustomerQueueDao customerQueueDao;
|
||||
private final CustomerTaskDao customerTaskDao;
|
||||
private EventType eventType = EventType.CUSTOMER_CREATED;
|
||||
|
||||
private Filter filter =
|
||||
new PathConditionFilter(new PathConditionRule(eventType.getThriftPath(), new IsNullCondition().not()));
|
||||
|
||||
private final CustomerDaoImpl customerDao;
|
||||
|
||||
private final CustomerQueueDao customerQueueDao;
|
||||
|
||||
private final CustomerTaskDao customerTaskDao;
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return filter;
|
||||
|
@ -18,17 +18,14 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class AdjustmentStatusChangedMapper extends NeedReadInvoiceEventMapper {
|
||||
|
||||
private final HellgateInvoicingService<InvoicingMessage> invoicingEventService;
|
||||
|
||||
private static final EventType EVENT_TYPE = EventType.INVOICE_PAYMENT_STATUS_CHANGED;
|
||||
|
||||
private static final String ADJUSTMENT_STATUS_CHANGED_PATH = "invoice_payment_change.payload." +
|
||||
"invoice_payment_adjustment_change.payload.invoice_payment_adjustment_status_changed." +
|
||||
"status.captured";
|
||||
|
||||
private static final Filter FILTER = new PathConditionFilter(
|
||||
new PathConditionRule(ADJUSTMENT_STATUS_CHANGED_PATH, new IsNullCondition().not())
|
||||
);
|
||||
private final HellgateInvoicingService<InvoicingMessage> invoicingEventService;
|
||||
|
||||
public AdjustmentStatusChangedMapper(InvoicingMessageDao messageDao,
|
||||
HellgateInvoicingService<InvoicingMessage> invoicingEventService) {
|
||||
|
@ -29,73 +29,8 @@ import java.util.concurrent.TimeUnit;
|
||||
@Slf4j
|
||||
public final class HttpLoggingInterceptor implements Interceptor {
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
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 {
|
||||
void log(String message);
|
||||
|
||||
/**
|
||||
* A {@link Logger} defaults output appropriate for the current platform.
|
||||
*/
|
||||
Logger DEFAULT = log::info;
|
||||
}
|
||||
private final Logger logger;
|
||||
private volatile Level level = Level.BASIC;
|
||||
|
||||
public HttpLoggingInterceptor() {
|
||||
this(Logger.DEFAULT);
|
||||
@ -105,9 +40,33 @@ public final class HttpLoggingInterceptor implements Interceptor {
|
||||
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.
|
||||
@ -120,10 +79,6 @@ public final class HttpLoggingInterceptor implements Interceptor {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Level level = this.level;
|
||||
@ -255,33 +210,76 @@ public final class HttpLoggingInterceptor implements Interceptor {
|
||||
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) {
|
||||
String contentEncoding = headers.get("Content-Encoding");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,10 @@ public enum EventType {
|
||||
INVOICE_STATUS_CHANGED("invoice_status_changed"),
|
||||
INVOICE_PAYMENT_STARTED("invoice_payment_change.payload.invoice_payment_started"),
|
||||
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_STATUS_CHANGED("invoice_payment_change.payload.invoice_payment_refund_change.payload.invoice_payment_refund_status_changed"),
|
||||
INVOICE_PAYMENT_REFUND_STARTED(
|
||||
"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"),
|
||||
|
||||
CUSTOMER_CREATED("customer_created"),
|
||||
|
@ -15,10 +15,10 @@ import java.util.concurrent.TimeUnit;
|
||||
@Slf4j
|
||||
public class PostSender {
|
||||
|
||||
private final OkHttpClient httpClient;
|
||||
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
public static final String SIGNATURE_HEADER = "Content-Signature";
|
||||
public static final long RESPONSE_MAX_LENGTH = 4096L;
|
||||
private final OkHttpClient httpClient;
|
||||
|
||||
public PostSender(int connectionPoolSize, int timeout) {
|
||||
OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder();
|
||||
|
@ -23,7 +23,7 @@ public class WebhookMessageService implements WebhookMessageServiceSrv.Iface {
|
||||
private final CustomerTaskDao customerTaskDao;
|
||||
|
||||
@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);
|
||||
Hook hook = hookDao.getHookById(hookId);
|
||||
if (hook == null) {
|
||||
|
@ -1,12 +1,16 @@
|
||||
server:
|
||||
port: '@server.port@'
|
||||
|
||||
management:
|
||||
security:
|
||||
flag: false
|
||||
server:
|
||||
port: '@management.port@'
|
||||
metrics:
|
||||
export:
|
||||
statsd:
|
||||
flavor: etsy
|
||||
enabled: false
|
||||
prometheus:
|
||||
enabled: false
|
||||
endpoint:
|
||||
|
@ -27,6 +27,8 @@ public abstract class AbstractIntegrationTest {
|
||||
@ClassRule
|
||||
public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer("postgres:9.6")
|
||||
.withStartupTimeout(Duration.ofMinutes(5));
|
||||
@Value("${local.server.port}")
|
||||
protected int port;
|
||||
|
||||
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
@Override
|
||||
@ -43,7 +45,4 @@ public abstract class AbstractIntegrationTest {
|
||||
.applyTo(configurableApplicationContext);
|
||||
}
|
||||
}
|
||||
|
||||
@Value("${local.server.port}")
|
||||
protected int port;
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ public abstract class AbstractKafkaIntegrationTest {
|
||||
@ClassRule
|
||||
public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer("postgres:9.6")
|
||||
.withStartupTimeout(Duration.ofMinutes(5));
|
||||
@Value("${local.server.port}")
|
||||
protected int port;
|
||||
|
||||
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
@Override
|
||||
@ -59,7 +61,4 @@ public abstract class AbstractKafkaIntegrationTest {
|
||||
.applyTo(configurableApplicationContext);
|
||||
}
|
||||
}
|
||||
|
||||
@Value("${local.server.port}")
|
||||
protected int port;
|
||||
}
|
||||
|
@ -26,12 +26,10 @@ import static org.junit.Assert.assertEquals;
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class CustomerMessageDaoImplTest extends AbstractIntegrationTest {
|
||||
private static Logger log = LoggerFactory.getLogger(CustomerMessageDaoImplTest.class);
|
||||
|
||||
private static boolean messagesCreated = false;
|
||||
@Autowired
|
||||
CustomerDaoImpl messageDao;
|
||||
|
||||
private static boolean messagesCreated = false;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (!messagesCreated) {
|
||||
|
@ -37,13 +37,40 @@ import static org.junit.Assert.assertNull;
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class HookDaoImplTest extends AbstractIntegrationTest {
|
||||
|
||||
List<Long> ids = new ArrayList<>();
|
||||
@Autowired
|
||||
private NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
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
|
||||
public void setUp() throws Exception {
|
||||
@ -154,39 +181,10 @@ public class HookDaoImplTest extends AbstractIntegrationTest {
|
||||
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
|
||||
public void updateAvailabilityTest() {
|
||||
double availability = 0.1;
|
||||
hookDao.getPartyHooks("123").forEach(h -> hookDao.updateAvailability(h.getId(), availability));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -32,12 +32,10 @@ import static org.junit.Assert.assertEquals;
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class InvoicingMessageDaoImplTest extends AbstractIntegrationTest {
|
||||
private static Logger log = LoggerFactory.getLogger(InvoicingMessageDaoImplTest.class);
|
||||
|
||||
private static boolean messagesCreated = false;
|
||||
@Autowired
|
||||
InvoicingMessageDaoImpl messageDao;
|
||||
|
||||
private static boolean messagesCreated = false;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (!messagesCreated) {
|
||||
|
@ -55,12 +55,10 @@ public class InvoicingTaskDaoTest extends AbstractIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
InvoicingMessageDaoImpl messageDao;
|
||||
|
||||
@Autowired
|
||||
private TransactionTemplate transactionTemplate;
|
||||
|
||||
Long messageId;
|
||||
Long hookId;
|
||||
@Autowired
|
||||
private TransactionTemplate transactionTemplate;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
@ -53,6 +53,15 @@ public class KafkaMachineEventListenerKafkaTest extends AbstractKafkaIntegration
|
||||
@MockBean
|
||||
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
|
||||
public void listenInvoiceEmptyChanges() {
|
||||
Mockito.when(eventParser.parse(any())).thenReturn(EventPayload.invoice_changes(emptyList()));
|
||||
@ -99,13 +108,4 @@ public class KafkaMachineEventListenerKafkaTest extends AbstractKafkaIntegration
|
||||
message.setData(data);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -37,18 +37,6 @@ public class CustomerMachineEventHandlerTest extends AbstractIntegrationTest {
|
||||
@MockBean
|
||||
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() {
|
||||
MachineEvent machineEvent = new MachineEvent();
|
||||
machineEvent.setSourceId("sourceId-1");
|
||||
@ -89,6 +77,18 @@ public class CustomerMachineEventHandlerTest extends AbstractIntegrationTest {
|
||||
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 {
|
||||
|
||||
@Override
|
||||
|
@ -98,7 +98,7 @@ public class BatchProcessingTest extends AbstractIntegrationTest {
|
||||
storage.put(KeyUtils.key(invoiceCreated), invoiceCreated);
|
||||
|
||||
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 =
|
||||
handlerManager.getHandler(icPaymentStarted);
|
||||
assertTrue(eventMapperPaymentStartedOptional.isPresent());
|
||||
|
Loading…
Reference in New Issue
Block a user