From 39e36edbb5fe2f030a1f56645ba9da594b9a5b81 Mon Sep 17 00:00:00 2001 From: "Joel Schneider (NMDP)" Date: Tue, 20 Sep 2016 15:04:49 -0500 Subject: [PATCH] modify hapi-fhir-jpaserver-example to run in STU3 mode --- .../fhir/jpa/demo/FhirTesterConfigDstu3.java | 56 +++++++++++++++++++ .../ca/uhn/fhir/jpa/demo/JpaServerDemo.java | 16 +++--- .../src/main/webapp/WEB-INF/web.xml | 8 +-- .../ca/uhn/fhir/jpa/demo/ExampleServerIT.java | 6 +- 4 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/FhirTesterConfigDstu3.java diff --git a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/FhirTesterConfigDstu3.java b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/FhirTesterConfigDstu3.java new file mode 100644 index 00000000000..714b8f10cd6 --- /dev/null +++ b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/FhirTesterConfigDstu3.java @@ -0,0 +1,56 @@ +package ca.uhn.fhir.jpa.demo; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +import ca.uhn.fhir.context.FhirVersionEnum; +import ca.uhn.fhir.to.FhirTesterMvcConfig; +import ca.uhn.fhir.to.TesterConfig; + +//@formatter:off +/** + * This spring config file configures the web testing module. It serves two + * purposes: + * 1. It imports FhirTesterMvcConfig, which is the spring config for the + * tester itself + * 2. It tells the tester which server(s) to talk to, via the testerConfig() + * method below + */ +@Configuration +@Import(FhirTesterMvcConfig.class) +public class FhirTesterConfigDstu3 { + + /** + * This bean tells the testing webpage which servers it should configure itself + * to communicate with. In this example we configure it to talk to the local + * server, as well as one public server. If you are creating a project to + * deploy somewhere else, you might choose to only put your own server's + * address here. + * + * Note the use of the ${serverBase} variable below. This will be replaced with + * the base URL as reported by the server itself. Often for a simple Tomcat + * (or other container) installation, this will end up being something + * like "http://localhost:8080/hapi-fhir-jpaserver-example". If you are + * deploying your server to a place with a fully qualified domain name, + * you might want to use that instead of using the variable. + */ + @Bean + public TesterConfig testerConfig() { + TesterConfig retVal = new TesterConfig(); + retVal + .addServer() + .withId("home") + .withFhirVersion(FhirVersionEnum.DSTU3) + .withBaseUrl("${serverBase}/baseDstu3") + .withName("Local Tester") + .addServer() + .withId("hapi") + .withFhirVersion(FhirVersionEnum.DSTU3) + .withBaseUrl("http://fhirtest.uhn.ca/baseDstu3") + .withName("Public HAPI Test Server"); + return retVal; + } + +} +//@formatter:on diff --git a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java index 92147e542af..3971498bcf5 100644 --- a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java +++ b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java @@ -42,19 +42,19 @@ public class JpaServerDemo extends RestfulServer { protected void initialize() throws ServletException { super.initialize(); - /* + /* * We want to support FHIR DSTU2 format. This means that the server * will use the DSTU2 bundle format and other DSTU2 encoding changes. * * If you want to use DSTU1 instead, change the following line, and change the 2 occurrences of dstu2 in web.xml to dstu1 */ - FhirVersionEnum fhirVersion = FhirVersionEnum.DSTU2; + FhirVersionEnum fhirVersion = FhirVersionEnum.DSTU3; setFhirContext(new FhirContext(fhirVersion)); // Get the spring context from the web container (it's declared in web.xml) myAppCtx = ContextLoaderListener.getCurrentWebApplicationContext(); - /* + /* * The BaseJavaConfigDstu2.java class is a spring configuration * file which is automatically generated as a part of hapi-fhir-jpaserver-base and * contains bean definitions for a resource provider for each resource type @@ -71,8 +71,8 @@ public class JpaServerDemo extends RestfulServer { } List beans = myAppCtx.getBean(resourceProviderBeanName, List.class); setResourceProviders(beans); - - /* + + /* * The system provider implements non-resource-type methods, such as * transaction, and global history. */ @@ -149,15 +149,15 @@ public class JpaServerDemo extends RestfulServer { } /* - * If you are hosting this server at a specific DNS name, the server will try to + * If you are hosting this server at a specific DNS name, the server will try to * figure out the FHIR base URL based on what the web container tells it, but * this doesn't always work. If you are setting links in your search bundles that * just refer to "localhost", you might want to use a server address strategy: */ //setServerAddressStrategy(new HardcodedServerAddressStrategy("http://mydomain.com/fhir/baseDstu2")); - + /* - * If you are using DSTU3+, you may want to add a terminology uploader, which allows + * If you are using DSTU3+, you may want to add a terminology uploader, which allows * uploading of external terminologies such as Snomed CT. Note that this uploader * does not have any security attached (any anonymous user may use it by default) * so it is a potential security vulnerability. Consider using an AuthorizationInterceptor diff --git a/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml b/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml index c81a6f602d0..f253110b57c 100644 --- a/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml +++ b/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml @@ -13,7 +13,7 @@ contextConfigLocation - ca.uhn.fhir.jpa.demo.FhirServerConfig + ca.uhn.fhir.jpa.demo.FhirServerConfigDstu3 @@ -28,7 +28,7 @@ contextConfigLocation - ca.uhn.fhir.jpa.demo.FhirTesterConfig + ca.uhn.fhir.jpa.demo.FhirTesterConfigDstu3 2 @@ -42,14 +42,14 @@ FhirVersion - DSTU2 + DSTU3 1 fhirServlet - /baseDstu2/* + /baseDstu3/* diff --git a/hapi-fhir-jpaserver-example/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java b/hapi-fhir-jpaserver-example/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java index 89a6ac2f06e..43c6a79b0c0 100644 --- a/hapi-fhir-jpaserver-example/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java +++ b/hapi-fhir-jpaserver-example/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java @@ -7,13 +7,13 @@ import java.io.IOException; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; +import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.client.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; @@ -21,7 +21,7 @@ import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; public class ExampleServerIT { private static IGenericClient ourClient; - private static FhirContext ourCtx = FhirContext.forDstu2(); + private static FhirContext ourCtx = FhirContext.forDstu3(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerIT.class); private static int ourPort; @@ -72,7 +72,7 @@ public class ExampleServerIT { ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000); - ourServerBase = "http://localhost:" + ourPort + "/baseDstu2"; + ourServerBase = "http://localhost:" + ourPort + "/baseDstu3"; ourClient = ourCtx.newRestfulGenericClient(ourServerBase); ourClient.registerInterceptor(new LoggingInterceptor(true));