A bit more cleanup for #646

This commit is contained in:
James 2017-05-22 08:13:00 -04:00
parent b71ba86a3a
commit a834770e38
16 changed files with 375 additions and 1175 deletions

View File

@ -29,7 +29,9 @@ import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.client.methods.*;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.hl7.fhir.instance.model.api.IBaseResource;
@ -45,7 +47,6 @@ import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.jpa.provider.ServletSubRequestDetails;
import ca.uhn.fhir.jpa.service.TMinusService;
import ca.uhn.fhir.jpa.thread.HttpRequestDstu2Job;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.Subscription;
@ -55,8 +56,9 @@ import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.*;
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
@ -94,7 +96,7 @@ public class RestHookSubscriptionDstu2Interceptor extends InterceptorAdapter imp
// run the subscriptions query and look for matches, add the id as part of the criteria to avoid getting matches of previous resources rather than the recent resource
String criteria = subscription.getCriteria();
criteria += "&_id=" + idType.getResourceType() + "/" + idType.getIdPart();
criteria = TMinusService.parseCriteria(criteria);
criteria = massageCriteria(criteria);
IBundleProvider results = getBundleProvider(criteria);
@ -220,6 +222,10 @@ public class RestHookSubscriptionDstu2Interceptor extends InterceptorAdapter imp
return null;
}
private String getResourceName(IBaseResource theResource) {
return myCtx.getResourceDefinition(theResource).getName();
}
/**
* Convert a resource into a string entity
*
@ -263,6 +269,13 @@ public class RestHookSubscriptionDstu2Interceptor extends InterceptorAdapter imp
return myNotifyOnDelete;
}
/**
* Subclasses may override
*/
protected String massageCriteria(String theCriteria) {
return theCriteria;
}
@PostConstruct
public void postConstruct() {
try {
@ -301,9 +314,8 @@ public class RestHookSubscriptionDstu2Interceptor extends InterceptorAdapter imp
Subscription subscription = (Subscription) theResource;
if (subscription.getChannel() != null
&& subscription.getChannel().getTypeElement().getValueAsEnum() == SubscriptionChannelTypeEnum.REST_HOOK
&& subscription.getStatusElement().getValueAsEnum() == SubscriptionStatusEnum.REQUESTED) {
subscription.setStatus(SubscriptionStatusEnum.ACTIVE);
mySubscriptionDao.update(subscription);
&& subscription.getStatusElement().getValueAsEnum() == SubscriptionStatusEnum.ACTIVE) {
removeLocalSubscription(subscription.getIdElement().getIdPart());
myRestHookSubscriptions.add(subscription);
ourLog.info("Subscription was added. Id: " + subscription.getId());
}
@ -328,7 +340,7 @@ public class RestHookSubscriptionDstu2Interceptor extends InterceptorAdapter imp
*/
@Override
public void resourceDeleted(RequestDetails theRequest, IBaseResource theResource) {
String resourceType = theRequest.getResourceName();
String resourceType = getResourceName(theResource);
IIdType idType = theResource.getIdElement();
if (resourceType.equals(Subscription.class.getSimpleName())) {
@ -347,7 +359,7 @@ public class RestHookSubscriptionDstu2Interceptor extends InterceptorAdapter imp
*/
@Override
public void resourceUpdated(RequestDetails theRequest, IBaseResource theResource) {
String resourceType = theRequest.getResourceName();
String resourceType = getResourceName(theResource);
IIdType idType = theResource.getIdElement();
ourLog.info("resource updated type: " + resourceType);

View File

@ -30,14 +30,11 @@ import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Subscription;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource;
@ -53,7 +50,6 @@ import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.jpa.provider.ServletSubRequestDetails;
import ca.uhn.fhir.jpa.service.TMinusService;
import ca.uhn.fhir.jpa.thread.HttpRequestDstu3Job;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
@ -67,22 +63,19 @@ import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter implements IServerOperationInterceptor {
private static volatile ExecutorService executor;
private static final Logger ourLog = LoggerFactory.getLogger(RestHookSubscriptionDstu3Interceptor.class);
private final static int MAX_THREADS = 1;
private static final Logger ourLog = LoggerFactory.getLogger(RestHookSubscriptionDstu3Interceptor.class);
@Autowired
@Qualifier("myObservationDaoDstu3")
private IFhirResourceDao<Observation> myObservationDao;
private FhirContext myCtx;
@Autowired
@Qualifier("mySubscriptionDaoDstu3")
private IFhirResourceDao<Subscription> mySubscriptionDao;
@Autowired
private FhirContext myCtx;
private boolean notifyOnDelete = false;
private final List<Subscription> restHookSubscriptions = new ArrayList<Subscription>();
private final List<Subscription> myRestHookSubscriptions = new ArrayList<Subscription>();
/**
* Check subscriptions and send notifications or payload
@ -92,34 +85,17 @@ public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter imp
* @param theOperation
*/
private void checkSubscriptions(IIdType idType, String resourceType, RestOperationTypeEnum theOperation) {
/*
* SearchParameterMap map = new SearchParameterMap();
* // map.add("_id", new StringParam("Observation/" + idType.getIdPart()));
* map.add("code", new TokenParam("SNOMED-CT", "1000000050"));
* //map.setLoadSynchronous(true);
* // Include include = new Include("nothing");
* // map.addInclude(include);
*
* RequestDetails req = new ServletSubRequestDetails();
* req.setSubRequest(true);
*
* IBundleProvider myBundle = myObservationDao.search(map, req);
* Observation myObservation = myObservationDao.read(idType);
*
* int mysize = myBundle.size();
* List result = myBundle.getResources(0, myBundle.size());
*/
for (Subscription subscription : restHookSubscriptions) {
for (Subscription subscription : myRestHookSubscriptions) {
// see if the criteria matches the created object
ourLog.info("subscription for " + resourceType + " with criteria " + subscription.getCriteria());
ourLog.info("Checking subscription {} for {} with criteria {}", subscription.getIdElement().getIdPart(), resourceType, subscription.getCriteria());
if (resourceType != null && subscription.getCriteria() != null && !subscription.getCriteria().startsWith(resourceType)) {
ourLog.info("Skipping subscription search for " + resourceType + " because it does not match the criteria " + subscription.getCriteria());
ourLog.info("Skipping subscription search for {} because it does not match the criteria {}", resourceType , subscription.getCriteria());
continue;
}
// run the subscriptions query and look for matches, add the id as part of the criteria to avoid getting matches of previous resources rather than the recent resource
String criteria = subscription.getCriteria();
criteria += "&_id=" + idType.getResourceType() + "/" + idType.getIdPart();
criteria = TMinusService.parseCriteria(criteria);
criteria = massageCriteria(criteria);
IBundleProvider results = getBundleProvider(criteria);
@ -217,24 +193,6 @@ public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter imp
return responseResults;
}
/**
* Get the encoding from the criteria or return JSON encoding if its not found
*
* @param criteria
* @return
*/
private EncodingEnum getEncoding(String criteria) {
// check criteria
String params = criteria.substring(criteria.indexOf('?') + 1);
List<NameValuePair> paramValues = URLEncodedUtils.parse(params, Constants.CHARSET_UTF8, '&');
for (NameValuePair nameValuePair : paramValues) {
if (Constants.PARAM_FORMAT.equals(nameValuePair.getName())) {
return EncodingEnum.forContentType(nameValuePair.getValue());
}
}
return EncodingEnum.JSON;
}
/**
* Get subscription from cache
*
@ -243,9 +201,9 @@ public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter imp
*/
private Subscription getLocalSubscription(String id) {
if (id != null && !id.trim().isEmpty()) {
int size = restHookSubscriptions.size();
int size = myRestHookSubscriptions.size();
if (size > 0) {
for (Subscription restHookSubscription : restHookSubscriptions) {
for (Subscription restHookSubscription : myRestHookSubscriptions) {
if (id.equals(restHookSubscription.getIdElement().getIdPart())) {
return restHookSubscription;
}
@ -256,6 +214,10 @@ public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter imp
return null;
}
private String getResourceName(IBaseResource theResource) {
return myCtx.getResourceDefinition(theResource).getName();
}
/**
* Convert a resource into a string entity
*
@ -292,7 +254,7 @@ public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter imp
List<IBaseResource> resourceList = subscriptionBundleList.getResources(0, subscriptionBundleList.size());
for (IBaseResource resource : resourceList) {
restHookSubscriptions.add((Subscription) resource);
myRestHookSubscriptions.add((Subscription) resource);
}
}
@ -300,6 +262,13 @@ public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter imp
return notifyOnDelete;
}
/**
* Subclasses may override
*/
protected String massageCriteria(String theCriteria) {
return theCriteria;
}
@PostConstruct
public void postConstruct() {
try {
@ -317,7 +286,7 @@ public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter imp
private void removeLocalSubscription(String subscriptionId) {
Subscription localSubscription = getLocalSubscription(subscriptionId);
if (localSubscription != null) {
restHookSubscriptions.remove(localSubscription);
myRestHookSubscriptions.remove(localSubscription);
ourLog.info("Subscription removed: " + subscriptionId);
} else {
ourLog.info("Subscription not found in local list. Subscription id: " + subscriptionId);
@ -338,11 +307,10 @@ public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter imp
Subscription subscription = (Subscription) theResource;
if (subscription.getChannel() != null
&& subscription.getChannel().getType() == Subscription.SubscriptionChannelType.RESTHOOK
&& subscription.getStatus() == Subscription.SubscriptionStatus.REQUESTED) {
subscription.setStatus(Subscription.SubscriptionStatus.ACTIVE);
mySubscriptionDao.update(subscription);
restHookSubscriptions.add(subscription);
ourLog.info("Subscription was added. Id: " + subscription.getId());
&& subscription.getStatus() == Subscription.SubscriptionStatus.ACTIVE) {
removeLocalSubscription(subscription.getIdElement().getIdPart());
myRestHookSubscriptions.add(subscription);
ourLog.info("Subscription was added, id: {} - Have {}", subscription.getIdElement().getIdPart(), myRestHookSubscriptions.size());
}
} else {
checkSubscriptions(idType, theRequest.getResourceName(), RestOperationTypeEnum.CREATE);
@ -365,7 +333,7 @@ public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter imp
*/
@Override
public void resourceDeleted(RequestDetails theRequest, IBaseResource theResource) {
String resourceType = theRequest.getResourceName();
String resourceType = getResourceName(theResource);
IIdType idType = theResource.getIdElement();
if (resourceType.equals(Subscription.class.getSimpleName())) {
@ -384,7 +352,7 @@ public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter imp
*/
@Override
public void resourceUpdated(RequestDetails theRequest, IBaseResource theResource) {
String resourceType = theRequest.getResourceName();
String resourceType = getResourceName(theResource);
IIdType idType = theResource.getIdElement();
ourLog.info("resource updated type: " + resourceType);
@ -395,8 +363,8 @@ public class RestHookSubscriptionDstu3Interceptor extends InterceptorAdapter imp
removeLocalSubscription(subscription.getIdElement().getIdPart());
if (subscription.getStatus() == Subscription.SubscriptionStatus.ACTIVE) {
restHookSubscriptions.add(subscription);
ourLog.info("Subscription was updated. Id: " + subscription.getId());
myRestHookSubscriptions.add(subscription);
ourLog.info("Subscription was updated, id: {} - Have {}", subscription.getIdElement().getIdPart(), myRestHookSubscriptions.size());
}
}
} else {

View File

@ -1,129 +0,0 @@
package ca.uhn.fhir.jpa.service;
/*-
* #%L
* HAPI FHIR JPA Server
* %%
* 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%
*/
import org.hl7.fhir.dstu3.model.DateTimeType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TMinusService {
private static final Logger logger = LoggerFactory.getLogger(TMinusService.class);
private static final String TMINUS = "Tminus";
private static final String WEEK = "w";
private static final String DAY = "d";
private static final String HOUR = "h";
private static final String MINUTE = "m";
private static final String SECOND = "s";
private static final long MINUTE_AS_MILLIS = 60 * 1000;
private static final long HOUR_AS_MILLIS = 60 * 60 * 1000;
private static final long DAY_AS_MILLIS = 24 * 60 * 60 * 1000;
private static final long WEEK_AS_MILLIS = 7 * 24 * 60 * 60 * 1000;
private static final Pattern TMINUS_PATTERN_REGEX = Pattern.compile("&([a-zA-Z0-9_]+)=Tminus([0-9]+)([wdhms])");
public static void main(String ... aaa){
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = criteria + "&effectiveDate=Tminus1m" + "&_format=xml";
Pattern myPattern = TMINUS_PATTERN_REGEX;
Matcher matcher = myPattern.matcher(payloadCriteria);
if (matcher.find()) {
String tMinus = matcher.group();
String tMinusVarName = tMinus.substring(1, tMinus.indexOf("="));
String tMinusValue = tMinus.substring(tMinus.indexOf(TMINUS) + TMINUS.length(), tMinus.length() - 1);
String tMinusPeriod = tMinus.substring(tMinus.length() - 1);
System.out.println(matcher.group());
System.out.println(tMinusVarName);
System.out.println(tMinusValue);
System.out.println(tMinusPeriod);
}else{
System.out.println("mmm");
}
}
public static String parseCriteria(String criteria) {
Matcher matcher = TMINUS_PATTERN_REGEX.matcher(criteria);
String response = criteria;
boolean matcherFound = false;
Date currentDate = new Date();
while (matcher.find()) {
matcherFound = true;
String tMinus = matcher.group();
String tMinusVarName = tMinus.substring(1, tMinus.indexOf("="));
String tMinusValue = tMinus.substring(tMinus.indexOf(TMINUS) + TMINUS.length(), tMinus.length() - 1);
String tMinusPeriod = tMinus.substring(tMinus.length() - 1);
long tMinusMillis = getTMinusValueAsLong(tMinusValue, tMinusPeriod);
String dateValue = getDateParameterValue(tMinusMillis, tMinusVarName, currentDate);
logger.debug("Tminus value replaced in criteria: " + criteria);
response = response.replace(tMinus, dateValue);
}
if(!matcherFound){
logger.debug("Tminus value not found in criteria: " + criteria);
}
return response;
}
private static String getDateParameterValue(long tMinusMillis, String tMinusVarName, Date currentDate){
Date lowerDate = new Date(currentDate.getTime() - tMinusMillis);
DateTimeType lowerDateTimeType = new DateTimeType(lowerDate);
DateTimeType currentDateTimeType = new DateTimeType(currentDate);
return "&" + tMinusVarName + "=%3E%3D" + lowerDateTimeType.getValueAsString() + "&" + tMinusVarName + "=%3C%3D" + currentDateTimeType.getValueAsString();
}
private static long getTMinusValueAsLong(String tMinusValue, String tMinusPeriod) {
long tMinusLongValue = Long.parseLong(tMinusValue);
long tMinusMillis;
if (WEEK.equals(tMinusPeriod)) {
tMinusMillis = WEEK_AS_MILLIS * tMinusLongValue;
} else if (DAY.equals(tMinusPeriod)) {
tMinusMillis = DAY_AS_MILLIS * tMinusLongValue;
} else if (HOUR.equals(tMinusPeriod)) {
tMinusMillis = HOUR_AS_MILLIS * tMinusLongValue;
} else if (MINUTE.equals(tMinusPeriod)) {
tMinusMillis = MINUTE_AS_MILLIS * tMinusLongValue;
} else if (SECOND.equals(tMinusPeriod)) {
tMinusMillis = 1000 * tMinusLongValue;
} else {
throw new IllegalArgumentException("Period not recognized: " + tMinusPeriod);
}
return tMinusMillis;
}
}

View File

@ -151,8 +151,10 @@ public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test {
ourRestHookSubscriptionInterceptor = wac.getBean(RestHookSubscriptionDstu3Interceptor.class);
ourClient = myFhirCtx.newRestfulGenericClient(ourServerBase);
ourClient.registerInterceptor(new LoggingInterceptor(true));
if (shouldLogClient()) {
ourClient.registerInterceptor(new LoggingInterceptor(true));
}
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connectionManager);
@ -162,6 +164,10 @@ public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test {
}
}
protected boolean shouldLogClient() {
return true;
}
protected List<String> toNameList(Bundle resp) {
List<String> names = new ArrayList<String>();
for (BundleEntryComponent next : resp.getEntry()) {

View File

@ -1,83 +0,0 @@
package ca.uhn.fhir.jpa.subscription;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
import ca.uhn.fhir.model.dstu2.resource.Observation;
import ca.uhn.fhir.model.dstu2.resource.Subscription;
import ca.uhn.fhir.rest.client.IGenericClient;
import ca.uhn.fhir.rest.gclient.IQuery;
import org.hl7.fhir.instance.model.api.IBaseCoding;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
@Ignore
public class RemoveDstu2TestIT {
private static Logger logger = LoggerFactory.getLogger(RemoveDstu2TestIT.class);
public static final int NUM_TO_DELETE_PER_QUERY = 100;
@Test
public void remove() {
IGenericClient client = FhirServiceUtil.getFhirDstu2Client();
deleteResources(Subscription.class, null, client);
deleteResources(Observation.class, null, client);
Bundle bundle = searchResources(Observation.class, null, NUM_TO_DELETE_PER_QUERY, client);
Assert.assertNotNull(bundle);
List<Bundle.Entry> entry = bundle.getEntry();
Assert.assertTrue(entry.isEmpty());
}
/**
* Delete resources from specified class and tag
*
* @param clazz
* @param tag
* @param <T>
*/
public static <T extends IBaseResource> void deleteResources(Class<T> clazz, IBaseCoding tag, IGenericClient client) {
Bundle bundle = searchResources(clazz, tag, NUM_TO_DELETE_PER_QUERY, client);
List<Bundle.Entry> bundleEntryComponents = bundle.getEntry();
while (bundleEntryComponents.size() > 0) {
for (Bundle.Entry bundleEntryComponent : bundleEntryComponents) {
IBaseResource resource = bundleEntryComponent.getResource();
String id = resource.getIdElement().getIdPart();
String className = clazz.getSimpleName();
logger.info("deleting resource------------------------------------------>" + className + "/" + id);
client.delete().resourceById(className, id).execute();
}
bundle = searchResources(clazz, tag, NUM_TO_DELETE_PER_QUERY, client);
bundleEntryComponents = bundle.getEntry();
}
}
/**
* Get resources from specified class and tag
*
* @param clazz
* @param tag
* @param limit
* @param <T>
* @return
*/
public static <T extends IBaseResource> Bundle searchResources(Class<T> clazz, IBaseCoding tag, Integer limit, IGenericClient client) {
IQuery iquery = client.search().forResource(clazz);
if (tag != null) {
iquery.withTag(tag.getSystem(), tag.getCode());
}
if (limit != null) {
iquery.count(limit);
}
return (Bundle) iquery.returnBundle(Bundle.class).execute();
}
}

View File

@ -1,91 +0,0 @@
package ca.uhn.fhir.jpa.subscription;
import ca.uhn.fhir.rest.client.IGenericClient;
import ca.uhn.fhir.rest.gclient.IQuery;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Subscription;
import org.hl7.fhir.instance.model.api.IBaseCoding;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
@Ignore
public class RemoveDstu3TestIT {
private static Logger logger = LoggerFactory.getLogger(RemoveDstu3TestIT.class);
public static final int NUM_TO_DELETE_PER_QUERY = 10000;
@Test
public void remove() {
IGenericClient client = FhirServiceUtil.getFhirDstu3Client();
deleteResources(Subscription.class, null, client);
deleteResources(Observation.class, null, client);
/* try {
//wait for cache to clear
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
*/
Bundle bundle = searchResources(Observation.class, null, NUM_TO_DELETE_PER_QUERY, client);
Assert.assertNotNull(bundle);
List<Bundle.BundleEntryComponent> entry = bundle.getEntry();
Assert.assertTrue(entry.isEmpty());
}
/**
* Delete resources from specified class and tag
*
* @param clazz
* @param tag
* @param <T>
*/
public static <T extends IBaseResource> void deleteResources(Class<T> clazz, IBaseCoding tag, IGenericClient client) {
Bundle bundle = searchResources(clazz, tag, NUM_TO_DELETE_PER_QUERY, client);
List<Bundle.BundleEntryComponent> bundleEntryComponents = bundle.getEntry();
// while (bundleEntryComponents.size() > 0) {
for (Bundle.BundleEntryComponent bundleEntryComponent : bundleEntryComponents) {
IBaseResource resource = bundleEntryComponent.getResource();
String id = resource.getIdElement().getIdPart();
String className = clazz.getSimpleName();
logger.info("deleting resource------------------------------------------>" + className + "/" + id);
client.delete().resourceById(className, id).execute();
}
// currently loops forever due to the FHIR server using a cached query result
// bundle = searchResources(clazz, tag, NUM_TO_DELETE_PER_QUERY, client);
// bundleEntryComponents = bundle.getEntry();
// }
}
/**
* Get resources from specified class and tag
*
* @param clazz
* @param tag
* @param limit
* @param <T>
* @return
*/
public static <T extends IBaseResource> Bundle searchResources(Class<T> clazz, IBaseCoding tag, Integer limit, IGenericClient client) {
IQuery iquery = client.search().forResource(clazz);
if (tag != null) {
iquery.withTag(tag.getSystem(), tag.getCode());
}
if (limit != null) {
iquery.count(limit);
}
return (Bundle) iquery.returnBundle(Bundle.class).execute();
}
}

View File

@ -1,130 +0,0 @@
package ca.uhn.fhir.jpa.subscription;
import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
import ca.uhn.fhir.model.dstu2.resource.Observation;
import ca.uhn.fhir.model.dstu2.resource.Subscription;
import ca.uhn.fhir.model.dstu2.valueset.ObservationStatusEnum;
import ca.uhn.fhir.model.dstu2.valueset.SubscriptionChannelTypeEnum;
import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.client.IGenericClient;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
/**
* Test the rest-hook subscriptions
*/
@Ignore
public class RestHookTestDstu2IT {
private static final Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSubscriptionWithSubscriptionIdDstu3Test.class);
private static String code = "1000000012";
private IGenericClient client = FhirServiceUtil.getFhirDstu2Client();
@Before
public void clean() {
RemoveDstu2TestIT.deleteResources(Subscription.class, null, client);
RemoveDstu2TestIT.deleteResources(Observation.class, null, client);
}
@Test
public void testRestHookSubscription() {
String payload = "application/json";
String endpoint = "http://localhost:10080/rest-hook";
String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml";
String criteria2 = "Observation?code=SNOMED-CT|" + code + "111&_format=xml";
Subscription subscription1 = createSubscription(criteria1, payload, endpoint, client);
Subscription subscription2 = createSubscription(criteria2, payload, endpoint, client);
Observation observationTemp1 = sendObservation(code, "SNOMED-CT", client);
Observation observation1 = client.read(Observation.class, observationTemp1.getId());
//Should see only one subscription notification
Subscription subscriptionTemp = client.read(Subscription.class, subscription2.getId());
Assert.assertNotNull(subscriptionTemp);
subscriptionTemp.setCriteria(criteria1);
client.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
Observation observationTemp2 = sendObservation(code, "SNOMED-CT", client);
Observation observation2 = client.read(Observation.class, observationTemp2.getId());
//Should see two subscription notifications
client.delete().resourceById("Subscription", subscription2.getId().getIdPart()).execute();
Observation observationTemp3 = sendObservation(code, "SNOMED-CT", client);
//Should see only one subscription notification
Observation observation3 = client.read(Observation.class, observationTemp1.getId());
CodeableConceptDt codeableConcept = new CodeableConceptDt();
observation3.setCode(codeableConcept);
CodingDt coding = codeableConcept.addCoding();
coding.setCode(code + "111");
coding.setSystem("SNOMED-CT");
client.update().resource(observation3).withId(observation3.getIdElement()).execute();
//Should see no subscription notification
Observation observation3a = client.read(Observation.class, observationTemp1.getId());
CodeableConceptDt codeableConcept2 = new CodeableConceptDt();
observation3a.setCode(codeableConcept2);
CodingDt coding2 = codeableConcept2.addCoding();
coding2.setCode(code);
coding2.setSystem("SNOMED-CT");
client.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
//Should see only one subscription notification
System.out.println("subscription id 1: " + subscription1.getId());
System.out.println("subscription id 2: " + subscription2.getId());
System.out.println("subscription temp id 2: " + subscriptionTemp.getId());
System.out.println("observation id 1: " + observation1.getId());
System.out.println("observation id 2: " + observation2.getId());
System.out.println("observation id 3: " + observation3.getId());
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
Assert.assertFalse(observation1.getId().isEmpty());
Assert.assertFalse(observation2.getId().isEmpty());
}
public Subscription createSubscription(String criteria, String payload, String endpoint, IGenericClient client) {
Subscription subscription = new Subscription();
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
subscription.setStatus(SubscriptionStatusEnum.REQUESTED);
subscription.setCriteria(criteria);
Subscription.Channel channel = new Subscription.Channel();
channel.setType(SubscriptionChannelTypeEnum.REST_HOOK);
channel.setPayload(payload);
channel.setEndpoint(endpoint);
subscription.setChannel(channel);
MethodOutcome methodOutcome = client.create().resource(subscription).execute();
subscription.setId(methodOutcome.getId().getIdPart());
return subscription;
}
public Observation sendObservation(String code, String system, IGenericClient client) {
Observation observation = new Observation();
CodeableConceptDt codeableConcept = new CodeableConceptDt();
observation.setCode(codeableConcept);
CodingDt coding = codeableConcept.addCoding();
coding.setCode(code);
coding.setSystem(system);
observation.setStatus(ObservationStatusEnum.FINAL);
MethodOutcome methodOutcome = client.create().resource(observation).execute();
String observationId = methodOutcome.getId().getIdPart();
observation.setId(observationId);
return observation;
}
}

View File

@ -68,7 +68,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
private Subscription createSubscription(String criteria, String payload, String endpoint) {
Subscription subscription = new Subscription();
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
subscription.setStatus(SubscriptionStatusEnum.REQUESTED);
subscription.setStatus(SubscriptionStatusEnum.ACTIVE);
subscription.setCriteria(criteria);
Channel channel = new Channel();

View File

@ -50,7 +50,6 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
@Before
public void beforeRegisterRestHookListener() {
// ourRestHookSubscriptionInterceptor.set
ourRestServer.registerInterceptor(ourRestHookSubscriptionInterceptor);
}
@ -63,7 +62,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
private Subscription createSubscription(String criteria, String payload, String endpoint) {
Subscription subscription = new Subscription();
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED);
subscription.setStatus(Subscription.SubscriptionStatus.ACTIVE);
subscription.setCriteria(criteria);
Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();

View File

@ -1,113 +0,0 @@
package ca.uhn.fhir.jpa.subscription;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.client.IGenericClient;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Subscription;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
/**
* Test the rest-hook subscriptions
*/
@Ignore
public class RestHookTestDstu3WithSubscriptionResponseCriteriaIT {
private static final Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSubscriptionWithSubscriptionIdDstu3Test.class);
@Test
public void testRestHookSubscription() {
IGenericClient client = FhirServiceUtil.getFhirDstu3Client();
String payload = "application/json";
String endpoint = "http://localhost:10080/rest-hook";
String code = "1000000050";
String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml";
String criteria2 = "Observation?code=SNOMED-CT|" + code + "111&_format=xml";
Subscription subscription1 = createSubscription(criteria1, "Observation?_format=xml", endpoint, client);
Subscription subscription2 = createSubscription(criteria2, payload, endpoint, client);
Observation observation1 = sendObservation(code, "SNOMED-CT", client);
//Should see a bundle
Subscription subscriptionTemp = client.read(Subscription.class, subscription2.getId());
Assert.assertNotNull(subscriptionTemp);
subscriptionTemp.setCriteria(criteria1);
client.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
Observation observation2 = sendObservation(code, "SNOMED-CT", client);
//Should see two subscription notifications
client.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute();
Observation observationTemp3 = sendObservation(code, "SNOMED-CT", client);
//Should see only one subscription notification
Observation observation3 = client.read(Observation.class, observationTemp3.getId());
CodeableConcept codeableConcept = new CodeableConcept();
observation3.setCode(codeableConcept);
Coding coding = codeableConcept.addCoding();
coding.setCode(code + "111");
coding.setSystem("SNOMED-CT");
client.update().resource(observation3).withId(observation3.getIdElement()).execute();
//Should see no subscription notification
Observation observation3a = client.read(Observation.class, observationTemp3.getId());
CodeableConcept codeableConcept1 = new CodeableConcept();
observation3a.setCode(codeableConcept1);
Coding coding1 = codeableConcept1.addCoding();
coding1.setCode(code);
coding1.setSystem("SNOMED-CT");
client.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
//Should see only one subscription notification
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
Assert.assertFalse(observation1.getId().isEmpty());
Assert.assertFalse(observation2.getId().isEmpty());
}
public Subscription createSubscription(String criteria, String payload, String endpoint, IGenericClient client) {
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(criteria);
Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();
channel.setType(Subscription.SubscriptionChannelType.RESTHOOK);
channel.setPayload(payload);
channel.setEndpoint(endpoint);
subscription.setChannel(channel);
MethodOutcome methodOutcome = client.create().resource(subscription).execute();
subscription.setId(methodOutcome.getId().getIdPart());
return subscription;
}
public Observation sendObservation(String code, String system, IGenericClient client) {
Observation observation = new Observation();
CodeableConcept codeableConcept = new CodeableConcept();
observation.setCode(codeableConcept);
Coding coding = codeableConcept.addCoding();
coding.setCode(code);
coding.setSystem(system);
observation.setStatus(Observation.ObservationStatus.FINAL);
MethodOutcome methodOutcome = client.create().resource(observation).execute();
String observationId = methodOutcome.getId().getIdPart();
observation.setId(observationId);
return observation;
}
}

View File

@ -0,0 +1,299 @@
package ca.uhn.fhir.jpa.subscription;
import static org.junit.Assert.*;
import java.util.List;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.*;
import com.google.common.collect.Lists;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.provider.dstu3.BaseResourceProviderDstu3Test;
import ca.uhn.fhir.jpa.testutil.RandomServerPortProvider;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
/**
* Test the rest-hook subscriptions
*/
public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends BaseResourceProviderDstu3Test {
private static List<Observation> ourCreatedObservations = Lists.newArrayList();
private static int ourListenerPort;
private static RestfulServer ourListenerRestServer;
private static Server ourListenerServer;
private static String ourListenerServerBase;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test.class);
private static List<Observation> ourUpdatedObservations = Lists.newArrayList();
@Override
protected boolean shouldLogClient() {
return false;
}
@After
public void afterUnregisterRestHookListener() {
myDaoConfig.setAllowMultipleDelete(true);
ourLog.info("Deleting all subscriptions");
ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute();
ourLog.info("Done deleting all subscriptions");
myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete());
myDaoConfig.getInterceptors().remove(ourRestHookSubscriptionInterceptor);
}
@Before
public void beforeRegisterRestHookListener() {
myDaoConfig.getInterceptors().add(ourRestHookSubscriptionInterceptor);
}
@Before
public void beforeReset() {
ourCreatedObservations.clear();
ourUpdatedObservations.clear();
}
private Subscription createSubscription(String criteria, String payload, String endpoint) {
Subscription subscription = new Subscription();
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
subscription.setStatus(Subscription.SubscriptionStatus.ACTIVE);
subscription.setCriteria(criteria);
Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();
channel.setType(Subscription.SubscriptionChannelType.RESTHOOK);
channel.setPayload(payload);
channel.setEndpoint(endpoint);
subscription.setChannel(channel);
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
subscription.setId(methodOutcome.getId().getIdPart());
return subscription;
}
private Observation sendObservation(String code, String system) {
Observation observation = new Observation();
CodeableConcept codeableConcept = new CodeableConcept();
observation.setCode(codeableConcept);
Coding coding = codeableConcept.addCoding();
coding.setCode(code);
coding.setSystem(system);
observation.setStatus(Observation.ObservationStatus.FINAL);
MethodOutcome methodOutcome = ourClient.create().resource(observation).execute();
String observationId = methodOutcome.getId().getIdPart();
observation.setId(observationId);
return observation;
}
@Test
public void testRestHookSubscriptionJson() throws Exception {
String payload = "application/json";
String code = "1000000050";
String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml";
String criteria2 = "Observation?code=SNOMED-CT|" + code + "111&_format=xml";
Subscription subscription1 = createSubscription(criteria1, payload, ourListenerServerBase);
Subscription subscription2 = createSubscription(criteria2, payload, ourListenerServerBase);
Observation observation1 = sendObservation(code, "SNOMED-CT");
// Should see 1 subscription notification
Thread.sleep(500);
assertEquals(1, ourCreatedObservations.size());
assertEquals(0, ourUpdatedObservations.size());
Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId());
Assert.assertNotNull(subscriptionTemp);
subscriptionTemp.setCriteria(criteria1);
ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
Observation observation2 = sendObservation(code, "SNOMED-CT");
// Should see two subscription notifications
Thread.sleep(500);
assertEquals(3, ourCreatedObservations.size());
assertEquals(0, ourUpdatedObservations.size());
ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute();
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
// Should see only one subscription notification
Thread.sleep(500);
assertEquals(4, ourCreatedObservations.size());
assertEquals(0, ourUpdatedObservations.size());
Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId());
CodeableConcept codeableConcept = new CodeableConcept();
observation3.setCode(codeableConcept);
Coding coding = codeableConcept.addCoding();
coding.setCode(code + "111");
coding.setSystem("SNOMED-CT");
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
// Should see no subscription notification
Thread.sleep(500);
assertEquals(4, ourCreatedObservations.size());
assertEquals(0, ourUpdatedObservations.size());
Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId());
CodeableConcept codeableConcept1 = new CodeableConcept();
observation3a.setCode(codeableConcept1);
Coding coding1 = codeableConcept1.addCoding();
coding1.setCode(code);
coding1.setSystem("SNOMED-CT");
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
// Should see only one subscription notification
Thread.sleep(500);
assertEquals(4, ourCreatedObservations.size());
assertEquals(1, ourUpdatedObservations.size());
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
Assert.assertFalse(observation1.getId().isEmpty());
Assert.assertFalse(observation2.getId().isEmpty());
}
@Test
public void testRestHookSubscriptionXml() throws Exception {
String payload = "application/xml";
String code = "1000000050";
String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml";
String criteria2 = "Observation?code=SNOMED-CT|" + code + "111&_format=xml";
Subscription subscription1 = createSubscription(criteria1, payload, ourListenerServerBase);
Subscription subscription2 = createSubscription(criteria2, payload, ourListenerServerBase);
Observation observation1 = sendObservation(code, "SNOMED-CT");
// Should see 1 subscription notification
Thread.sleep(500);
assertEquals(1, ourCreatedObservations.size());
assertEquals(0, ourUpdatedObservations.size());
Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId());
Assert.assertNotNull(subscriptionTemp);
subscriptionTemp.setCriteria(criteria1);
ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
Observation observation2 = sendObservation(code, "SNOMED-CT");
// Should see two subscription notifications
Thread.sleep(500);
assertEquals(3, ourCreatedObservations.size());
assertEquals(0, ourUpdatedObservations.size());
ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute();
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
// Should see only one subscription notification
Thread.sleep(500);
assertEquals(4, ourCreatedObservations.size());
assertEquals(0, ourUpdatedObservations.size());
Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId());
CodeableConcept codeableConcept = new CodeableConcept();
observation3.setCode(codeableConcept);
Coding coding = codeableConcept.addCoding();
coding.setCode(code + "111");
coding.setSystem("SNOMED-CT");
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
// Should see no subscription notification
Thread.sleep(500);
assertEquals(4, ourCreatedObservations.size());
assertEquals(0, ourUpdatedObservations.size());
Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId());
CodeableConcept codeableConcept1 = new CodeableConcept();
observation3a.setCode(codeableConcept1);
Coding coding1 = codeableConcept1.addCoding();
coding1.setCode(code);
coding1.setSystem("SNOMED-CT");
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
// Should see only one subscription notification
Thread.sleep(500);
assertEquals(4, ourCreatedObservations.size());
assertEquals(1, ourUpdatedObservations.size());
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
Assert.assertFalse(observation1.getId().isEmpty());
Assert.assertFalse(observation2.getId().isEmpty());
}
@BeforeClass
public static void startListenerServer() throws Exception {
ourListenerPort = RandomServerPortProvider.findFreePort();
ourListenerRestServer = new RestfulServer(FhirContext.forDstu3());
ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context";
ObservationListener obsListener = new ObservationListener();
ourListenerRestServer.setResourceProviders(obsListener);
ourListenerServer = new Server(ourListenerPort);
ServletContextHandler proxyHandler = new ServletContextHandler();
proxyHandler.setContextPath("/");
ServletHolder servletHolder = new ServletHolder();
servletHolder.setServlet(ourListenerRestServer);
proxyHandler.addServlet(servletHolder, "/fhir/context/*");
ourListenerServer.setHandler(proxyHandler);
ourListenerServer.start();
}
@AfterClass
public static void stopListenerServer() throws Exception {
ourListenerServer.stop();
}
public static class ObservationListener implements IResourceProvider {
@Create
public MethodOutcome create(@ResourceParam Observation theObservation) {
ourLog.info("Received Listener Create");
ourCreatedObservations.add(theObservation);
return new MethodOutcome(new IdType("Observation/1"), true);
}
@Override
public Class<? extends IBaseResource> getResourceType() {
return Observation.class;
}
@Update
public MethodOutcome update(@ResourceParam Observation theObservation) {
ourLog.info("Received Listener Update");
ourUpdatedObservations.add(theObservation);
return new MethodOutcome(new IdType("Observation/1"), false);
}
}
}

View File

@ -1,164 +0,0 @@
package ca.uhn.fhir.jpa.subscription;
import ca.uhn.fhir.model.dstu2.resource.Observation;
import ca.uhn.fhir.model.dstu2.resource.Subscription;
import ca.uhn.fhir.rest.client.IGenericClient;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
/**
* Must have a fhir server and web service endpoint to run these tests which subscribe to the fhir and receive notifications
*/
@Ignore
public class ResthookSubscriptionDstu2TestsIT {
private static IGenericClient client;
@BeforeClass
public static void init() {
client = FhirServiceUtil.getFhirDstu2Client();
}
@Before
public void clean() {
RemoveDstu2TestIT.deleteResources(Subscription.class, null, client);
RemoveDstu2TestIT.deleteResources(Observation.class, null, client);
}
@Test
public void testSubscriptionsWithoutPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
Observation loincObservation = FhirDstu2Util.getLoincObservation();
Observation snomedObservation = FhirDstu2Util.getSnomedObservation();
FhirDstu2Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(loincObservation, client); //should not trigger a notification
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
snomedObservation.setComments("mock change");
FhirServiceUtil.updateResource(snomedObservation, client); //should trigger one notification
FhirServiceUtil.deleteResource(snomedObservation.getIdElement().getIdPart(), Observation.class, client); //should trigger one notification
}
@Test
public void testSubscriptionsWithXmlPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
Observation snomedObservation = FhirDstu2Util.getSnomedObservation();
FhirDstu2Util.createSubscription(criteria, FhirServiceUtil.XML_PAYLOAD, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with xml resource in the body
snomedObservation.setComments("mock change");
FhirServiceUtil.updateResource(snomedObservation, client); //should trigger one notification with xml resource in the body
FhirServiceUtil.deleteResource(snomedObservation.getIdElement().getIdPart(), Observation.class, client); //should trigger one notification with xml resource in the body
}
@Test
public void testSubscriptionsWithJsonPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
Observation snomedObservation = FhirDstu2Util.getSnomedObservation();
FhirServiceUtil.createResource(snomedObservation, client);
FhirServiceUtil.createResource(snomedObservation, client);
FhirDstu2Util.createSubscription(criteria, FhirServiceUtil.JSON_PAYLOAD, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with json resource in the body
}
@Test
public void testSubscriptionsWithCustomXmlPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = "application/fhir+query/" + criteria + "&_format=xml";
Observation snomedObservation = FhirDstu2Util.getSnomedObservation();
FhirServiceUtil.createResource(snomedObservation, client);
FhirServiceUtil.createResource(snomedObservation, client);
FhirDstu2Util.createSubscription(criteria, payloadCriteria, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with xml bundle resource in the body containing three observations
}
@Test
public void testSubscriptionsWithCustomJsonPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = "application/fhir+query/" + criteria + "&_format=json";
Observation snomedObservation = FhirDstu2Util.getSnomedObservation();
FhirServiceUtil.createResource(snomedObservation, client);
FhirDstu2Util.createSubscription(criteria, payloadCriteria, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with JSON bundle resource in the body containing two observations
}
@Test
public void testSubscriptionsWithCustomDefaultPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = "application/fhir+query/" + criteria;
Observation snomedObservation = FhirDstu2Util.getSnomedObservation();
FhirDstu2Util.createSubscription(criteria, payloadCriteria, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with JSON bundle resource in the body containing one observations
}
@Test
public void testSubscriptionsWithCustomDefaultPayloadThatIsEmpty() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = "application/fhir+query/Observation?code=SNOMED-CT|" + code + "1111";
Observation snomedObservation = FhirDstu2Util.getSnomedObservation();
FhirDstu2Util.createSubscription(criteria, payloadCriteria, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with JSON bundle resource in the body containing no observations
}
/**
* Add a 5 second delay to the HttpRequestDstu3Job to test if threading is improving creation speed
*/
@Test
public void testSubscriptionsThreading() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
Observation snomedObservation = FhirDstu2Util.getSnomedObservation();
FhirDstu2Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
System.out.println("start");
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
System.out.println("done");
}
/**
* Add a 5 second delay to the HttpRequestDstu3Job to test if threading is improving creation speed
*/
@Test
public void testSubscriptionsThreading2() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
Observation snomedObservation = FhirDstu2Util.getSnomedObservation();
FhirDstu2Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirDstu2Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirDstu2Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirDstu2Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirDstu2Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
System.out.println("start");
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
System.out.println("done");
}
}

View File

@ -1,210 +0,0 @@
package ca.uhn.fhir.jpa.subscription;
import ca.uhn.fhir.rest.client.IGenericClient;
import org.hl7.fhir.dstu3.model.DateTimeType;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Subscription;
import org.junit.*;
/**
* Must have a fhir server and web service endpoint to run these
* tests which subscribe to the fhir and receive notifications
*/
@Ignore
public class ResthookSubscriptionDstu3TestsIT {
private static IGenericClient client;
@BeforeClass
public static void init() {
client = FhirServiceUtil.getFhirDstu3Client();
}
//@Before
//@Test
public void clean() {
RemoveDstu3TestIT.deleteResources(Subscription.class, null, client);
RemoveDstu3TestIT.deleteResources(Observation.class, null, client);
}
@Test
public void createSnomedObservation() {
String id = FhirServiceUtil.createResource(FhirDstu3Util.getSnomedObservation(), client);
FhirServiceUtil.deleteResource(id, Observation.class, client);
}
@Test
public void testSubscriptionsWithoutPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
Observation loincObservation = FhirDstu3Util.getLoincObservation();
Observation snomedObservation = FhirDstu3Util.getSnomedObservation();
// FhirDstu3Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(loincObservation, client); //should not trigger a notification
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
snomedObservation.setComment("mock change");
FhirServiceUtil.updateResource(snomedObservation, client); //should trigger one notification
FhirServiceUtil.deleteResource(snomedObservation.getIdElement().getIdPart(), Observation.class, client); //should trigger one notification
}
@Test
public void testSubscriptionsWithXmlPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
Observation snomedObservation = FhirDstu3Util.getSnomedObservation();
FhirDstu3Util.createSubscription(criteria, FhirServiceUtil.XML_PAYLOAD, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with xml resource in the body
snomedObservation.setComment("mock change");
FhirServiceUtil.updateResource(snomedObservation, client); //should trigger one notification with xml resource in the body
FhirServiceUtil.deleteResource(snomedObservation.getIdElement().getIdPart(), Observation.class, client); //should trigger one notification with xml resource in the body
}
@Test
public void testSubscriptionsWithJsonPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
Observation snomedObservation = FhirDstu3Util.getSnomedObservation();
FhirServiceUtil.createResource(snomedObservation, client);
FhirServiceUtil.createResource(snomedObservation, client);
FhirDstu3Util.createSubscription(criteria, FhirServiceUtil.JSON_PAYLOAD, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with json resource in the body
}
@Test
public void testSubscriptionsWithCustomXmlPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = "application/fhir+query/" + criteria + "&_format=xml";
Observation snomedObservation = FhirDstu3Util.getSnomedObservation();
FhirServiceUtil.createResource(snomedObservation, client);
FhirServiceUtil.createResource(snomedObservation, client);
FhirDstu3Util.createSubscription(criteria, payloadCriteria, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with xml bundle resource in the body containing three observations
}
@Test
public void testSubscriptionsWithCustomJsonPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = "application/fhir+query/" + criteria + "&_format=json";
Observation snomedObservation = FhirDstu3Util.getSnomedObservation();
FhirServiceUtil.createResource(snomedObservation, client);
FhirDstu3Util.createSubscription(criteria, payloadCriteria, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with JSON bundle resource in the body containing two observations
}
@Test
public void testSubscriptionsWithCustomDefaultPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = "application/fhir+query/" + criteria;
Observation snomedObservation = FhirDstu3Util.getSnomedObservation();
FhirDstu3Util.createSubscription(criteria, payloadCriteria, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with JSON bundle resource in the body containing one observations
}
@Test
public void testSubscriptionsWithCustomDefaultPayloadThatIsEmpty() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = "application/fhir+query/Observation?code=SNOMED-CT|" + code + "1111";
Observation snomedObservation = FhirDstu3Util.getSnomedObservation();
FhirDstu3Util.createSubscription(criteria, payloadCriteria, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with JSON bundle resource in the body containing no observations
}
/**
* Add a 5 second delay to the HttpRequestDstu3Job to test if threading is improving creation speed
*/
@Test
public void testSubscriptionsThreading() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
Observation snomedObservation = FhirDstu3Util.getSnomedObservation();
FhirDstu3Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
System.out.println("start");
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
System.out.println("done");
}
/**
* Add a 5 second delay to the HttpRequestDstu3Job to test if threading is improving creation speed
*/
@Test
public void testSubscriptionsThreading2() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
Observation snomedObservation = FhirDstu3Util.getSnomedObservation();
FhirDstu3Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirDstu3Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirDstu3Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirDstu3Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
FhirDstu3Util.createSubscription(criteria, null, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
System.out.println("start");
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification
System.out.println("done");
}
@Test
public void testSubscriptionsWithTMinusPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = "application/fhir+query/" + criteria + "&date=Tminus100s" + "&_format=xml";
Observation snomedObservation = FhirDstu3Util.getSnomedObservation();
DateTimeType dateTimeType = DateTimeType.now();
dateTimeType.setYear(2017);
dateTimeType.setMonth(2);
dateTimeType.setDay(1);
System.out.println(dateTimeType.getValueAsString());
snomedObservation.setEffective(dateTimeType);
FhirServiceUtil.createResource(snomedObservation, client);
snomedObservation.setEffective(DateTimeType.now());
FhirServiceUtil.createResource(snomedObservation, client);
FhirDstu3Util.createSubscription(criteria, payloadCriteria, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
snomedObservation.setEffective(DateTimeType.now());
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with xml bundle resource in the body containing two observations
}
@Test
public void testSubscriptionsWith2TMinusPayload() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = "application/fhir+query/" + criteria + "&date=Tminus2m" + "&_lastUpdated=Tminus20s" + "&_format=xml";
Observation snomedObservation = FhirDstu3Util.getSnomedObservation();
DateTimeType dateTimeType = DateTimeType.now();
dateTimeType.setYear(2017);
dateTimeType.setMonth(2);
dateTimeType.setDay(1);
System.out.println(dateTimeType.getValueAsString());
snomedObservation.setEffective(dateTimeType);
FhirServiceUtil.createResource(snomedObservation, client);
snomedObservation.setEffective(DateTimeType.now());
FhirServiceUtil.createResource(snomedObservation, client);
FhirDstu3Util.createSubscription(criteria, payloadCriteria, FhirServiceUtil.REST_HOOK_ENDPOINT, client);
snomedObservation.setEffective(DateTimeType.now());
FhirServiceUtil.createResource(snomedObservation, client); //should trigger one notification with xml bundle resource in the body containing two observations
}
}

View File

@ -1,164 +0,0 @@
package ca.uhn.fhir.jpa.subscription;
import ca.uhn.fhir.jpa.service.TMinusService;
import org.hl7.fhir.dstu3.model.DateTimeType;
import org.junit.Assert;
import org.junit.Test;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TminusTest {
@Test
public void testDays() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = criteria + "&effectiveDate=Tminus10d" + "&noEffectiveDate=Tminus1d" + "&_format=xml";
System.out.println(payloadCriteria);
System.out.println("Tminus10d with the current datetime - 10d");
payloadCriteria = TMinusService.parseCriteria(payloadCriteria);
System.out.println(payloadCriteria);
Assert.assertTrue(!payloadCriteria.contains("Tminus"));
}
@Test
public void testSeconds() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = criteria + "&date=Tminus200s" + "&_format=xml";
System.out.println(payloadCriteria);
System.out.println("replace Tminus200s with the current datetime - 200s");
payloadCriteria = TMinusService.parseCriteria(payloadCriteria);
System.out.println(payloadCriteria);
Assert.assertTrue(!payloadCriteria.contains("Tminus"));
}
@Test
public void testMinutes() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = criteria + "&effectiveDate=Tminus1m" + "&_format=xml";
System.out.println(payloadCriteria);
System.out.println("replace Tminus1m with the current datetime - 1m");
payloadCriteria = TMinusService.parseCriteria(payloadCriteria);
System.out.println(payloadCriteria);
Assert.assertTrue(!payloadCriteria.contains("Tminus"));
}
@Test
public void testMinutesAtTheEnd() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = criteria + "&date=Tminus1m";
System.out.println(payloadCriteria);
System.out.println("replace Tminus1m with the current datetime - 1m");
payloadCriteria = TMinusService.parseCriteria(payloadCriteria);
System.out.println(payloadCriteria);
Assert.assertTrue(!payloadCriteria.contains("Tminus"));
}
@Test
public void testWithoutTminus() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = criteria;
System.out.println(payloadCriteria);
System.out.println("test without a Tminus");
String newPayloadCriteria = TMinusService.parseCriteria(payloadCriteria);
System.out.println(payloadCriteria);
Assert.assertTrue(!payloadCriteria.contains("Tminus"));
Assert.assertTrue(payloadCriteria.equals(newPayloadCriteria));
}
@Test
public void testWithoutTminusUnits() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = criteria + "&date=Tminus1";
System.out.println(payloadCriteria);
System.out.println("check Tminus without units");
String newPayloadCriteria = TMinusService.parseCriteria(payloadCriteria);
System.out.println(payloadCriteria);
Assert.assertTrue(payloadCriteria.contains("Tminus"));
Assert.assertTrue(payloadCriteria.equals(newPayloadCriteria));
}
@Test
public void testWithoutTminusValue() {
String code = "1000000050";
String criteria = "Observation?code=SNOMED-CT|" + code;
String payloadCriteria = criteria + "&date=Tminusm";
System.out.println(payloadCriteria);
System.out.println("check Tminus without a value");
String newPayloadCriteria = TMinusService.parseCriteria(payloadCriteria);
System.out.println(payloadCriteria);
Assert.assertTrue(payloadCriteria.contains("Tminus"));
Assert.assertTrue(payloadCriteria.equals(newPayloadCriteria));
}
@Test
public void parsingCriteria() {
String criteria = "Observation?code=SNOMED-CT|1000000050&date=Tminus1d&_format=xml";
//String criteria = "Observation?code=SNOMED-CT|1000000050&date=%3E%3D2017-03-05T12:55:02-08:00&_format=xml";
String TMINUS = "Tminus";
String WEEK = "w";
String DAY = "d";
String HOUR = "h";
String MINUTE = "m";
String SECOND = "s";
long MINUTE_AS_MILLIS = 60 * 1000;
long HOUR_AS_MILLIS = 60 * 60 * 1000;
long DAY_AS_MILLIS = 24 * 60 * 60 * 1000;
long WEEK_AS_MILLIS = 7 * 24 * 60 * 60 * 1000;
Pattern pattern = Pattern.compile("Tminus([0-9]+)([wdhms])");
Matcher matcher = pattern.matcher(criteria);
if (matcher.find()) {
String tMinus = matcher.group();
String tMinusValue = tMinus.substring(TMINUS.length(), tMinus.length() - 1);
String tMinusPeriod = tMinus.substring(tMinus.length() - 1);
long tMinusLongValue = Long.parseLong(tMinusValue);
long tMinusMillis = 0L;
if (WEEK.equals(tMinusPeriod)) {
tMinusMillis = WEEK_AS_MILLIS * tMinusLongValue;
} else if (DAY.equals(tMinusPeriod)) {
tMinusMillis = DAY_AS_MILLIS * tMinusLongValue;
} else if (HOUR.equals(tMinusPeriod)) {
tMinusMillis = HOUR_AS_MILLIS * tMinusLongValue;
} else if (MINUTE.equals(tMinusPeriod)) {
tMinusMillis = MINUTE_AS_MILLIS * tMinusLongValue;
} else if (SECOND.equals(tMinusPeriod)) {
tMinusMillis = 1000 * tMinusLongValue;
} else {
throw new IllegalArgumentException("Period not recognized: " + tMinusPeriod);
}
Date currentDate = new Date();
Date lowerDate = new Date(currentDate.getTime() - tMinusMillis);
DateTimeType lowerDateTimeType = new DateTimeType(lowerDate);
DateTimeType currentDateTimeType = new DateTimeType(currentDate);
String dateValue = "%3E%3D" + lowerDateTimeType.getValueAsString() + "&date=%3C%3D" + currentDateTimeType.getValueAsString();
String formattedCriteria = criteria.replace(tMinus, dateValue);
System.out.println(tMinus);
System.out.println(tMinusValue);
System.out.println(tMinusPeriod);
System.out.println(tMinusMillis);
System.out.println(currentDate);
System.out.println(lowerDate);
System.out.println(lowerDateTimeType.getValueAsString());
System.out.println(formattedCriteria);
} else {
System.out.println("nothing");
}
}
}

