- fixed issue on diff contextPath during running and testing, updated from "/hapi-fhir-jpaserver" to "/" and hapi.properties configs on server_address and server.base works out of the box with jetty
- replicated testWebsocketSubscription test from ExampleServerR4IT into ExampleServerDstu3IT
This commit is contained in:
14
README.md
14
README.md
@@ -20,7 +20,7 @@ mvn jetty:run
|
||||
|
||||
Then, browse to the following link to use the server:
|
||||
|
||||
[http://localhost:8080/hapi-fhir-jpaserver/](http://localhost:8080/hapi-fhir-jpaserver/)
|
||||
[http://localhost:8080/](http://localhost:8080/)
|
||||
|
||||
# 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).
|
||||
|
||||
[http://localhost:8080/hapi-fhir-jpaserver/](http://localhost:8080/hapi-fhir-jpaserver/)
|
||||
[http://localhost:8080/](http://localhost:8080/)
|
||||
|
||||
# Customizing The Web Testpage UI
|
||||
|
||||
@@ -67,10 +67,10 @@ 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
|
||||
* datasource.driver=com.mysql.cj.jdbc.Driver
|
||||
* datasource.url=jdbc:mysql://localhost:3306/hapi_dstu3
|
||||
* datasource.username=hapiDbUser
|
||||
* datasource.password=hapiDbPass
|
||||
* hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
|
||||
|
||||
It is important to use MySQL5Dialect when using MySQL version 5+.
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -204,7 +204,7 @@
|
||||
<version>9.4.8.v20180619</version>
|
||||
<configuration>
|
||||
<webApp>
|
||||
<contextPath>/hapi-fhir-jpaserver</contextPath>
|
||||
<contextPath>/</contextPath>
|
||||
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
|
||||
</webApp>
|
||||
</configuration>
|
||||
|
||||
@@ -6,17 +6,11 @@ fhir_version=DSTU3
|
||||
# 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
|
||||
# server, put the DNS name of that server here.
|
||||
#server_address=http://localhost/fhir/
|
||||
|
||||
# For Jetty, use this:
|
||||
server_address=http://localhost:8080/hapi-fhir-jpaserver/fhir/
|
||||
server_address=http://localhost:8080/fhir/
|
||||
|
||||
# This is the context path for the FHIR endpoint. If this is changed, the
|
||||
# setting above should also be changed.
|
||||
#server.base=/fhir
|
||||
|
||||
# For Jetty, use this:
|
||||
server.base=/hapi-fhir-jpaserver/fhir
|
||||
server.base=/fhir
|
||||
|
||||
default_encoding=JSON
|
||||
etag_support=ENABLED
|
||||
|
||||
@@ -1,15 +1,27 @@
|
||||
package ca.uhn.fhir.jpa.starter;
|
||||
|
||||
import static ca.uhn.fhir.util.TestUtil.waitForSize;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import ca.uhn.fhir.rest.api.CacheControlDirective;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.hl7.fhir.dstu3.model.Bundle;
|
||||
import org.hl7.fhir.dstu3.model.Observation;
|
||||
import org.hl7.fhir.dstu3.model.Patient;
|
||||
import org.hl7.fhir.dstu3.model.Subscription;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.*;
|
||||
|
||||
@@ -33,6 +45,7 @@ public class ExampleServerDstu3IT {
|
||||
HapiProperties.setProperty(HapiProperties.FHIR_VERSION, "DSTU3");
|
||||
HapiProperties.setProperty(HapiProperties.DATASOURCE_URL, "jdbc:derby:memory:dbr3;create=true");
|
||||
HapiProperties.setProperty(HapiProperties.TEST_PORT, Integer.toString(PortUtil.findFreePort()));
|
||||
HapiProperties.setProperty(HapiProperties.SUBSCRIPTION_WEBSOCKET_ENABLED, "true");
|
||||
ourCtx = FhirContext.forDstu3();
|
||||
ourPort = HapiProperties.getTestPort();
|
||||
}
|
||||
@@ -50,6 +63,64 @@ public class ExampleServerDstu3IT {
|
||||
assertEquals(methodName, pt2.getName().get(0).getFamily());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebsocketSubscription() throws Exception {
|
||||
/*
|
||||
* Create subscription
|
||||
*/
|
||||
Subscription subscription = new Subscription();
|
||||
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
||||
subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED);
|
||||
subscription.setCriteria("Observation?status=final");
|
||||
|
||||
Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();
|
||||
channel.setType(Subscription.SubscriptionChannelType.WEBSOCKET);
|
||||
channel.setPayload("application/json");
|
||||
subscription.setChannel(channel);
|
||||
|
||||
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
||||
IIdType mySubscriptionId = methodOutcome.getId();
|
||||
|
||||
// Wait for the subscription to be activated
|
||||
waitForSize(1, () -> ourClient.search().forResource(Subscription.class).where(Subscription.STATUS.exactly().code("active")).cacheControl(new CacheControlDirective().setNoCache(true)).returnBundle(Bundle.class).execute().getEntry().size());
|
||||
|
||||
/*
|
||||
* Attach websocket
|
||||
*/
|
||||
|
||||
WebSocketClient myWebSocketClient = new WebSocketClient();
|
||||
SocketImplementation mySocketImplementation = new SocketImplementation(mySubscriptionId.getIdPart(), EncodingEnum.JSON);
|
||||
|
||||
myWebSocketClient.start();
|
||||
URI echoUri = new URI("ws://localhost:" + ourPort + "/websocket");
|
||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
ourLog.info("Connecting to : {}", echoUri);
|
||||
Future<Session> connection = myWebSocketClient.connect(mySocketImplementation, echoUri, request);
|
||||
Session session = connection.get(2, TimeUnit.SECONDS);
|
||||
|
||||
ourLog.info("Connected to WS: {}", session.isOpen());
|
||||
|
||||
/*
|
||||
* Create a matching resource
|
||||
*/
|
||||
Observation obs = new Observation();
|
||||
obs.setStatus(Observation.ObservationStatus.FINAL);
|
||||
ourClient.create().resource(obs).execute();
|
||||
|
||||
// Give some time for the subscription to deliver
|
||||
Thread.sleep(2000);
|
||||
|
||||
/*
|
||||
* Ensure that we receive a ping on the websocket
|
||||
*/
|
||||
waitForSize(1, () -> mySocketImplementation.myPingCount);
|
||||
|
||||
/*
|
||||
* Clean up
|
||||
*/
|
||||
ourClient.delete().resourceById(mySubscriptionId).execute();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
ourServer.stop();
|
||||
|
||||
@@ -64,7 +64,6 @@ public class ExampleServerR4IT {
|
||||
assertEquals(methodName, pt2.getName().get(0).getFamily());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWebsocketSubscription() throws Exception {
|
||||
/*
|
||||
@@ -123,7 +122,6 @@ public class ExampleServerR4IT {
|
||||
ourClient.delete().resourceById(mySubscriptionId).execute();
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
ourServer.stop();
|
||||
|
||||
Reference in New Issue
Block a user