Merge branch 'master' of github.com:jamesagnew/hapi-fhir
This commit is contained in:
commit
ad12ee4a5c
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
release-date: "2020-08-13"
|
||||||
|
codename: "Manticore"
|
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
- item:
|
||||||
|
type: "add"
|
||||||
|
title: "The version of a few dependencies have been bumped to the latest versions
|
||||||
|
(dependent HAPI modules listed in brackets):
|
||||||
|
<ul>
|
||||||
|
<li>Flyway (JPA): 6.4.1-> 6.5.4</li>
|
||||||
|
</ul>"
|
|
@ -34,8 +34,9 @@ import java.util.Collection;
|
||||||
* time to time, even within minor point releases.
|
* time to time, even within minor point releases.
|
||||||
*/
|
*/
|
||||||
public interface IDao {
|
public interface IDao {
|
||||||
|
String RESOURCE_PID_KEY = "RESOURCE_PID";
|
||||||
|
|
||||||
MetadataKeyResourcePid RESOURCE_PID = new MetadataKeyResourcePid("RESOURCE_PID");
|
MetadataKeyResourcePid RESOURCE_PID = new MetadataKeyResourcePid(RESOURCE_PID_KEY);
|
||||||
|
|
||||||
MetadataKeyCurrentlyReindexing CURRENTLY_REINDEXING = new MetadataKeyCurrentlyReindexing("CURRENTLY_REINDEXING");
|
MetadataKeyCurrentlyReindexing CURRENTLY_REINDEXING = new MetadataKeyCurrentlyReindexing("CURRENTLY_REINDEXING");
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,6 @@ import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
|
import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
|
|
||||||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
||||||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
||||||
|
@ -114,10 +113,8 @@ import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.transaction.support.TransactionCallback;
|
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
@ -636,7 +633,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> extends BaseStora
|
||||||
ResourceMetadataKeyEnum.VERSION.put(res, Long.toString(theEntity.getVersion()));
|
ResourceMetadataKeyEnum.VERSION.put(res, Long.toString(theEntity.getVersion()));
|
||||||
ResourceMetadataKeyEnum.PUBLISHED.put(res, theEntity.getPublished());
|
ResourceMetadataKeyEnum.PUBLISHED.put(res, theEntity.getPublished());
|
||||||
ResourceMetadataKeyEnum.UPDATED.put(res, theEntity.getUpdated());
|
ResourceMetadataKeyEnum.UPDATED.put(res, theEntity.getUpdated());
|
||||||
IDao.RESOURCE_PID.put(res, theEntity.getId());
|
IDao.RESOURCE_PID.put(res, theEntity.getResourceId());
|
||||||
|
|
||||||
Collection<? extends BaseTag> tags = theTagList;
|
Collection<? extends BaseTag> tags = theTagList;
|
||||||
if (theEntity.isHasTags()) {
|
if (theEntity.isHasTags()) {
|
||||||
|
@ -708,7 +705,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> extends BaseStora
|
||||||
res.setId(res.getIdElement().withVersion(theVersion.toString()));
|
res.setId(res.getIdElement().withVersion(theVersion.toString()));
|
||||||
|
|
||||||
res.getMeta().setLastUpdated(theEntity.getUpdatedDate());
|
res.getMeta().setLastUpdated(theEntity.getUpdatedDate());
|
||||||
IDao.RESOURCE_PID.put(res, theEntity.getId());
|
IDao.RESOURCE_PID.put(res, theEntity.getResourceId());
|
||||||
|
|
||||||
Collection<? extends BaseTag> tags = theTagList;
|
Collection<? extends BaseTag> tags = theTagList;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,25 @@
|
||||||
package ca.uhn.fhir.jpa.provider.r4;
|
package ca.uhn.fhir.jpa.provider.r4;
|
||||||
|
|
||||||
import ca.uhn.fhir.interceptor.api.Pointcut;
|
import ca.uhn.fhir.interceptor.api.Pointcut;
|
||||||
|
import ca.uhn.fhir.jpa.api.config.DaoConfig;
|
||||||
|
import ca.uhn.fhir.jpa.api.dao.IDao;
|
||||||
|
import ca.uhn.fhir.jpa.dao.index.IdHelperService;
|
||||||
|
import ca.uhn.fhir.jpa.model.util.JpaConstants;
|
||||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
|
import org.hl7.fhir.r4.model.BooleanType;
|
||||||
|
import org.hl7.fhir.r4.model.Parameters;
|
||||||
import org.hl7.fhir.r4.model.Patient;
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
@ -15,16 +27,24 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
|
public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
|
||||||
|
private static final Logger ourLog = LoggerFactory.getLogger(HookInterceptorR4Test.class);
|
||||||
|
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(HookInterceptorR4Test.class);
|
@Autowired
|
||||||
|
IdHelperService myIdHelperService;
|
||||||
|
|
||||||
// @Override
|
@BeforeEach
|
||||||
// @AfterEach
|
public void before() throws Exception {
|
||||||
// public void after( ) throws Exception {
|
super.before();
|
||||||
// super.after();
|
|
||||||
//
|
myDaoConfig.setExpungeEnabled(true);
|
||||||
// myInterceptorRegistry.unregisterAllInterceptors();
|
}
|
||||||
// }
|
|
||||||
|
@AfterEach
|
||||||
|
public void after() throws Exception {
|
||||||
|
myDaoConfig.setExpungeEnabled(new DaoConfig().isExpungeEnabled());
|
||||||
|
|
||||||
|
super.after();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOP_PRESTORAGE_RESOURCE_CREATED_ModifyResource() {
|
public void testOP_PRESTORAGE_RESOURCE_CREATED_ModifyResource() {
|
||||||
|
@ -69,7 +89,7 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
|
||||||
AtomicLong pid = new AtomicLong();
|
AtomicLong pid = new AtomicLong();
|
||||||
myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRECOMMIT_RESOURCE_CREATED, (thePointcut, t) -> {
|
myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRECOMMIT_RESOURCE_CREATED, (thePointcut, t) -> {
|
||||||
IAnyResource resource = (IAnyResource) t.get(IBaseResource.class, 0);
|
IAnyResource resource = (IAnyResource) t.get(IBaseResource.class, 0);
|
||||||
Long resourcePid = (Long) resource.getUserData("RESOURCE_PID");
|
Long resourcePid = (Long) resource.getUserData(IDao.RESOURCE_PID_KEY);
|
||||||
assertNotNull(resourcePid, "Expecting RESOURCE_PID to be set on resource user data.");
|
assertNotNull(resourcePid, "Expecting RESOURCE_PID to be set on resource user data.");
|
||||||
pid.set(resourcePid);
|
pid.set(resourcePid);
|
||||||
});
|
});
|
||||||
|
@ -77,6 +97,72 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
|
||||||
assertTrue(pid.get() > 0);
|
assertTrue(pid.get() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSTORAGE_PRECOMMIT_RESOURCE_CREATED_hasCorrectPid() {
|
||||||
|
AtomicLong pid = new AtomicLong();
|
||||||
|
myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRECOMMIT_RESOURCE_CREATED, (thePointcut, t) -> {
|
||||||
|
IAnyResource resource = (IAnyResource) t.get(IBaseResource.class, 0);
|
||||||
|
Long resourcePid = (Long) resource.getUserData(IDao.RESOURCE_PID_KEY);
|
||||||
|
assertNotNull(resourcePid, "Expecting RESOURCE_PID to be set on resource user data.");
|
||||||
|
pid.set(resourcePid);
|
||||||
|
});
|
||||||
|
IIdType savedPatientId = myClient.create().resource(new Patient()).execute().getId();
|
||||||
|
Long savedPatientPid = myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong();
|
||||||
|
assertEquals(savedPatientPid.longValue(), pid.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSTORAGE_PRESTORAGE_EXPUNGE_RESOURCE_hasCorrectPid() {
|
||||||
|
AtomicLong pid = new AtomicLong();
|
||||||
|
myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRESTORAGE_EXPUNGE_RESOURCE, (thePointcut, t) -> {
|
||||||
|
IAnyResource resource = (IAnyResource) t.get(IBaseResource.class, 0);
|
||||||
|
Long resourcePid = (Long) resource.getUserData(IDao.RESOURCE_PID_KEY);
|
||||||
|
assertNotNull(resourcePid, "Expecting RESOURCE_PID to be set on resource user data.");
|
||||||
|
pid.set(resourcePid);
|
||||||
|
});
|
||||||
|
IIdType savedPatientId = myClient.create().resource(new Patient()).execute().getId();
|
||||||
|
Long savedPatientPid = myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong();
|
||||||
|
|
||||||
|
myClient.delete().resourceById(savedPatientId).execute();
|
||||||
|
Parameters parameters = new Parameters();
|
||||||
|
|
||||||
|
parameters.addParameter().setName(JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES).setValue(new BooleanType(true));
|
||||||
|
myClient
|
||||||
|
.operation()
|
||||||
|
.onInstance(savedPatientId)
|
||||||
|
.named(JpaConstants.OPERATION_EXPUNGE)
|
||||||
|
.withParameters(parameters)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
assertEquals(savedPatientPid.longValue(), pid.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSTORAGE_PRECOMMIT_RESOURCE_UPDATED_hasCorrectPid() {
|
||||||
|
AtomicLong pidOld = new AtomicLong();
|
||||||
|
AtomicLong pidNew = new AtomicLong();
|
||||||
|
Patient patient = new Patient();
|
||||||
|
IIdType savedPatientId = myClient.create().resource(patient).execute().getId();
|
||||||
|
patient.setId(savedPatientId);
|
||||||
|
myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRECOMMIT_RESOURCE_UPDATED, (thePointcut, t) -> {
|
||||||
|
IAnyResource resourceOld = (IAnyResource) t.get(IBaseResource.class, 0);
|
||||||
|
IAnyResource resourceNew = (IAnyResource) t.get(IBaseResource.class, 1);
|
||||||
|
Long resourceOldPid = (Long) resourceOld.getUserData(IDao.RESOURCE_PID_KEY);
|
||||||
|
Long resourceNewPid = (Long) resourceNew.getUserData(IDao.RESOURCE_PID_KEY);
|
||||||
|
assertNotNull(resourceOldPid, "Expecting RESOURCE_PID to be set on resource user data.");
|
||||||
|
assertNotNull(resourceNewPid, "Expecting RESOURCE_PID to be set on resource user data.");
|
||||||
|
pidOld.set(resourceOldPid);
|
||||||
|
pidNew.set(resourceNewPid);
|
||||||
|
});
|
||||||
|
patient.setActive(true);
|
||||||
|
myClient.update().resource(patient).execute();
|
||||||
|
Long savedPatientPid = myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong();
|
||||||
|
assertEquals(savedPatientPid.longValue(), pidOld.get());
|
||||||
|
assertEquals(savedPatientPid.longValue(), pidNew.get());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSTORAGE_PRECOMMIT_RESOURCE_UPDATED_hasPid() {
|
public void testSTORAGE_PRECOMMIT_RESOURCE_UPDATED_hasPid() {
|
||||||
AtomicLong oldPid = new AtomicLong();
|
AtomicLong oldPid = new AtomicLong();
|
||||||
|
@ -84,12 +170,12 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
|
||||||
myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRECOMMIT_RESOURCE_UPDATED, (thePointcut, t) -> {
|
myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRECOMMIT_RESOURCE_UPDATED, (thePointcut, t) -> {
|
||||||
|
|
||||||
IAnyResource oldResource = (IAnyResource) t.get(IBaseResource.class, 0);
|
IAnyResource oldResource = (IAnyResource) t.get(IBaseResource.class, 0);
|
||||||
Long oldResourcePid = (Long) oldResource.getUserData("RESOURCE_PID");
|
Long oldResourcePid = (Long) oldResource.getUserData(IDao.RESOURCE_PID_KEY);
|
||||||
assertNotNull(oldResourcePid, "Expecting RESOURCE_PID to be set on resource user data.");
|
assertNotNull(oldResourcePid, "Expecting RESOURCE_PID to be set on resource user data.");
|
||||||
oldPid.set(oldResourcePid);
|
oldPid.set(oldResourcePid);
|
||||||
|
|
||||||
IAnyResource newResource = (IAnyResource) t.get(IBaseResource.class, 1);
|
IAnyResource newResource = (IAnyResource) t.get(IBaseResource.class, 1);
|
||||||
Long newResourcePid = (Long) newResource.getUserData("RESOURCE_PID");
|
Long newResourcePid = (Long) newResource.getUserData(IDao.RESOURCE_PID_KEY);
|
||||||
assertNotNull(newResourcePid, "Expecting RESOURCE_PID to be set on resource user data.");
|
assertNotNull(newResourcePid, "Expecting RESOURCE_PID to be set on resource user data.");
|
||||||
newPid.set(newResourcePid);
|
newPid.set(newResourcePid);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
package ca.uhn.fhir.rest.server;
|
package ca.uhn.fhir.rest.server;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
import ca.uhn.fhir.interceptor.api.HookParams;
|
||||||
|
import ca.uhn.fhir.interceptor.api.IAnonymousInterceptor;
|
||||||
|
import ca.uhn.fhir.interceptor.api.Pointcut;
|
||||||
import ca.uhn.fhir.rest.annotation.Create;
|
import ca.uhn.fhir.rest.annotation.Create;
|
||||||
import ca.uhn.fhir.rest.annotation.ResourceParam;
|
import ca.uhn.fhir.rest.annotation.ResourceParam;
|
||||||
import ca.uhn.fhir.rest.annotation.Search;
|
import ca.uhn.fhir.rest.annotation.Search;
|
||||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||||
import ca.uhn.fhir.test.utilities.JettyUtil;
|
import ca.uhn.fhir.test.utilities.JettyUtil;
|
||||||
|
@ -29,11 +31,13 @@ import org.hl7.fhir.dstu3.model.OperationOutcome.IssueType;
|
||||||
import org.hl7.fhir.dstu3.model.Patient;
|
import org.hl7.fhir.dstu3.model.Patient;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.junit.jupiter.api.AfterAll;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -44,11 +48,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
public class ServerExceptionDstu3Test {
|
public class ServerExceptionDstu3Test {
|
||||||
|
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerExceptionDstu3Test.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerExceptionDstu3Test.class);
|
||||||
public static BaseServerResponseException ourException;
|
public static Exception ourException;
|
||||||
private static CloseableHttpClient ourClient;
|
private static CloseableHttpClient ourClient;
|
||||||
private static FhirContext ourCtx = FhirContext.forDstu3();
|
private static FhirContext ourCtx = FhirContext.forDstu3();
|
||||||
private static int ourPort;
|
private static int ourPort;
|
||||||
private static Server ourServer;
|
private static Server ourServer;
|
||||||
|
private static RestfulServer ourServlet;
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void after() {
|
||||||
|
ourException = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddHeadersNotFound() throws Exception {
|
public void testAddHeadersNotFound() throws Exception {
|
||||||
|
@ -56,8 +66,8 @@ public class ServerExceptionDstu3Test {
|
||||||
OperationOutcome operationOutcome = new OperationOutcome();
|
OperationOutcome operationOutcome = new OperationOutcome();
|
||||||
operationOutcome.addIssue().setCode(IssueType.BUSINESSRULE);
|
operationOutcome.addIssue().setCode(IssueType.BUSINESSRULE);
|
||||||
|
|
||||||
ourException = new ResourceNotFoundException("SOME MESSAGE");
|
ourException = new ResourceNotFoundException("SOME MESSAGE")
|
||||||
ourException.addResponseHeader("X-Foo", "BAR BAR");
|
.addResponseHeader("X-Foo", "BAR BAR");
|
||||||
|
|
||||||
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient");
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient");
|
||||||
|
@ -99,6 +109,65 @@ public class ServerExceptionDstu3Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMethodThrowsNonHapiUncheckedExceptionHandledCleanly() throws Exception {
|
||||||
|
|
||||||
|
ourException = new NullPointerException("Hello");
|
||||||
|
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_format=json");
|
||||||
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
||||||
|
assertEquals(500, status.getStatusLine().getStatusCode());
|
||||||
|
byte[] responseContentBytes = IOUtils.toByteArray(status.getEntity().getContent());
|
||||||
|
String responseContent = new String(responseContentBytes, Charsets.UTF_8);
|
||||||
|
ourLog.info(status.getStatusLine().toString());
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
assertThat(responseContent, containsString("\"diagnostics\":\"Failed to call access method: java.lang.NullPointerException: Hello\""));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMethodThrowsNonHapiCheckedExceptionHandledCleanly() throws Exception {
|
||||||
|
|
||||||
|
ourException = new IOException("Hello");
|
||||||
|
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_format=json");
|
||||||
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
||||||
|
assertEquals(500, status.getStatusLine().getStatusCode());
|
||||||
|
byte[] responseContentBytes = IOUtils.toByteArray(status.getEntity().getContent());
|
||||||
|
String responseContent = new String(responseContentBytes, Charsets.UTF_8);
|
||||||
|
ourLog.info(status.getStatusLine().toString());
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
assertThat(responseContent, containsString("\"diagnostics\":\"Failed to call access method: java.io.IOException: Hello\""));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInterceptorThrowsNonHapiUncheckedExceptionHandledCleanly() throws Exception {
|
||||||
|
|
||||||
|
ourServlet.getInterceptorService().registerAnonymousInterceptor(Pointcut.SERVER_INCOMING_REQUEST_PRE_HANDLED, new IAnonymousInterceptor() {
|
||||||
|
@Override
|
||||||
|
public void invoke(Pointcut thePointcut, HookParams theArgs) {
|
||||||
|
throw new NullPointerException("Hello");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_format=json");
|
||||||
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
||||||
|
assertEquals(500, status.getStatusLine().getStatusCode());
|
||||||
|
byte[] responseContentBytes = IOUtils.toByteArray(status.getEntity().getContent());
|
||||||
|
String responseContent = new String(responseContentBytes, Charsets.UTF_8);
|
||||||
|
ourLog.info(status.getStatusLine().toString());
|
||||||
|
ourLog.info(responseContent);
|
||||||
|
assertThat(responseContent, containsString("\"diagnostics\":\"Hello\""));
|
||||||
|
}
|
||||||
|
|
||||||
|
ourServlet.getInterceptorService().unregisterAllInterceptors();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostWithNoBody() throws IOException {
|
public void testPostWithNoBody() throws IOException {
|
||||||
|
|
||||||
|
@ -143,7 +212,10 @@ public class ServerExceptionDstu3Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Search()
|
@Search()
|
||||||
public List<Patient> search() {
|
public List<Patient> search() throws Exception {
|
||||||
|
if (ourException == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
throw ourException;
|
throw ourException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,15 +240,15 @@ public class ServerExceptionDstu3Test {
|
||||||
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
||||||
|
|
||||||
ServletHandler proxyHandler = new ServletHandler();
|
ServletHandler proxyHandler = new ServletHandler();
|
||||||
RestfulServer servlet = new RestfulServer(ourCtx);
|
ourServlet = new RestfulServer(ourCtx);
|
||||||
servlet.setPagingProvider(new FifoMemoryPagingProvider(10));
|
ourServlet.setPagingProvider(new FifoMemoryPagingProvider(10));
|
||||||
|
|
||||||
servlet.setResourceProviders(patientProvider);
|
ourServlet.setResourceProviders(patientProvider);
|
||||||
ServletHolder servletHolder = new ServletHolder(servlet);
|
ServletHolder servletHolder = new ServletHolder(ourServlet);
|
||||||
proxyHandler.addServletWithMapping(servletHolder, "/*");
|
proxyHandler.addServletWithMapping(servletHolder, "/*");
|
||||||
ourServer.setHandler(proxyHandler);
|
ourServer.setHandler(proxyHandler);
|
||||||
JettyUtil.startServer(ourServer);
|
JettyUtil.startServer(ourServer);
|
||||||
ourPort = JettyUtil.getPortForStartedServer(ourServer);
|
ourPort = JettyUtil.getPortForStartedServer(ourServer);
|
||||||
|
|
||||||
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
||||||
HttpClientBuilder builder = HttpClientBuilder.create();
|
HttpClientBuilder builder = HttpClientBuilder.create();
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -717,7 +717,7 @@
|
||||||
<!-- 9.4.17 seems to have issues -->
|
<!-- 9.4.17 seems to have issues -->
|
||||||
<jetty_version>9.4.30.v20200611</jetty_version>
|
<jetty_version>9.4.30.v20200611</jetty_version>
|
||||||
<jsr305_version>3.0.2</jsr305_version>
|
<jsr305_version>3.0.2</jsr305_version>
|
||||||
<flyway_version>6.4.1</flyway_version>
|
<flyway_version>6.5.4</flyway_version>
|
||||||
<!--<hibernate_version>5.2.10.Final</hibernate_version>-->
|
<!--<hibernate_version>5.2.10.Final</hibernate_version>-->
|
||||||
<hibernate_version>5.4.14.Final</hibernate_version>
|
<hibernate_version>5.4.14.Final</hibernate_version>
|
||||||
<!-- Update lucene version when you update hibernate-search version -->
|
<!-- Update lucene version when you update hibernate-search version -->
|
||||||
|
|
Loading…
Reference in New Issue