- cors configuration via hapi properties based on change request 6858c0d799 (r266027967)

- reverted mysql as default and used derby based on change request 6858c0d799 (r266028296) and updated readme to include specifics on configuring mysql
- defaulted to jetty configs on hapi.properties so that this starter app will outright work without changing any configs with mvn jetty:run
- updated subscription configs as it doesn't match already active subscription on subsequent runs using mysql as db
- updated project based path resolution and removed unused file .keep_hapi-fhir-jpaserver-starter
This commit is contained in:
Jessie James Cosare
2019-03-16 16:20:47 +08:00
parent 6858c0d799
commit 1cfcaddda8
6 changed files with 57 additions and 45 deletions

View File

@@ -12,7 +12,7 @@ In order to use this sample, you should have:
# Running Locally # Running Locally
The easiest way to run this server is to run it directly in Maven using a built-in Jetty server. To do this, execute the following command: The easiest way to run this server is to run it directly in Maven using a built-in Jetty server. To do this, change `src/main/resources/hapi.properties` `server_address` and `server.base` with the values commented out as *For Jetty, use this* and then execute the following command:
``` ```
mvn jetty:run mvn jetty:run
@@ -20,7 +20,7 @@ mvn jetty:run
Then, browse to the following link to use the server: Then, browse to the following link to use the server:
[http://localhost:8080/](http://localhost:8080/) [http://localhost:8080/hapi-fhir-jpaserver/](http://localhost:8080/hapi-fhir-jpaserver/)
# Deploying to a Container # Deploying to a Container
@@ -40,7 +40,7 @@ This will create a file called `hapi-fhir-jpaserver.war` in your `target` direct
Again, browse to the following link to use the server (note that the port 8080 may not be correct depending on how your server is configured). Again, browse to the following link to use the server (note that the port 8080 may not be correct depending on how your server is configured).
[http://localhost:8080/](http://localhost:8080/) [http://localhost:8080/hapi-fhir-jpaserver/](http://localhost:8080/hapi-fhir-jpaserver/)
# Customizing The Web Testpage UI # Customizing The Web Testpage UI
@@ -56,13 +56,21 @@ Much of this HAPI starter project can be configured using the properties file in
## MySql ## MySql
To configure the starter app to with MySQL, use the commands below to add user and database: To configure the starter app to use MySQL, instead of the default Derby:
> Add user and database on your mysql server via mysql cli
``` ```
CREATE USER 'fhirUser'@'localhost' IDENTIFIED BY 'fhirPass'; CREATE USER 'hapiDbUser'@'localhost' IDENTIFIED BY 'hapiDbPass';
CREATE DATABASE fhir_r4; CREATE DATABASE hapi_dstu3;
GRANT ALL PRIVILEGES ON fhir_r4.* to 'fhirUser'@'localhost'; GRANT ALL PRIVILEGES ON hapi_dstu3.* to 'hapiDbUser'@'localhost';
FLUSH PRIVILEGES; FLUSH PRIVILEGES;
``` ```
> Update hapi.properties file to have the following
* @line34 datasource.driver=com.mysql.cj.jdbc.Driver
* @line35 datasource.url=jdbc:mysql://localhost:3306/hapi_dstu3
* @line36 datasource.username=hapiDbUser
* @line37 datasource.password=hapiDbPass
* @line41 hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
It is important to use MySQL5Dialect when using MySQL version 5+. It is important to use MySQL5Dialect when using MySQL version 5+.

View File

@@ -204,7 +204,7 @@
<version>9.4.8.v20180619</version> <version>9.4.8.v20180619</version>
<configuration> <configuration>
<webApp> <webApp>
<contextPath>/</contextPath> <contextPath>/hapi-fhir-jpaserver</contextPath>
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames> <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
</webApp> </webApp>
</configuration> </configuration>

View File

@@ -41,6 +41,8 @@ public class HapiProperties {
static final String SUBSCRIPTION_WEBSOCKET_ENABLED = "subscription.websocket.enabled"; static final String SUBSCRIPTION_WEBSOCKET_ENABLED = "subscription.websocket.enabled";
static final String TEST_PORT = "test.port"; 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"; static final String TESTER_CONFIG_REFUSE_TO_FETCH_THIRD_PARTY_URLS = "tester.config.refuse_to_fetch_third_party_urls";
static final String CORS_ENABLED = "cors.enabled";
static final String CORS_ALLOWED_ORIGIN = "cors.allowed_origin";
private static Properties properties; private static Properties properties;
@@ -255,6 +257,14 @@ public class HapiProperties {
return HapiProperties.getBooleanProperty(TESTER_CONFIG_REFUSE_TO_FETCH_THIRD_PARTY_URLS, false); return HapiProperties.getBooleanProperty(TESTER_CONFIG_REFUSE_TO_FETCH_THIRD_PARTY_URLS, false);
} }
public static Boolean getCorsEnabled() {
return HapiProperties.getBooleanProperty(CORS_ENABLED, true);
}
public static String getCorsAllowedOrigin() {
return HapiProperties.getProperty(CORS_ALLOWED_ORIGIN, "*");
}
public static String getServerBase() { public static String getServerBase() {
return HapiProperties.getProperty(SERVER_BASE, "/fhir"); return HapiProperties.getProperty(SERVER_BASE, "/fhir");
} }

View File

@@ -5,7 +5,6 @@ import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.model.interceptor.executor.InterceptorService; import ca.uhn.fhir.jpa.model.interceptor.executor.InterceptorService;
import ca.uhn.fhir.jpa.model.interceptor.api.IInterceptorRegistry;
import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2; import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2; import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2;
import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider; import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider;
@@ -18,8 +17,6 @@ import ca.uhn.fhir.jpa.provider.r4.TerminologyUploaderProviderR4;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider; import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
import ca.uhn.fhir.jpa.subscription.SubscriptionInterceptorLoader; import ca.uhn.fhir.jpa.subscription.SubscriptionInterceptorLoader;
import ca.uhn.fhir.jpa.subscription.module.interceptor.SubscriptionDebugLogInterceptor; import ca.uhn.fhir.jpa.subscription.module.interceptor.SubscriptionDebugLogInterceptor;
import ca.uhn.fhir.jpa.subscription.SubscriptionActivatingInterceptor;
import ca.uhn.fhir.jpa.subscription.SubscriptionMatcherInterceptor;
import ca.uhn.fhir.model.dstu2.composite.MetaDt; import ca.uhn.fhir.model.dstu2.composite.MetaDt;
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy; import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy;
@@ -175,6 +172,7 @@ public class JpaRestfulServer extends RestfulServer {
// Define your CORS configuration. This is an example // Define your CORS configuration. This is an example
// showing a typical setup. You should customize this // showing a typical setup. You should customize this
// to your specific needs // to your specific needs
if(HapiProperties.getCorsEnabled()) {
CorsConfiguration config = new CorsConfiguration(); CorsConfiguration config = new CorsConfiguration();
config.addAllowedHeader("x-fhir-starter"); config.addAllowedHeader("x-fhir-starter");
config.addAllowedHeader("Origin"); config.addAllowedHeader("Origin");
@@ -182,7 +180,7 @@ public class JpaRestfulServer extends RestfulServer {
config.addAllowedHeader("X-Requested-With"); config.addAllowedHeader("X-Requested-With");
config.addAllowedHeader("Content-Type"); config.addAllowedHeader("Content-Type");
config.addAllowedOrigin("*"); config.addAllowedOrigin(HapiProperties.getCorsAllowedOrigin());
config.addExposedHeader("Location"); config.addExposedHeader("Location");
config.addExposedHeader("Content-Location"); config.addExposedHeader("Content-Location");
@@ -191,13 +189,13 @@ public class JpaRestfulServer extends RestfulServer {
// Create the interceptor and register it // Create the interceptor and register it
CorsInterceptor interceptor = new CorsInterceptor(config); CorsInterceptor interceptor = new CorsInterceptor(config);
registerInterceptor(interceptor); registerInterceptor(interceptor);
}
// If subscriptions are enabled, we want to register the interceptor that // If subscriptions are enabled, we want to register the interceptor that
// will activate them and match results against them // will activate them and match results against them
if (HapiProperties.getSubscriptionWebsocketEnabled() || if (HapiProperties.getSubscriptionWebsocketEnabled() ||
HapiProperties.getSubscriptionEmailEnabled() || HapiProperties.getSubscriptionEmailEnabled() ||
HapiProperties.getSubscriptionRestHookEnabled()) { HapiProperties.getSubscriptionRestHookEnabled()) {
// Loads subscription interceptors (SubscriptionActivatingInterceptor, SubscriptionMatcherInterceptor) // Loads subscription interceptors (SubscriptionActivatingInterceptor, SubscriptionMatcherInterceptor)
// with activation of scheduled subscription // with activation of scheduled subscription
SubscriptionInterceptorLoader subscriptionInterceptorLoader = appCtx.getBean(SubscriptionInterceptorLoader.class); SubscriptionInterceptorLoader subscriptionInterceptorLoader = appCtx.getBean(SubscriptionInterceptorLoader.class);
@@ -206,7 +204,6 @@ public class JpaRestfulServer extends RestfulServer {
// Subscription debug logging // Subscription debug logging
InterceptorService interceptorService = (InterceptorService) appCtx.getBean("interceptorService"); InterceptorService interceptorService = (InterceptorService) appCtx.getBean("interceptorService");
interceptorService.registerInterceptor(new SubscriptionDebugLogInterceptor()); interceptorService.registerInterceptor(new SubscriptionDebugLogInterceptor());
} }
} }

View File

@@ -1,27 +1,29 @@
# Adjust this to set the version of FHIR supported by this server. See # Adjust this to set the version of FHIR supported by this server. See
# FhirVersionEnum for a list of available constants. # FhirVersionEnum for a list of available constants.
fhir_version=R4 fhir_version=DSTU3
# This is the address that the FHIR server will report as its own address. # 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 # If this server will be deployed (for example) to an internet accessible
# server, put the DNS name of that server here. # server, put the DNS name of that server here.
server_address=http://localhost:8080/fhir/ #server_address=http://localhost/fhir/
# For Jetty, use this: # For Jetty, use this:
# server_address=http://localhost:8080/hapi-fhir-jpaserver/fhir/ server_address=http://localhost:8080/hapi-fhir-jpaserver/fhir/
# This is the context path for the FHIR endpoint. If this is changed, the # This is the context path for the FHIR endpoint. If this is changed, the
# setting above should also be changed. # setting above should also be changed.
server.base=/fhir #server.base=/fhir
# For Jetty, use this: # For Jetty, use this:
# server.base=/hapi-fhir-jpaserver/fhir server.base=/hapi-fhir-jpaserver/fhir
default_encoding=JSON default_encoding=JSON
etag_support=ENABLED etag_support=ENABLED
default_page_size=20 default_page_size=20
max_page_size=200 max_page_size=200
allow_override_default_search_params=true
allow_contains_searches=true
allow_multiple_delete=true allow_multiple_delete=true
allow_external_references=true allow_external_references=true
allow_placeholder_references=true allow_placeholder_references=true
@@ -31,14 +33,14 @@ 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.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.error_format=ERROR - ${requestVerb} ${requestUrl}
logger.log_exceptions=true logger.log_exceptions=true
datasource.driver=com.mysql.cj.jdbc.Driver datasource.driver=org.apache.derby.jdbc.EmbeddedDriver
datasource.url=jdbc:mysql://localhost:3306/fhir_r4 datasource.url=jdbc:derby:directory:target/jpaserver_derby_files;create=true
datasource.username=fhirUser datasource.username=
datasource.password=fhirPass datasource.password=
server.name=Local Tester server.name=Local Tester
server.id=home server.id=home
test.port= test.port=
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect hibernate.dialect=ca.uhn.fhir.jpa.util.DerbyTenSevenHapiFhirDialect
hibernate.search.model_mapping=ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory hibernate.search.model_mapping=ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory
hibernate.format_sql=false hibernate.format_sql=false
hibernate.show_sql=false hibernate.show_sql=false
@@ -52,7 +54,8 @@ hibernate.search.default.directory_provider=filesystem
hibernate.search.default.indexBase=target/lucenefiles hibernate.search.default.indexBase=target/lucenefiles
hibernate.search.lucene_version=LUCENE_CURRENT hibernate.search.lucene_version=LUCENE_CURRENT
tester.config.refuse_to_fetch_third_party_urls=false tester.config.refuse_to_fetch_third_party_urls=false
cors.enabled=true
cors.allowed_origin=*
################################################## ##################################################
# Subscriptions # Subscriptions

View File

@@ -22,9 +22,9 @@ import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.file.Paths;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -131,13 +131,7 @@ public class ExampleServerR4IT {
@BeforeClass @BeforeClass
public static void beforeClass() throws Exception { public static void beforeClass() throws Exception {
/* String path = Paths.get("").toAbsolutePath().toString();
* This runs under maven, and I'm not sure how else to figure out the target directory from code..
*/
String path = ExampleServerR4IT.class.getClassLoader().getResource(".keep_hapi-fhir-jpaserver-starter").getPath();
path = new File(path).getParent();
path = new File(path).getParent();
path = new File(path).getParent();
ourLog.info("Project base path is: {}", path); ourLog.info("Project base path is: {}", path);