View File

@ -26,7 +26,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import ca.uhn.fhir.util.RandomServerPortProvider;
import ca.uhn.fhir.util.PortUtil;
import ca.uhn.fhir.util.TestUtil;
public class IncomingRequestAddressStrategyTest {
@ -93,7 +93,7 @@ public class IncomingRequestAddressStrategyTest {
@Test
public void testUnderJettyWithContextPathServletRoot() throws Exception {
int port = RandomServerPortProvider.findFreePort();
int port = PortUtil.findFreePort();
String contextPath = "/ctx";
String servletPath = "/*";
@ -119,7 +119,7 @@ public class IncomingRequestAddressStrategyTest {
@Test
public void testUnderJettyWithContextPathServletRootContextOnly() throws Exception {
int port = RandomServerPortProvider.findFreePort();
int port = PortUtil.findFreePort();
String contextPath = "/ctx";
String servletPath = "/";
@ -147,7 +147,7 @@ public class IncomingRequestAddressStrategyTest {
@Test
public void testUnderJettyWithContextPathServletRoot2() throws Exception {
int port = RandomServerPortProvider.findFreePort();
int port = PortUtil.findFreePort();
String contextPath = "/ctx";
String servletPath = "/foo/bar/*"; // not /* but still this should work
@ -173,7 +173,7 @@ public class IncomingRequestAddressStrategyTest {
@Test
public void testUnderJettyWithContextPathServletPath() throws Exception {
int port = RandomServerPortProvider.findFreePort();
int port = PortUtil.findFreePort();
String contextPath = "/ctx";
String servletPath = "/servlet/*";
@ -195,7 +195,7 @@ public class IncomingRequestAddressStrategyTest {
@Test
public void testUnderJettyWithContextRootServletRoot() throws Exception {
int port = RandomServerPortProvider.findFreePort();
int port = PortUtil.findFreePort();
String contextPath = "/";
String servletPath = "/*";

View File

@ -26,7 +26,7 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.util.RandomServerPortProvider;
import ca.uhn.fhir.util.PortUtil;
import ca.uhn.fhir.util.TestUtil;
public class ServletContextParsingTest {
@ -53,7 +53,7 @@ public class ServletContextParsingTest {
HttpGet httpget = new HttpGet(url);
HttpResponse status = ourClient.execute(httpget);
String responseContent = IOUtils.toString(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent(), Constants.CHARSET_UTF8);
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info(responseContent);
}
@ -75,7 +75,7 @@ public class ServletContextParsingTest {
@Test
public void testUnderJettyWithContextPathServletRoot() throws Exception {
int port = RandomServerPortProvider.findFreePort();
int port = PortUtil.findFreePort();
String contextPath = "/ctx";
String servletPath = "/*";
@ -90,7 +90,7 @@ public class ServletContextParsingTest {
@Test
public void testUnderJettyWithContextPathServletRoot2() throws Exception {
int port = RandomServerPortProvider.findFreePort();
int port = PortUtil.findFreePort();
String contextPath = "/ctx";
String servletPath = "/foo/bar/*"; // not /* but still this should work
@ -104,7 +104,7 @@ public class ServletContextParsingTest {
@Test
public void testUnderJettyWithContextPathServletPath() throws Exception {
int port = RandomServerPortProvider.findFreePort();
int port = PortUtil.findFreePort();
String contextPath = "/ctx";
String servletPath = "/servlet/*";
@ -117,7 +117,7 @@ public class ServletContextParsingTest {
@Test
public void testUnderJettyWithMultiplePaths() throws Exception {
int port = RandomServerPortProvider.findFreePort();
int port = PortUtil.findFreePort();
myServer = new Server(port);
@ -139,7 +139,7 @@ public class ServletContextParsingTest {
@Test
public void testUnderJettyWithContextRootServletRoot() throws Exception {
int port = RandomServerPortProvider.findFreePort();
int port = PortUtil.findFreePort();
String contextPath = "/";
String servletPath = "/*";