-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Server with Spring Boot autoconfiguration should not depend on AbstractJaxRsProvider #7197
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
Open
adamzkover
wants to merge
2
commits into
hapifhir:master
Choose a base branch
from
adamzkover:spring-boot-server-autoconfig
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
45 changes: 45 additions & 0 deletions
45
...ing-boot-sample-client-apache/src/test/java/sample/fhir/client/AutoconfigurationTest.java
This file contains hidden or 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,45 @@ | ||
package sample.fhir.client; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
import ca.uhn.fhir.spring.boot.autoconfigure.FhirProperties; | ||
|
||
@SpringBootTest | ||
public class AutoconfigurationTest { | ||
|
||
@Autowired | ||
private FhirProperties properties; | ||
|
||
@Autowired | ||
private ApplicationContext applicationContext; | ||
|
||
@Test | ||
public void testContextNotNull() { | ||
assertThat(applicationContext).isNotNull(); | ||
} | ||
|
||
@Test | ||
public void testBean() { | ||
// Test that no bean has a URL mapping that includes the FHIR server path set in the application configuration | ||
String[] beanNames = applicationContext.getBeanNamesForType(ServletRegistrationBean.class); | ||
String expectedPath = properties.getServer().getPath(); | ||
long count = 0; | ||
for (String beanName : beanNames) { | ||
ServletRegistrationBean<?> bean = applicationContext.getBean(beanName, ServletRegistrationBean.class); | ||
for (String mapping : bean.getUrlMappings()) { | ||
if (mapping.contains(expectedPath)) { | ||
count++; | ||
} | ||
} | ||
} | ||
// The server should not be created because the hapi-fhir-server dependency is not added | ||
assertThat(count).isEqualTo(0); | ||
} | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
...ring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-plain/pom.xml
This file contains hidden or 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 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>ca.uhn.hapi.fhir</groupId> | ||
<artifactId>hapi-fhir-spring-boot-samples</artifactId> | ||
<version>8.5.1-SNAPSHOT</version> | ||
|
||
</parent> | ||
|
||
<artifactId>hapi-fhir-spring-boot-sample-server-plain</artifactId> | ||
<name>HAPI-FHIR Spring Boot Sample Server</name> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<!-- Compile --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>ca.uhn.hapi.fhir</groupId> | ||
<artifactId>hapi-fhir-spring-boot-starter</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ca.uhn.hapi.fhir</groupId> | ||
<artifactId>hapi-fhir-structures-r4</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ca.uhn.hapi.fhir</groupId> | ||
<artifactId>hapi-fhir-server</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<!-- Test --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Logging --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>log4j-over-slf4j</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>${spring_boot_version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
<optional>true</optional> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.basepom.maven</groupId> | ||
<artifactId>duplicate-finder-maven-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
36 changes: 36 additions & 0 deletions
36
...ver-plain/src/main/java/sample/fhir/server/plain/SamplePlainRestfulServerApplication.java
This file contains hidden or 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,36 @@ | ||
/*- | ||
* #%L | ||
* hapi-fhir-spring-boot-sample-server-jersey | ||
* %% | ||
* Copyright (C) 2014 - 2017 University Health Network | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
package sample.fhir.server.plain; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
import ca.uhn.fhir.spring.boot.autoconfigure.FhirAutoConfiguration; | ||
|
||
@SpringBootApplication | ||
@ImportAutoConfiguration(FhirAutoConfiguration.class) | ||
public class SamplePlainRestfulServerApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SamplePlainRestfulServerApplication.class, args); | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
...server-plain/src/main/java/sample/fhir/server/plain/provider/PatientResourceProvider.java
This file contains hidden or 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,66 @@ | ||
/*- | ||
* #%L | ||
* hapi-fhir-spring-boot-sample-server-jersey | ||
* %% | ||
* Copyright (C) 2014 - 2017 University Health Network | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
package sample.fhir.server.plain.provider; | ||
|
||
import java.util.HashMap; | ||
|
||
import org.hl7.fhir.r4.model.HumanName; | ||
import org.hl7.fhir.r4.model.IdType; | ||
import org.hl7.fhir.r4.model.Patient; | ||
import org.springframework.stereotype.Component; | ||
|
||
import ca.uhn.fhir.i18n.Msg; | ||
import ca.uhn.fhir.rest.annotation.IdParam; | ||
import ca.uhn.fhir.rest.annotation.Read; | ||
import ca.uhn.fhir.rest.server.IResourceProvider; | ||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; | ||
|
||
@Component | ||
public class PatientResourceProvider implements IResourceProvider { | ||
|
||
private static final HashMap<String, Patient> patients = new HashMap<>(); | ||
|
||
static { | ||
patients.put(String.valueOf(1L), createPatient("1", "Doe", "Jane")); | ||
patients.put(String.valueOf(2L), createPatient("2", "Doe", "John")); | ||
} | ||
|
||
@Override | ||
public Class<Patient> getResourceType() { | ||
return Patient.class; | ||
} | ||
|
||
@Read | ||
public Patient find(@IdParam final IdType theId) { | ||
if (patients.containsKey(theId.getIdPart())) { | ||
return patients.get(theId.getIdPart()); | ||
} else { | ||
throw new ResourceNotFoundException(Msg.code(2005) + theId); | ||
} | ||
} | ||
|
||
private static Patient createPatient(final String id, final String family, final String given) { | ||
final Patient patient = new Patient(); | ||
patient.getName().add(new HumanName().setFamily(family).addGiven(given)); | ||
patient.setId(id); | ||
return patient; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...boot-samples/hapi-fhir-spring-boot-sample-server-plain/src/main/resources/application.yml
This file contains hidden or 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,18 @@ | ||
hapi: | ||
fhir: | ||
version: R4 | ||
server: | ||
path: /fhir/* | ||
rest: | ||
server-name: hapi-fhir-spring-boot-sample-server-plain | ||
server-version: 1.0.0 | ||
implementation-description: Spring Boot Plain Server Sample | ||
default-response-encoding: json | ||
e-tag-support: enabled | ||
default-pretty-print: true | ||
validation: | ||
enabled: true | ||
request-only: true | ||
management: | ||
security: | ||
enabled: false |
40 changes: 40 additions & 0 deletions
40
...plain/src/test/java/sample/fhir/server/plain/SamplePlainRestfulServerApplicationTest.java
This file contains hidden or 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,40 @@ | ||
package sample.fhir.server.plain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
import ca.uhn.fhir.spring.boot.autoconfigure.FhirProperties; | ||
|
||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
public class SamplePlainRestfulServerApplicationTest { | ||
|
||
@Autowired | ||
private FhirProperties properties; | ||
|
||
@Autowired | ||
private ApplicationContext applicationContext; | ||
|
||
@Test | ||
public void testBean() { | ||
// Test if exactly one bean has a URL mapping that includes the FHIR server path set in the application configuration | ||
String[] beanNames = applicationContext.getBeanNamesForType(ServletRegistrationBean.class); | ||
String expectedPath = properties.getServer().getPath(); | ||
long count = 0; | ||
for (String beanName : beanNames) { | ||
ServletRegistrationBean<?> bean = applicationContext.getBean(beanName, ServletRegistrationBean.class); | ||
for (String mapping : bean.getUrlMappings()) { | ||
if (mapping.contains(expectedPath)) { | ||
count++; | ||
} | ||
} | ||
} | ||
assertThat(count).isEqualTo(1); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...oot-samples/hapi-fhir-spring-boot-sample-server-plain/src/test/resources/logback-test.xml
This file contains hidden or 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,14 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%file:%line] - %msg%n | ||
</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
|
||
</configuration> |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wouldn't you do the
execute
invocation here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling
execute
would actually execute the request, and fail if there isn't a FHIR server running onlocalhost:8080
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enabled execute again, and added a mock CommandLineRunner in the test class.