Skip to content

Commit

Permalink
#414: remove deprecated fhir classes, fix Spring Boot Autoconfig, add…
Browse files Browse the repository at this point in the history
… HttpClient5-based RestClientFactory. Disabled one async test (TestIti56)
  • Loading branch information
Christian Ohr committed Mar 7, 2024
1 parent fe093f4 commit 84fea44
Show file tree
Hide file tree
Showing 70 changed files with 853 additions and 791 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.openehealth.ipf.boot.atna.IpfAtnaAutoConfiguration
org.openehealth.ipf.boot.atna.IpfAtnaSpringSecurityAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
package org.openehealth.ipf.boot.fhir;

import ca.uhn.fhir.context.FhirVersionEnum;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.core.io.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.cors.CorsConfiguration;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import java.util.*;

/**
Expand Down Expand Up @@ -155,6 +154,9 @@ public static class Servlet {
private boolean strict = false;
}

public static class CorsConfiguration extends org.springframework.web.cors.CorsConfiguration {
}

private static CorsConfiguration defaultCorsConfiguration() {
var cors = new CorsConfiguration();
cors.addAllowedOrigin("*");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.openehealth.ipf.boot.fhir.IpfFhirAutoConfiguration
org.openehealth.ipf.boot.fhir.IpfFhirPixpdqAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openehealth.ipf.boot.IpfAutoConfiguration;
import org.openehealth.ipf.commons.core.config.ContextFacade;
import org.openehealth.ipf.commons.map.MappingService;
import org.openehealth.ipf.commons.spring.map.config.CustomMappings;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.openehealth.ipf.boot.fhir.IpfFhirAutoConfiguration
org.openehealth.ipf.boot.fhir.IpfFhirPixpdqAutoConfiguration

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.openehealth.ipf.boot.hl7v2.IpfHl7v2AutoConfiguration

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.openehealth.ipf.boot.hl7v3.IpfHl7v3AutoConfiguration

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.openehealth.ipf.boot.hpd.IpfHpdAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Registry springRegistry() {

@Bean
@ConditionalOnMissingBean(SpringConfigurationPostProcessor.class)
public SpringConfigurationPostProcessor postProcessor(CustomMappingsConfigurer customMappingsConfigurer) {
public SpringConfigurationPostProcessor postProcessor(CustomMappingsConfigurer<SpringRegistry> customMappingsConfigurer) {
var processor = new SpringConfigurationPostProcessor();
var list = new ArrayList<OrderedConfigurer>();
if (customMappingsConfigurer != null) list.add(customMappingsConfigurer);
Expand All @@ -60,8 +60,8 @@ public SpringConfigurationPostProcessor postProcessor(CustomMappingsConfigurer c

@Bean
@ConditionalOnMissingBean(CustomMappingsConfigurer.class)
protected CustomMappingsConfigurer customMappingsConfigurer(SpringBidiMappingService mappingService) {
var configurer = new CustomMappingsConfigurer();
protected CustomMappingsConfigurer<SpringRegistry> customMappingsConfigurer(SpringBidiMappingService mappingService) {
var configurer = new CustomMappingsConfigurer<SpringRegistry>();
configurer.setMappingService(mappingService);
return configurer;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.openehealth.ipf.boot.IpfAutoConfiguration

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.openehealth.ipf.boot.xacml20.IpfXacml20AutoConfiguration

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.openehealth.ipf.boot.xds.IpfXdsAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public enum AuditTransmissionChannel {
NETTY_TLS("NETTY-TLS", NettyTLSSyslogSenderProvider.class.getName()),
REACTOR_NETTY_TLS("REACTOR-NETTY-TLS", ReactorNettyTLSSyslogSenderProvider.class.getName()),
FHIR_REST_TLS("FHIR-REST-TLS", "org.openehealth.ipf.commons.ihe.fhir.audit.protocol.FhirRestTLSAuditRecordApacheSenderProvider"),
FHIR_REST_APACHE5_TLS("FHIR-REST-APACHE5-TLS", "org.openehealth.ipf.commons.ihe.fhir.audit.protocol.FhirRestTLSAuditRecordApache5SenderProvider"),
FHIR_REST_METHANOL_TLS("FHIR-REST-METHANOL-TLS", "org.openehealth.ipf.commons.ihe.fhir.audit.protocol.FhirRestTLSAuditRecordMethanolSenderProvider"),
RECORDING("RECORDING", RecordingAuditMessageTransmissionProvider.class.getName());

Expand Down
10 changes: 10 additions & 0 deletions commons/ihe/fhir/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.mizosoft.methanol</groupId>
<artifactId>methanol</artifactId>
Expand Down Expand Up @@ -108,6 +113,11 @@
<artifactId>undertow-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2024 the original author or authors.
*
* 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.
*/
package org.openehealth.ipf.commons.ihe.fhir;

