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.validation.ResultSeverityEnum;
import net.ttddyy.dsproxy.listener.SingleQueryCountHolder;
import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel;
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.context.annotation.Bean;
@ -96,7 +97,7 @@ public class TestR4Config extends BaseJavaConfigR4 {
DataSource dataSource = ProxyDataSourceBuilder
.create(retVal)
// .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL")
.logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL")
// .logSlowQueryBySlf4j(10, TimeUnit.SECONDS)
// .countQuery(new ThreadQueryCountHolder())
.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
public void testDeleteResourceConditional1() throws IOException {
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.Subscription;
import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.*;
@ -65,6 +66,39 @@ public class CanonicalSubscription implements Serializable {
@JsonProperty("extensions")
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
* may change in the future when things stabilize
@ -105,8 +139,9 @@ public class CanonicalSubscription implements Serializable {
myEndpointUrl = theEndpointUrl;
}
@Nonnull
public List<String> getHeaders() {
return Collections.unmodifiableList(myHeaders);
return myHeaders != null ? Collections.unmodifiableList(myHeaders) : Collections.emptyList();
}
public void setHeaders(List<? extends IPrimitiveType<String>> theHeader) {
@ -236,6 +271,21 @@ public class CanonicalSubscription implements Serializable {
@JsonProperty("subjectTemplate")
private String mySubjectTemplate;
/**
* Construcor
*/
public EmailDetails() {
super();
}
/**
* Copy Constructor
*/
public EmailDetails(EmailDetails theEmailDetails) {
myFrom = theEmailDetails.getFrom();
mySubjectTemplate = theEmailDetails.getSubjectTemplate();
}
public String getFrom() {
return myFrom;
}
@ -261,6 +311,21 @@ public class CanonicalSubscription implements Serializable {
@JsonProperty("deliverLatestVersion")
private boolean myDeliverLatestVersion;
/**
* Constructor
*/
public RestHookDetails() {
super();
}
/**
* Copy constructor
*/
public RestHookDetails(RestHookDetails theRestHookDetails) {
myDeliverLatestVersion = theRestHookDetails.isDeliverLatestVersion();
myStripVersionId = theRestHookDetails.isStripVersionId();
}
public boolean isDeliverLatestVersion() {
return myDeliverLatestVersion;
}

View File

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