- fixed issue on ui regarding pagination of results by configuring refuseToFetchThirdPartyUrls

- updated fhir version to R4 and used mysql as datasource with docs updated
- transferred jetty plugin to be viewable on intellij
- disabled oss snapshots
- replaced corsFilter based on new hapi docs
This commit is contained in:
Jessie James Cosare
2019-03-08 13:22:25 +08:00
parent 6907ae34ba
commit c5bfade9ce
7 changed files with 119 additions and 89 deletions

View File

@@ -56,10 +56,13 @@ Much of this HAPI starter project can be configured using the properties file in
## MySql
To configure the starter app to use MySQL, instead of the default Derby, update the hapi.properties file to have the following:
To configure the starter app to with MySQL, use the commands below to add user and database:
* datasource.driver=com.mysql.jdbc.Driver
* datasource.url=jdbc:mysql://localhost:3306/hapi_dstu3
* hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
```
CREATE USER 'fhirUser'@'localhost' IDENTIFIED BY 'fhirPass';
CREATE DATABASE fhir_r4;
GRANT ALL PRIVILEGES ON fhir_r4.* to 'fhirUser'@'localhost';
FLUSH PRIVILEGES;
```
It is important to use MySQL5Dialect when using MySQL version 5+.

47
pom.xml
View File

@@ -24,7 +24,7 @@
<repository>
<id>oss-snapshots</id>
<snapshots>
<enabled>true</enabled>
<enabled>false</enabled>
</snapshots>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
@@ -111,16 +111,11 @@
</dependency>
<!-- Used for CORS support -->
<dependency>
<groupId>org.ebaysf.web</groupId>
<artifactId>cors-filter</artifactId>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
</exclusions>
</dependency>
<!--<dependency>-->
<!--<groupId>org.eclipse.jetty</groupId>-->
<!--<artifactId>jetty-servlets</artifactId>-->
<!--<version>9.4.12.v20180830</version>-->
<!--</dependency>-->
<!-- Spring Web is used to deploy the server to a web container. -->
<dependency>
@@ -207,24 +202,20 @@
<!-- Tells Maven to name the generated WAR file as hapi-fhir-jpaserver.war -->
<finalName>hapi-fhir-jpaserver</finalName>
<!-- The following is not required for the application to build, but allows you to test it by issuing "mvn jetty:run" from the command line. -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.8.v20180619</version>
<configuration>
<webApp>
<contextPath>/</contextPath>
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
</webApp>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- The following is not required for the application to build, but allows you to test it by issuing "mvn jetty:run" from the command line. -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.8.v20180619</version>
<configuration>
<webApp>
<contextPath>/</contextPath>
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
</webApp>
</configuration>
</plugin>
<!-- Tell Maven which Java source version you want to use -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -43,6 +43,7 @@ public class FhirTesterConfig {
.withFhirVersion(HapiProperties.getFhirVersion())
.withBaseUrl(HapiProperties.getServerAddress())
.withName(HapiProperties.getServerName());
retVal.setRefuseToFetchThirdPartyUrls(HapiProperties.getTesterConfigRefustToFetchThirdPartyUrls());
return retVal;
}

View File

@@ -39,6 +39,7 @@ public class HapiProperties {
static final String SUBSCRIPTION_EMAIL_ENABLED = "subscription.email.enabled";
static final String SUBSCRIPTION_RESTHOOK_ENABLED = "subscription.resthook.enabled";
static final String TEST_PORT = "test.port";
static final String TESTER_CONFIG_REFUSE_TO_FETCH_THIRD_PARTY_URLS = "tester.config.refuse_to_fetch_third_party_urls";
private static Properties properties;
@@ -249,6 +250,10 @@ public class HapiProperties {
return HapiProperties.getIntegerProperty(TEST_PORT, 0);
}
public static Boolean getTesterConfigRefustToFetchThirdPartyUrls() {
return HapiProperties.getBooleanProperty(TESTER_CONFIG_REFUSE_TO_FETCH_THIRD_PARTY_URLS, false);
}
public static String getServerBase() {
return HapiProperties.getProperty(SERVER_BASE, "/fhir");
}

View File

@@ -4,6 +4,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.model.interceptor.executor.InterceptorService;
import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2;
import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider;
@@ -14,17 +15,22 @@ import ca.uhn.fhir.jpa.provider.r4.JpaConformanceProviderR4;
import ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4;
import ca.uhn.fhir.jpa.provider.r4.TerminologyUploaderProviderR4;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
import ca.uhn.fhir.jpa.subscription.SubscriptionInterceptorLoader;
import ca.uhn.fhir.jpa.subscription.module.interceptor.SubscriptionDebugLogInterceptor;
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.interceptor.CorsInterceptor;
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Meta;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.cors.CorsConfiguration;
import javax.servlet.ServletException;
import java.util.Arrays;
import java.util.List;
public class JpaRestfulServer extends RestfulServer {
@@ -173,6 +179,33 @@ public class JpaRestfulServer extends RestfulServer {
SubscriptionTriggeringProvider retriggeringProvider = appCtx.getBean(SubscriptionTriggeringProvider.class);
registerProvider(retriggeringProvider);
}
// Define your CORS configuration. This is an example
// showing a typical setup. You should customize this
// to your specific needs
CorsConfiguration config = new CorsConfiguration();
config.addAllowedHeader("x-fhir-starter");
config.addAllowedHeader("Origin");
config.addAllowedHeader("Accept");
config.addAllowedHeader("X-Requested-With");
config.addAllowedHeader("Content-Type");
config.addAllowedOrigin("*");
config.addExposedHeader("Location");
config.addExposedHeader("Content-Location");
config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
// Create the interceptor and register it
CorsInterceptor interceptor = new CorsInterceptor(config);
registerInterceptor(interceptor);
// Enable the use of subscriptions
SubscriptionInterceptorLoader subscriptionInterceptorLoader = appCtx.getBean(SubscriptionInterceptorLoader.class);
subscriptionInterceptorLoader.registerInterceptors();
// Subscription debug logging
InterceptorService interceptorService = (InterceptorService) appCtx.getBean("interceptorService");
interceptorService.registerInterceptor(new SubscriptionDebugLogInterceptor());
}
}

