Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generic routing handler #26

Merged
merged 19 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- 'release/**'
- 'feature/**'

jobs:
build:
Expand Down
11 changes: 11 additions & 0 deletions REALSENOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Release notes
## 1.0.15
* Upgrade to Spring-Boot 2.7.1
* Modified GitHub Action to build maven snapshots on published features
* RoutingHandler Refactoring
* Added generic RoutingHandler.handleGenericRequestInternal() to handle GET and POST via Spring RestTemplate including the request body. Legacy RoutingHandler logic is deprecated.
* Rearranged helper bean initialization to configuration
* switched to null checks on http proxy properties
* Added spring-boot-starter-test and hamcrest-all test dependencies
* Moved from org.junit to org.junit.jupiter.api
* Implemented more tests
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,15 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/*--- (C) 1999-2019 Techniker Krankenkasse ---*/
/*--- (C) 1999-2021 Techniker Krankenkasse ---*/

package de.tk.opensource.privacyproxy.config;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.Collections;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
Expand All @@ -22,32 +19,19 @@
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.retry.listener.RetryListenerSupport;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.StringUtils;

@Configuration
@Configuration("PrivacyProxyConfig")
@EnableCaching
@EnableConfigurationProperties
@EnableRetry
@EnableScheduling
public class PrivacyProxyConfig {
public class ApplicationConfig {

@Bean
public ConversionService conversionService() {
return new DefaultConversionService();
}

@Bean
public Proxy proxy(
@Value("${http.proxyHost:''}") String proxyHost,
@Value("${http.proxyPort:-1}") Integer proxyPort
) {
if (StringUtils.isEmpty(proxyHost) || proxyPort == -1) {
return Proxy.NO_PROXY;
} else {
return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
}
}

@Bean
public List<RetryListener> retryListeners() {
Logger log = LoggerFactory.getLogger(getClass());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
/*--- (C) 1999-2019 Techniker Krankenkasse ---*/
/*--- (C) 1999-2021 Techniker Krankenkasse ---*/

package de.tk.opensource.privacyproxy.config;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpMethod;

/**
* @deprecated because {@linkplain
* de.tk.opensource.privacyproxy.routing.RoutingHandler#handleGenericRequestInternal(String,
* Map, HttpServletRequest, String, HttpMethod)} can handle both method types.
*/
@Deprecated
public enum ProviderRequestMethod {

POST, GET
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*--- (C) 1999-2021 Techniker Krankenkasse ---*/

package de.tk.opensource.privacyproxy.config.proxy;

import java.net.InetSocketAddress;
import java.net.Proxy;

import org.apache.http.HttpHost;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.web.client.RestTemplate;

import de.tk.opensource.privacyproxy.util.ProxyHelper;
import de.tk.opensource.privacyproxy.util.ProxyRoutePlanner;
import de.tk.opensource.privacyproxy.util.RestTemplateProxyCustomizer;

@Configuration
public class HttpProxyConfig {

@Value("${http.proxyHost:#{null}}")
private String proxyHost;

@Value("${http.proxyPort:#{null}}")
private Integer proxyPort;

@Value("${http.nonProxyHosts:#{null}}")
private String nonProxyHosts;

@Bean
public Proxy proxy() {
if (proxyHost == null || proxyPort == null) {
return Proxy.NO_PROXY;
} else {
return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
}
}

@Bean
public HttpHost httpHost() {
if (proxyHost != null && proxyPort != null) {
return new HttpHost(proxyHost, proxyPort);
}
return null;
}

@Bean
@DependsOn("proxy")
public ProxyHelper proxyHelper() {
return new ProxyHelper(proxy(), nonProxyHosts);
}

@Bean
@DependsOn({ "httpHost", "proxyHelper" })
public ProxyRoutePlanner proxyRoutePlanner() {
return new ProxyRoutePlanner(proxyHelper(), httpHost());
}

@Bean
@DependsOn({ "proxyHelper", "proxyRoutePlanner" })
public RestTemplate restTemplate() {
return new RestTemplateBuilder(
new RestTemplateProxyCustomizer(proxyRoutePlanner(), proxyHelper())
)
.build();
}
}

/*--- Formatiert nach TK Code Konventionen vom 05.03.2002 ---*/
Loading