import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.client.apache.BaseHttpClient;
import ca.uhn.fhir.rest.client.api.Header;
import ca.uhn.fhir.rest.client.api.IHttpClient;
import ca.uhn.fhir.rest.client.api.IHttpRequest;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.http.message.BasicNameValuePair;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ApacheHttpClient5 extends BaseHttpClient implements IHttpClient {

private final CloseableHttpClient client;

public ApacheHttpClient5(CloseableHttpClient client,
StringBuilder url,
Map<String, List<String>> ifNoneExistParams,
String ifNoneExistString,
RequestTypeEnum requestType,
List<Header> theHeaders) {
super(url, ifNoneExistParams, ifNoneExistString, requestType, theHeaders);
this.client = client;
}

@Override
protected IHttpRequest createHttpRequest() {
return createHttpRequest((HttpEntity) null);
}

@Override
protected IHttpRequest createHttpRequest(byte[] content) {
return createHttpRequest(new ByteArrayEntity(content, null));
}

@Override
protected IHttpRequest createHttpRequest(Map<String, List<String>> params) {
List<NameValuePair> parameters = new ArrayList<>();
params.forEach((key, value) -> value.stream()
.map(s -> new BasicNameValuePair(key, s))
.forEach(parameters::add));
UrlEncodedFormEntity entity = createFormEntity(parameters);
return createHttpRequest(entity);
}

private UrlEncodedFormEntity createFormEntity(List<NameValuePair> parameters) {
return new UrlEncodedFormEntity(parameters, StandardCharsets.UTF_8);
}

@Override
protected IHttpRequest createHttpRequest(String content) {
return createHttpRequest(content.getBytes(StandardCharsets.UTF_8));
}

private ApacheHttpRequest5 createHttpRequest(HttpEntity entity) {
return new ApacheHttpRequest5(client, constructRequest(entity).build());
}

private ClassicRequestBuilder constructRequest(HttpEntity entity) {
String url = myUrl.toString();
return switch (myRequestType) {
case DELETE -> ClassicRequestBuilder.delete(url);
case PATCH -> ClassicRequestBuilder.patch(url).setEntity(entity);
case OPTIONS -> ClassicRequestBuilder.options(url);
case POST -> ClassicRequestBuilder.post(url).setEntity(entity);
case PUT -> ClassicRequestBuilder.put(url).setEntity(entity);
default -> ClassicRequestBuilder.get(url);
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2024 the original author or authors.
*
* 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.
*/
package org.openehealth.ipf.commons.ihe.fhir;

import ca.uhn.fhir.rest.client.api.BaseHttpRequest;
import ca.uhn.fhir.rest.client.api.IHttpRequest;
import ca.uhn.fhir.rest.client.api.IHttpResponse;
import ca.uhn.fhir.util.StopWatch;
import org.apache.commons.io.IOUtils;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.routing.RoutingSupport;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpException;

import java.io.IOException;
import java.net.URI;
import java.util.*;

public class ApacheHttpRequest5 extends BaseHttpRequest implements IHttpRequest {

private final ClassicHttpRequest request;
private final CloseableHttpClient httpClient;

public ApacheHttpRequest5(CloseableHttpClient httpClient, ClassicHttpRequest request) {
this.request = request;
this.httpClient = httpClient;
}

@Override
public void addHeader(String name, String value) {
request.addHeader(name, value);
}

@Override
public IHttpResponse execute() throws IOException {
var responseStopWatch = new StopWatch();
try {
// BaseClient will close the response stream for us
ClassicHttpResponse response = httpClient.executeOpen(RoutingSupport.determineHost(request), request, null);
return new ApacheHttpResponse5(response, responseStopWatch);
} catch (HttpException e) {
throw new IOException(e);
}

}

@Override
public Map<String, List<String>> getAllHeaders() {
Map<String, List<String>> result = new HashMap<>();
for (var header : request.getHeaders()) {
if (!result.containsKey(header.getName())) {
result.put(header.getName(), new LinkedList<>());
}
result.get(header.getName()).add(header.getValue());
}
return Collections.unmodifiableMap(result);
}

@Override
public String getRequestBodyFromStream() throws IOException {
var entity = request.getEntity();
if (entity.isRepeatable()) {
final var contentTypeHeader = request.getFirstHeader("Content-Type");
var charset = contentTypeHeader == null
? null
: ContentType.parse(contentTypeHeader.getValue()).getCharset();
return IOUtils.toString(entity.getContent(), charset);
}
return null;
}

@Override
public String getUri() {
return request.getRequestUri();
}

@Override
public void setUri(String uri) {
request.setUri(URI.create(uri));
}

@Override
public String getHttpVerbName() {
return request.getMethod();
}

@Override
public void removeHeaders(String name) {
request.removeHeaders(name);
}
}
Loading

0 comments on commit 84fea44

Please sign in to comment.