-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Shedlock Table Implement RAT Valueset Download * Add missing trailing new line * Add Unit Tests Remove enabled flag for proxy -> Autodetection Disable Sheduling for Tests * Update RatValuesetUpdateServiceTest.java * Update pom.xml
- Loading branch information
Showing
20 changed files
with
1,055 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/eu/europa/ec/dgc/gateway/client/JrcClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*- | ||
* ---license-start | ||
* EU Digital Green Certificate Gateway Service / dgc-gateway | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package eu.europa.ec.dgc.gateway.client; | ||
|
||
import eu.europa.ec.dgc.gateway.model.JrcRatValuesetResponse; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
@FeignClient( | ||
name = "jrcClient", | ||
url = "${dgc.jrc.url}", | ||
configuration = JrcClientConfig.class) | ||
public interface JrcClient { | ||
|
||
/** | ||
* This method gets a the RAT values from JRC API. | ||
* | ||
* @return List of RAT values. | ||
*/ | ||
@GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
JrcRatValuesetResponse downloadRatValues(); | ||
} |
94 changes: 94 additions & 0 deletions
94
src/main/java/eu/europa/ec/dgc/gateway/client/JrcClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/*- | ||
* ---license-start | ||
* EU Digital Green Certificate Gateway Service / dgc-gateway | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package eu.europa.ec.dgc.gateway.client; | ||
|
||
import eu.europa.ec.dgc.gateway.config.DgcConfigProperties; | ||
import feign.Client; | ||
import feign.httpclient.ApacheHttpClient; | ||
import java.security.NoSuchAlgorithmException; | ||
import javax.net.ssl.SSLContext; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.auth.AuthScope; | ||
import org.apache.http.auth.UsernamePasswordCredentials; | ||
import org.apache.http.client.CredentialsProvider; | ||
import org.apache.http.conn.ssl.DefaultHostnameVerifier; | ||
import org.apache.http.impl.client.BasicCredentialsProvider; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class JrcClientConfig { | ||
|
||
private final DgcConfigProperties config; | ||
|
||
/** | ||
* Configure the client depending on the ssl properties. | ||
* | ||
* @return an Apache Http Client with or without SSL features | ||
*/ | ||
@Bean | ||
public Client jrcClient() throws NoSuchAlgorithmException { | ||
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); | ||
|
||
httpClientBuilder.setSSLContext(SSLContext.getDefault()); | ||
httpClientBuilder.setSSLHostnameVerifier(new DefaultHostnameVerifier()); | ||
|
||
if (config.getJrc().getProxy().getHost() != null | ||
&& config.getJrc().getProxy().getPort() != -1 | ||
&& !config.getJrc().getProxy().getHost().isEmpty()) { | ||
log.info("Using Proxy for JRC Connection"); | ||
// Set proxy | ||
httpClientBuilder.setProxy(new HttpHost( | ||
config.getJrc().getProxy().getHost(), | ||
config.getJrc().getProxy().getPort() | ||
)); | ||
|
||
// Set proxy authentication | ||
if (config.getJrc().getProxy().getUsername() != null | ||
&& config.getJrc().getProxy().getPassword() != null | ||
&& !config.getJrc().getProxy().getUsername().isEmpty() | ||
&& !config.getJrc().getProxy().getPassword().isEmpty()) { | ||
|
||
log.info("Using Proxy with Authentication for JRC Connection"); | ||
|
||
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); | ||
credentialsProvider.setCredentials( | ||
new AuthScope( | ||
config.getJrc().getProxy().getHost(), | ||
config.getJrc().getProxy().getPort()), | ||
new UsernamePasswordCredentials( | ||
config.getJrc().getProxy().getUsername(), | ||
config.getJrc().getProxy().getPassword())); | ||
|
||
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); | ||
} | ||
} else { | ||
log.info("Using no proxy for JRC Connection"); | ||
} | ||
|
||
return new ApacheHttpClient(httpClientBuilder.build()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/eu/europa/ec/dgc/gateway/config/SchedulerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*- | ||
* ---license-start | ||
* EU Digital Green Certificate Gateway Service / dgc-gateway | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package eu.europa.ec.dgc.gateway.config; | ||
|
||
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
@Configuration | ||
@Profile("!test") | ||
@EnableScheduling | ||
@EnableSchedulerLock(defaultLockAtMostFor = "PT30S") | ||
public class SchedulerConfig { | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/eu/europa/ec/dgc/gateway/config/ShedLockConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*- | ||
* ---license-start | ||
* EU Digital Green Certificate Gateway Service / dgc-gateway | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package eu.europa.ec.dgc.gateway.config; | ||
|
||
import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder; | ||
|
||
import javax.sql.DataSource; | ||
import lombok.RequiredArgsConstructor; | ||
import net.javacrumbs.shedlock.core.LockProvider; | ||
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class ShedLockConfig { | ||
|
||
private final DataSource dataSource; | ||
|
||
/** | ||
* Creates a LockProvider for ShedLock. | ||
* | ||
* @return LockProvider | ||
*/ | ||
@Bean | ||
public LockProvider lockProvider() { | ||
return new JdbcTemplateLockProvider(builder() | ||
.withTableName("shedlock") | ||
.withJdbcTemplate(new JdbcTemplate(dataSource)) | ||
.usingDbTime() | ||
.build() | ||
); | ||
} | ||
} |
Oops, something went wrong.