View File

@@ -1,7 +1,7 @@
# Adjust this to set the version of FHIR supported by this server. See
# FhirVersionEnum for a list of available constants.
fhir_version=DSTU3
fhir_version=R4
# This is the address that the FHIR server will report as its own address.
# If this server will be deployed (for example) to an internet accessible
@@ -25,16 +25,16 @@ logger.name=fhirtest.access
logger.format=Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${operationName} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}] ResponseEncoding[${responseEncodingNoDefault}]
logger.error_format=ERROR - ${requestVerb} ${requestUrl}
logger.log_exceptions=true
datasource.driver=org.apache.derby.jdbc.EmbeddedDriver
datasource.url=jdbc:derby:directory:target/jpaserver_derby_files;create=true
datasource.username=
datasource.password=
datasource.driver=com.mysql.cj.jdbc.Driver
datasource.url=jdbc:mysql://localhost:3306/fhir_r4
datasource.username=fhirUser
datasource.password=fhirPass
server.name=Local Tester
server.id=home
test.port=
subscription.email.enabled=true
subscription.resthook.enabled=true
hibernate.dialect=ca.uhn.fhir.jpa.util.DerbyTenSevenHapiFhirDialect
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.search.model_mapping=ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory
hibernate.format_sql=false
hibernate.show_sql=false
@@ -47,3 +47,4 @@ hibernate.cache.use_minimal_puts=false
hibernate.search.default.directory_provider=filesystem
hibernate.search.default.indexBase=target/lucenefiles
hibernate.search.lucene_version=LUCENE_CURRENT
tester.config.refuse_to_fetch_third_party_urls=false

View File

@@ -37,69 +37,65 @@
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>fhirServlet</servlet-name>
<servlet-class>ca.uhn.fhir.jpa.starter.JpaRestfulServer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>fhirServlet</servlet-name>
<url-pattern>/fhir/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- This filters provide support for Cross Origin Resource Sharing (CORS) -->
<filter>
<filter-name>CORS Filter</filter-name>
<filter-class>org.ebaysf.web.cors.CORSFilter</filter-class>
<init-param>
<description>A comma separated list of allowed origins. Note: An '*' cannot be used for an allowed origin when using credentials.</description>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<description>A comma separated list of HTTP verbs, using which a CORS request can be made.</description>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,PUT,DELETE,OPTIONS</param-value>
</init-param>
<init-param>
<description>A comma separated list of allowed headers when making a non simple CORS request.</description>
<param-name>cors.allowed.headers</param-name>
<param-value>Accept,Access-Control-Request-Headers,Access-Control-Request-Method,Cache-Control,Content-Type,Origin,Prefer,X-FHIR-Starter,X-Requested-With</param-value>
</init-param>
<init-param>
<description>A comma separated list non-standard response headers that will be exposed to XHR2 object.</description>
<param-name>cors.exposed.headers</param-name>
<param-value>Location,Content-Location</param-value>
</init-param>
<init-param>
<description>A flag that suggests if CORS is supported with cookies</description>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<description>A flag to control logging</description>
<param-name>cors.logging.enabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<description>Indicates how long (in seconds) the results of a preflight request can be cached in a preflight result cache.</description>
<param-name>cors.preflight.maxage</param-name>
<param-value>300</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--<filter>-->
<!--<filter-name>CORS Filter</filter-name>-->
<!--<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>-->
<!--<init-param>-->
<!--<description>A comma separated list of allowed origins. Note: An '*' cannot be used for an allowed origin when using credentials.</description>-->
<!--<param-name>cors.allowed.origins</param-name>-->
<!--<param-value>*</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<description>A comma separated list of HTTP verbs, using which a CORS request can be made.</description>-->
<!--<param-name>cors.allowed.methods</param-name>-->
<!--<param-value>GET,POST,PUT,DELETE,OPTIONS</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<description>A comma separated list of allowed headers when making a non simple CORS request.</description>-->
<!--<param-name>cors.allowed.headers</param-name>-->
<!--<param-value>Accept,Access-Control-Request-Headers,Access-Control-Request-Method,Cache-Control,Content-Type,Origin,Prefer,X-FHIR-Starter,X-Requested-With</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<description>A comma separated list non-standard response headers that will be exposed to XHR2 object.</description>-->
<!--<param-name>cors.exposed.headers</param-name>-->
<!--<param-value>Location,Content-Location</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<description>A flag that suggests if CORS is supported with cookies</description>-->
<!--<param-name>cors.support.credentials</param-name>-->
<!--<param-value>true</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<description>A flag to control logging</description>-->
<!--<param-name>cors.logging.enabled</param-name>-->
<!--<param-value>true</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<description>Indicates how long (in seconds) the results of a preflight request can be cached in a preflight result cache.</description>-->
<!--<param-name>cors.preflight.maxage</param-name>-->
<!--<param-value>300</param-value>-->
<!--</init-param>-->
<!--</filter>-->
<!--<filter-mapping>-->
<!--<filter-name>CORS Filter</filter-name>-->
<!--<url-pattern>/*</url-pattern>-->
<!--</filter-mapping>-->
</web-app>