Work on interceptors

This commit is contained in:
James Agnew 2019-01-18 09:04:45 -05:00
parent 4367e340ae
commit 5ce9d444e9
5 changed files with 85 additions and 22 deletions

View File

@ -1 +0,0 @@
version=${project.version}

View File

@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.config;
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
import ca.uhn.fhir.validation.ResultSeverityEnum; import ca.uhn.fhir.validation.ResultSeverityEnum;
import net.ttddyy.dsproxy.listener.SingleQueryCountHolder; import net.ttddyy.dsproxy.listener.SingleQueryCountHolder;
import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel;
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder; import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;
import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -96,7 +97,7 @@ public class TestR4Config extends BaseJavaConfigR4 {
DataSource dataSource = ProxyDataSourceBuilder DataSource dataSource = ProxyDataSourceBuilder
.create(retVal) .create(retVal)
// .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL") .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL")
// .logSlowQueryBySlf4j(10, TimeUnit.SECONDS) // .logSlowQueryBySlf4j(10, TimeUnit.SECONDS)
// .countQuery(new ThreadQueryCountHolder()) // .countQuery(new ThreadQueryCountHolder())
.beforeQuery(new BlockLargeNumbersOfParamsListener()) .beforeQuery(new BlockLargeNumbersOfParamsListener())

View File

@ -945,6 +945,19 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
} }
} }
@Test
@Ignore
public void testQuery() throws IOException {
ourLog.info("** Performing Search");
HttpGet read = new HttpGet(ourServerBase + "/MedicationRequest?category=community&identifier=urn:oid:2.16.840.1.113883.3.7418.12.3%7C&intent=order&medication.code:text=calcitriol,hectorol,Zemplar,rocaltrol,vectical,vitamin%20D,doxercalciferol,paricalcitol&status=active,completed");
try (CloseableHttpResponse response = ourHttpClient.execute(read)) {
ourLog.info(response.toString());
}
ourLog.info("** DONE Performing Search");
}
@Test @Test
public void testDeleteResourceConditional1() throws IOException { public void testDeleteResourceConditional1() throws IOException {
String methodName = "testDeleteResourceConditional1"; String methodName = "testDeleteResourceConditional1";

View File

@ -31,6 +31,7 @@ import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.r4.model.EventDefinition; import org.hl7.fhir.r4.model.EventDefinition;
import org.hl7.fhir.r4.model.Subscription; import org.hl7.fhir.r4.model.Subscription;
import javax.annotation.Nonnull;
import java.io.Serializable; import java.io.Serializable;
import java.util.*; import java.util.*;
@ -65,6 +66,39 @@ public class CanonicalSubscription implements Serializable {
@JsonProperty("extensions") @JsonProperty("extensions")
private Map<String, String> myChannelExtensions; private Map<String, String> myChannelExtensions;
/**
* Constructor
*/
public CanonicalSubscription() {
super();
}
/**
* Copy Constructor
*/
public CanonicalSubscription(CanonicalSubscription theSubscription) {
myChannelExtensions = new HashMap<>(theSubscription.getChannelExtensions());
myChannelType = theSubscription.getChannelType();
myCriteriaString = theSubscription.getCriteriaString();
if (theSubscription.getEmailDetails() != null) {
myEmailDetails = new EmailDetails(theSubscription.getEmailDetails());
}
if (theSubscription.getRestHookDetails() != null) {
myRestHookDetails = new RestHookDetails(theSubscription.getRestHookDetails());
}
myHeaders = new ArrayList<>(theSubscription.getHeaders());
myEndpointUrl = theSubscription.getEndpointUrl();
myIdElement = theSubscription.getIdElementString();
myPayloadString = theSubscription.getPayloadString();
myStatus = theSubscription.getStatus();
// FIXME: is this constructor needed
// my
}
private Map<String, String> getChannelExtensions() {
return myChannelExtensions != null ? myChannelExtensions : Collections.emptyMap();
}
/** /**
* For now we're using the R4 TriggerDefinition, but this * For now we're using the R4 TriggerDefinition, but this
* may change in the future when things stabilize * may change in the future when things stabilize
@ -105,8 +139,9 @@ public class CanonicalSubscription implements Serializable {
myEndpointUrl = theEndpointUrl; myEndpointUrl = theEndpointUrl;
} }
@Nonnull
public List<String> getHeaders() { public List<String> getHeaders() {
return Collections.unmodifiableList(myHeaders); return myHeaders != null ? Collections.unmodifiableList(myHeaders) : Collections.emptyList();
} }
public void setHeaders(List<? extends IPrimitiveType<String>> theHeader) { public void setHeaders(List<? extends IPrimitiveType<String>> theHeader) {
@ -236,6 +271,21 @@ public class CanonicalSubscription implements Serializable {
@JsonProperty("subjectTemplate") @JsonProperty("subjectTemplate")
private String mySubjectTemplate; private String mySubjectTemplate;
/**
* Construcor
*/
public EmailDetails() {
super();
}
/**
* Copy Constructor
*/
public EmailDetails(EmailDetails theEmailDetails) {
myFrom = theEmailDetails.getFrom();
mySubjectTemplate = theEmailDetails.getSubjectTemplate();
}
public String getFrom() { public String getFrom() {
return myFrom; return myFrom;
} }
@ -261,6 +311,21 @@ public class CanonicalSubscription implements Serializable {
@JsonProperty("deliverLatestVersion") @JsonProperty("deliverLatestVersion")
private boolean myDeliverLatestVersion; private boolean myDeliverLatestVersion;
/**
* Constructor
*/
public RestHookDetails() {
super();
}
/**
* Copy constructor
*/
public RestHookDetails(RestHookDetails theRestHookDetails) {
myDeliverLatestVersion = theRestHookDetails.isDeliverLatestVersion();
myStripVersionId = theRestHookDetails.isStripVersionId();
}
public boolean isDeliverLatestVersion() { public boolean isDeliverLatestVersion() {
return myDeliverLatestVersion; return myDeliverLatestVersion;
} }

View File

@ -55,7 +55,9 @@ public class SubscriptionDeliveringRestHookSubscriber extends BaseSubscriptionDe
protected void deliverPayload(ResourceDeliveryMessage theMsg, CanonicalSubscription theSubscription, EncodingEnum thePayloadType, IGenericClient theClient) { protected void deliverPayload(ResourceDeliveryMessage theMsg, CanonicalSubscription theSubscription, EncodingEnum thePayloadType, IGenericClient theClient) {
IBaseResource payloadResource = getAndMassagePayload(theMsg, theSubscription); IBaseResource payloadResource = getAndMassagePayload(theMsg, theSubscription);
if (payloadResource == null) return; if (payloadResource == null) {
return;
}
doDelivery(theMsg, theSubscription, thePayloadType, theClient, payloadResource); doDelivery(theMsg, theSubscription, thePayloadType, theClient, payloadResource);
} }
@ -64,22 +66,6 @@ public class SubscriptionDeliveringRestHookSubscriber extends BaseSubscriptionDe
IClientExecutable<?, ?> operation; IClientExecutable<?, ?> operation;
switch (theMsg.getOperationType()) { switch (theMsg.getOperationType()) {
case CREATE: case CREATE:
if (thePayloadResource == null || thePayloadResource.isEmpty()) {
if (thePayloadType != null ) {
operation = theClient.create().resource(thePayloadResource);
} else {
sendNotification(theMsg);
return;
}
} else {
if (thePayloadType != null ) {
operation = theClient.update().resource(thePayloadResource);
} else {
sendNotification(theMsg);
return;
}
}
break;
case UPDATE: case UPDATE:
if (thePayloadResource == null || thePayloadResource.isEmpty()) { if (thePayloadResource == null || thePayloadResource.isEmpty()) {
if (thePayloadType != null ) { if (thePayloadType != null ) {
@ -179,10 +165,9 @@ public class SubscriptionDeliveringRestHookSubscriber extends BaseSubscriptionDe
/** /**
* Sends a POST notification without a payload * Sends a POST notification without a payload
* @param theMsg
*/ */
protected void sendNotification(ResourceDeliveryMessage theMsg) { protected void sendNotification(ResourceDeliveryMessage theMsg) {
Map<String, List<String>> params = new HashMap(); Map<String, List<String>> params = new HashMap<>();
List<Header> headers = new ArrayList<>(); List<Header> headers = new ArrayList<>();
StringBuilder url = new StringBuilder(theMsg.getSubscription().getEndpointUrl()); StringBuilder url = new StringBuilder(theMsg.getSubscription().getEndpointUrl());
IHttpClient client = myFhirContext.getRestfulClientFactory().getHttpClient(url, params, "", RequestTypeEnum.POST, headers); IHttpClient client = myFhirContext.getRestfulClientFactory().getHttpClient(url, params, "", RequestTypeEnum.POST, headers);