Skip to content

Instantly share code, notes, and snippets.

View artemptushkin's full-sized avatar
:octocat:
Reducing complexity

Artem Ptushkin artemptushkin

:octocat:
Reducing complexity
View GitHub Profile
package io.github.aptushkin.proxy.image.filter
import org.springframework.cloud.gateway.filter.GatewayFilter
import org.springframework.cloud.gateway.filter.GatewayFilterChain
import org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter.ROUTE_TO_URL_FILTER_ORDER
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils
import org.springframework.core.Ordered
import org.springframework.web.server.ServerWebExchange
import reactor.core.publisher.Mono
@Component
class ProxyForwardGatewayFilterFactory:
AbstractGatewayFilterFactory<AbstractGatewayFilterFactory.NameConfig>(NameConfig::class.java) {
override fun apply(config: NameConfig): GatewayFilter = ProxyForwardGatewayFilter()
}
spring.cloud.gateway:
filters:
- name: ExampleFilter
args:
foo: "amazing"
baz: 1
spring:
cloud:
gateway:
routes:
- id: modify_image_router
uri: http://my-image-server.org
predicates:
- Path=/rotate
filters:
- name: RotateImage
spring:
cloud:
gateway:
default-filters:
- ProxyForward
routes:
- id: modify_image_router
uri: no://op
predicates:
- Path=/**
@artemptushkin
artemptushkin / .java
Last active May 25, 2020 09:40
Hibernate NPE on delete events
@Test
public void hibernate() throws Exception {
UUID id = fromString("b80db28f-2e4f-4d18-bb96-6bc5b9b387cb");
EntityManager entityManager = entityManagerProvider.get();
ObjectMapper objectMapper = new ObjectMapper();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
Maven Gradle
group-id project.group
artifact-id project.name
version project.version
@artemptushkin
artemptushkin / maven-gradle-scopes.csv
Last active October 29, 2020 19:45
The cheat-sheet table for maven-gradle relations. Read more https://dev.to/art_ptushkin/gradle-maven-scopes-cheat-sheet-4i56
Direct dependency Transitive dependency
Gradle configurations Maven scope Requirements Artifact inclusion Compile classpath Runtime classpath Test compile classpath Test runtime classpath Compile classpath Runtime classpath
implementation runtime yes + + + + +
api compile plugins: id 'java-library' yes + + + + + +
compile compile yes + + + + + +
compileOnly - no +
runtimeOnly runtime yes + + +
providedCompile provided plugins: id 'war' no + + + +
providedRuntime provided plugins: id 'war' no + +
testImplementation test no + +
@artemptushkin
artemptushkin / everon-consumer-pact.java
Last active December 8, 2020 16:52
The basic setup of pact consumer using `au.com.dius.pact.consumer:junit`
public class TariffClientPactTest {
@Rule
public PactProviderRule pactProviderRule = new PactProviderRule("billing", "localhost", 8080, this);
@Pact(provider = "billing", consumer = "transactions")
public RequestResponsePact itProvidesTariffPact(PactDslWithProvider pactDsl) {
return pactDsl
.given("tariff-for-transactions")
.uponReceiving("get tariff")
.path("/billing/tariffs/04974939-2630-4cb3-b2d0-baac27842172")
@artemptushkin
artemptushkin / everon-provider-pact.java
Last active December 11, 2020 19:13
The basic setup of pact provider using `au.com.dius.pact.provider:junit`
@RunWith(RestPactRunner.class)
@Provider("billing")
@PactBroker(consumerVersionSelectors = {
@VersionSelector(consumer = "transactions")
})
public class TariffProviderPactTest {
@Autowired
private TariffRepository tariffRepository;
@TestTarget
public final Target target = new HttpTarget("http", "localhost", 8080);