Skip to content

Commit

Permalink
revert restclient apollon changes
Browse files Browse the repository at this point in the history
  • Loading branch information
krusche committed Jan 3, 2025
1 parent 81ce8ed commit f7b21b5
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class EurekaClientConfiguration {
@Bean
public RestClientDiscoveryClientOptionalArgs restClientDiscoveryClientOptionalArgs(TlsProperties tlsProperties, ObjectProvider<RestClient.Builder> restClientBuilderProvider)
throws GeneralSecurityException, IOException {
log.debug("Using RestClient for the Eureka client.");
log.debug("Using RestTemplate for the Eureka client.");
// The Eureka DiscoveryClientOptionalArgsConfiguration invokes a private method setupTLS.
// This code is taken from that method.
var supplier = new DefaultEurekaClientHttpRequestFactorySupplier(new RestClientTimeoutProperties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;

import de.tum.cit.aet.artemis.athena.config.AthenaAuthorizationInterceptor;
Expand Down Expand Up @@ -63,8 +62,8 @@ public RestTemplate athenaRestTemplate(AthenaAuthorizationInterceptor athenaAuth

@Bean
@Profile(PROFILE_APOLLON)
public RestClient apollonRestClient() {
return createRestClient();
public RestTemplate apollonRestTemplate() {
return createRestTemplate();
}

/**
Expand Down Expand Up @@ -107,8 +106,8 @@ public RestTemplate shortTimeoutAthenaRestTemplate(AthenaAuthorizationIntercepto

@Bean
@Profile(PROFILE_APOLLON)
public RestClient shortTimeoutApollonRestClient() {
return createShortTimeoutRestClient();
public RestTemplate shortTimeoutApollonRestTemplate() {
return createShortTimeoutRestTemplate();
}

@Bean
Expand Down Expand Up @@ -173,14 +172,6 @@ private RestTemplate createRestTemplate() {
return new RestTemplate();
}

private RestClient createRestClient() {
return RestClient.create();
}

private RestClient createShortTimeoutRestClient() {
return RestClient.builder().requestFactory(getSimpleClientHttpRequestFactory(SHORT_READ_TIMEOUT, SHORT_CONNECTION_TIMEOUT)).build();
}

private RestTemplate createShortTimeoutRestTemplate() {
final var requestFactory = getSimpleClientHttpRequestFactory(SHORT_READ_TIMEOUT, SHORT_CONNECTION_TIMEOUT);
return new RestTemplate(requestFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;

import de.tum.cit.aet.artemis.modeling.dto.ApollonModelDTO;

Expand All @@ -25,14 +25,14 @@ public class ApollonConversionService {
@Value("${artemis.apollon.conversion-service-url}")
private String apollonConversionUrl;

private RestClient restClient;
private RestTemplate restTemplate;

public ApollonConversionService(RestClient apollonRestClient) {
setRestClient(apollonRestClient);
public ApollonConversionService(RestTemplate apollonRestTemplate) {
setRestTemplate(apollonRestTemplate);
}

public void setRestClient(RestClient restClient) {
this.restClient = restClient;
public void setRestTemplate(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}

/**
Expand All @@ -46,7 +46,7 @@ public InputStream convertModel(String model) {
log.info("Calling Remote Service to convert for model.");
try {
var apollonModel = new ApollonModelDTO(model);
var response = restClient.post().uri(apollonConversionUrl + "/pdf").body(apollonModel).retrieve().toEntity(Resource.class);
var response = restTemplate.postForEntity(apollonConversionUrl + "/pdf", apollonModel, Resource.class);
if (response.getBody() != null) {
return response.getBody().getInputStream();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import de.tum.cit.aet.artemis.core.service.connectors.ConnectorHealth;

@Component
@Profile(PROFILE_APOLLON)
public class ApollonHealthIndicator implements HealthIndicator {

private final RestClient shortTimeoutRestClient;
private final RestTemplate shortTimeoutRestTemplate;

@Value("${artemis.apollon.conversion-service-url}")
private String apollonConversionUrl;

public ApollonHealthIndicator(@Qualifier("shortTimeoutApollonRestClient") RestClient shortTimeoutRestClient) {
this.shortTimeoutRestClient = shortTimeoutRestClient;
public ApollonHealthIndicator(@Qualifier("shortTimeoutApollonRestTemplate") RestTemplate shortTimeoutRestTemplate) {
this.shortTimeoutRestTemplate = shortTimeoutRestTemplate;
}

/**
Expand All @@ -38,7 +38,7 @@ public Health health() {
Map<String, Object> additionalInfo = Map.of("url", apollonConversionUrl);
ConnectorHealth health;
try {
ResponseEntity<String> response = shortTimeoutRestClient.get().uri(apollonConversionUrl + "/status").retrieve().toEntity(String.class);
ResponseEntity<String> response = shortTimeoutRestTemplate.getForEntity(apollonConversionUrl + "/status", String.class);
HttpStatusCode statusCode = response.getStatusCode();
health = new ConnectorHealth(statusCode.is2xxSuccessful(), additionalInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
import org.springframework.test.web.client.ExpectedCount;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.test.web.client.ResponseActions;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;

@Component
@Profile(PROFILE_APOLLON)
public class ApollonRequestMockProvider {

private final RestClient restClient;
private final RestTemplate restTemplate;

private MockRestServiceServer mockServer;

private final RestClient shortTimeoutRestClient;
private final RestTemplate shortTimeoutRestTemplate;

private MockRestServiceServer mockServerShortTimeout;

Expand All @@ -38,17 +38,18 @@ public class ApollonRequestMockProvider {

private AutoCloseable closeable;

public ApollonRequestMockProvider(@Qualifier("apollonRestClient") RestClient restClient, @Qualifier("shortTimeoutApollonRestClient") RestClient shortTimeoutRestClient) {
this.restClient = restClient;
this.shortTimeoutRestClient = shortTimeoutRestClient;
public ApollonRequestMockProvider(@Qualifier("apollonRestTemplate") RestTemplate restTemplate,
@Qualifier("shortTimeoutApollonRestTemplate") RestTemplate shortTimeoutRestTemplate) {
this.restTemplate = restTemplate;
this.shortTimeoutRestTemplate = shortTimeoutRestTemplate;
}

public void enableMockingOfRequests() {
MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(restClient.mutate());
MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(restTemplate);
builder.ignoreExpectOrder(true);
mockServer = builder.build();

MockRestServiceServer.MockRestServiceServerBuilder builderShortTimeout = MockRestServiceServer.bindTo(shortTimeoutRestClient.mutate());
MockRestServiceServer.MockRestServiceServerBuilder builderShortTimeout = MockRestServiceServer.bindTo(shortTimeoutRestTemplate);
builderShortTimeout.ignoreExpectOrder(true);
mockServerShortTimeout = builderShortTimeout.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;

import de.tum.cit.aet.artemis.assessment.domain.AssessmentType;
import de.tum.cit.aet.artemis.assessment.domain.Feedback;
Expand Down Expand Up @@ -127,8 +127,8 @@ class DataExportCreationServiceTest extends AbstractSpringIntegrationJenkinsGitl
private ApollonRequestMockProvider apollonRequestMockProvider;

@Autowired
@Qualifier("apollonRestClient")
private RestClient restClient;
@Qualifier("apollonRestTemplate")
private RestTemplate restTemplate;

@Autowired
private ApollonConversionService apollonConversionService;
Expand Down Expand Up @@ -159,7 +159,7 @@ void initTestCase() throws IOException {
userUtilService.addUsers(TEST_PREFIX, 2, 5, 0, 1);
userUtilService.adjustUserGroupsToCustomGroups(TEST_PREFIX, "", 2, 5, 0, 1);

apollonConversionService.setRestClient(restClient);
apollonConversionService.setRestTemplate(restTemplate);

apollonRequestMockProvider.enableMockingOfRequests();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;

import de.tum.cit.aet.artemis.core.connector.apollon.ApollonRequestMockProvider;
import de.tum.cit.aet.artemis.modeling.dto.ApollonModelDTO;
Expand All @@ -29,8 +29,8 @@ class ApollonConversionIntegrationTest extends AbstractSpringIntegrationIndepend
private ApollonRequestMockProvider apollonRequestMockProvider;

@Autowired
@Qualifier("apollonRestClient")
RestClient restClient;
@Qualifier("apollonRestTemplate")
RestTemplate restTemplate;

@Value("${artemis.apollon.conversion-service-url}")
private String apollonConversionUrl;
Expand All @@ -40,7 +40,7 @@ class ApollonConversionIntegrationTest extends AbstractSpringIntegrationIndepend

@BeforeEach
void init() {
apollonConversionService.setRestClient(restClient);
apollonConversionService.setRestTemplate(restTemplate);
ReflectionTestUtils.setField(apollonConversionService, "apollonConversionUrl", apollonConversionUrl);

apollonRequestMockProvider.enableMockingOfRequests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;

import de.tum.cit.aet.artemis.core.connector.apollon.ApollonRequestMockProvider;
import de.tum.cit.aet.artemis.modeling.service.apollon.ApollonConversionService;
Expand All @@ -31,8 +31,8 @@ class ApollonConversionServiceTest extends AbstractSpringIntegrationIndependentT
private ApollonRequestMockProvider apollonRequestMockProvider;

@Autowired
@Qualifier("apollonRestClient")
RestClient restClient;
@Qualifier("apollonRestTemplate")
RestTemplate restTemplate;

@Value("${artemis.apollon.conversion-service-url}")
private String apollonConversionUrl;
Expand All @@ -45,7 +45,7 @@ class ApollonConversionServiceTest extends AbstractSpringIntegrationIndependentT
@BeforeEach
void init() {
// Create apollonConversionService and inject @Value fields
apollonConversionService = new ApollonConversionService(restClient);
apollonConversionService = new ApollonConversionService(restTemplate);
ReflectionTestUtils.setField(apollonConversionService, "apollonConversionUrl", apollonConversionUrl);

apollonRequestMockProvider.enableMockingOfRequests();
Expand Down

0 comments on commit f7b21b5

Please sign in to comment.