[ACS-4460] simplify required bean definitions

This commit is contained in:
kcichonczyk 2023-02-20 16:53:07 +01:00
parent 0af53e93f3
commit 149f3a500c
2 changed files with 17 additions and 17 deletions

View File

@ -55,16 +55,9 @@ import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException; import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import static org.springframework.http.HttpHeaders.ACCEPT;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Configuration @Configuration
public class MTLSConfig { public class MTLSConfig {
@Value("${filestore-url}")
private String url;
@Value("${server.ssl.enabled:false}") @Value("${server.ssl.enabled:false}")
boolean sslEnabled; boolean sslEnabled;
@ -89,15 +82,6 @@ public class MTLSConfig {
@Value("${server.ssl.trust.store.type:}") @Value("${server.ssl.trust.store.type:}")
private String trustStoreType; private String trustStoreType;
@Bean
public WebClient client(WebClient.Builder clientBuilder)
{
return clientBuilder.baseUrl(url.endsWith("/") ? url : url + "/")
.defaultHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.defaultHeader(ACCEPT, APPLICATION_JSON_VALUE)
.build();
}
@Bean @Bean
public WebClient.Builder clientBuilder() throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException, UnrecoverableKeyException { public WebClient.Builder clientBuilder() throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException, UnrecoverableKeyException {
if(sslEnabled) if(sslEnabled)

View File

@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Transform Core * Alfresco Transform Core
* %% * %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited * Copyright (C) 2005 - 2023 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* - * -
@ -26,7 +26,10 @@
*/ */
package org.alfresco.transform.base.sfs; package org.alfresco.transform.base.sfs;
import static org.springframework.http.HttpHeaders.ACCEPT;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
import java.io.File; import java.io.File;
@ -49,6 +52,8 @@ import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient;
import javax.annotation.PostConstruct;
/** /**
* Simple Rest client that call Alfresco Shared File Store * Simple Rest client that call Alfresco Shared File Store
*/ */
@ -64,8 +69,19 @@ public class SharedFileStoreClient
private RestTemplate restTemplate; private RestTemplate restTemplate;
@Autowired @Autowired
private WebClient.Builder clientBuilder;
private WebClient client; private WebClient client;
@PostConstruct
public void init()
{
client = clientBuilder.baseUrl(url.endsWith("/") ? url : url + "/")
.defaultHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.defaultHeader(ACCEPT, APPLICATION_JSON_VALUE)
.build();
}
/** /**
* Retrieves a file from Shared File Store using given file reference * Retrieves a file from Shared File Store using given file reference
* *