Merge pull request #613 from SRiviere/jaxrs-sever-evolution
Changing with stackTrace paramter without server restart
This commit is contained in:
commit
c66e147ec8
|
@ -64,8 +64,6 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
|||
|
||||
private final FhirContext CTX;
|
||||
|
||||
/** The default exception interceptor */
|
||||
private static final JaxRsExceptionInterceptor DEFAULT_EXCEPTION_HANDLER = new JaxRsExceptionInterceptor();
|
||||
private static final String PROCESSING = "processing";
|
||||
private static final String ERROR = "error";
|
||||
|
||||
|
@ -260,13 +258,13 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
|||
public Response handleException(final JaxRsRequest theRequest, final Throwable theException)
|
||||
throws IOException {
|
||||
if (theException instanceof JaxRsResponseException) {
|
||||
return DEFAULT_EXCEPTION_HANDLER.convertExceptionIntoResponse(theRequest, (JaxRsResponseException) theException);
|
||||
return new JaxRsExceptionInterceptor().convertExceptionIntoResponse(theRequest, (JaxRsResponseException) theException);
|
||||
} else if (theException instanceof DataFormatException) {
|
||||
return DEFAULT_EXCEPTION_HANDLER.convertExceptionIntoResponse(theRequest, new JaxRsResponseException(
|
||||
return new JaxRsExceptionInterceptor().convertExceptionIntoResponse(theRequest, new JaxRsResponseException(
|
||||
new InvalidRequestException(theException.getMessage(), createOutcome((DataFormatException) theException))));
|
||||
} else {
|
||||
return DEFAULT_EXCEPTION_HANDLER.convertExceptionIntoResponse(theRequest,
|
||||
DEFAULT_EXCEPTION_HANDLER.convertException(this, theException));
|
||||
return new JaxRsExceptionInterceptor().convertExceptionIntoResponse(theRequest,
|
||||
new JaxRsExceptionInterceptor().convertException(this, theException));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
package ca.uhn.fhir.parser;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Sébastien Rivière 12/04/2017
|
||||
*/
|
||||
public class ElementWithExtensionDstu2Test {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ca.uhn.fhir.parser.ElementWithExtensionDstu2Test.class);
|
||||
private static final FhirContext ctx = FhirContext.forDstu2();
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtensionOnPrimitiveExtensionJson() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getPetName().addUndeclaredExtension(false, "http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringDt("UNK"));
|
||||
final IParser parser = ctx.newJsonParser().setPrettyPrint(true);
|
||||
final String json = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(json);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, json);
|
||||
assertEquals(1, patient.getPetName().getUndeclaredExtensions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtensionOnPrimitiveExtensionXml() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getPetName().addUndeclaredExtension(false, "http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringDt("UNK"));
|
||||
final IParser parser = ctx.newXmlParser().setPrettyPrint(true);
|
||||
final String xml = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(xml);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, xml);
|
||||
assertEquals(1, patient.getPetName().getUndeclaredExtensions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtensionOnIDDatatypeJson() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getId().addUndeclaredExtension(false, "http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringDt("UNK"));
|
||||
final IParser parser = ctx.newJsonParser().setPrettyPrint(true);
|
||||
final String json = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(json);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, json);
|
||||
assertEquals(1, patient.getId().getUndeclaredExtensions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtensionOnIDDatatypeXml() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getId().addUndeclaredExtension(false, "http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringDt("UNK"));
|
||||
final IParser parser = ctx.newXmlParser().setPrettyPrint(true);
|
||||
final String xml = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(xml);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, xml);
|
||||
assertEquals(1, patient.getId().getUndeclaredExtensions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtensionOnIDDatatypeExtensionJson() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getCustomId().addUndeclaredExtension(false, "http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringDt("UNK"));
|
||||
final IParser parser = ctx.newJsonParser().setPrettyPrint(true);
|
||||
final String json = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(json);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, json);
|
||||
assertEquals(1, patient.getCustomId().getUndeclaredExtensions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtensionOnIDDatatypeExtensionXml() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getCustomId().addUndeclaredExtension(false, "http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringDt("UNK"));
|
||||
final IParser parser = ctx.newXmlParser().setPrettyPrint(true);
|
||||
final String xml = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(xml);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, xml);
|
||||
assertEquals(1, patient.getCustomId().getUndeclaredExtensions().size());
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import ca.uhn.fhir.model.api.annotation.Description;
|
|||
import ca.uhn.fhir.model.api.annotation.Extension;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
|
||||
@ResourceDef()
|
||||
|
@ -17,11 +18,19 @@ public class MyPatientWithCustomUrlExtension extends Patient {
|
|||
@Description(shortDefinition = "The name of the patient's favourite pet")
|
||||
private StringDt myPetName;
|
||||
|
||||
@Child(name = "customid")
|
||||
@Extension(url = "/customid", definedLocally = false, isModifier = false)
|
||||
@Description(shortDefinition = "The customid of the patient's ")
|
||||
private IdDt myCustomId;
|
||||
|
||||
public StringDt getPetName() {
|
||||
if (myPetName == null) {
|
||||
myPetName = new StringDt();
|
||||
}
|
||||
return myPetName;
|
||||
}
|
||||
|
||||
public void setPetName(StringDt thePetName) {
|
||||
public void setPetName(final StringDt thePetName) {
|
||||
myPetName = thePetName;
|
||||
}
|
||||
|
||||
|
@ -30,4 +39,14 @@ public class MyPatientWithCustomUrlExtension extends Patient {
|
|||
return super.isEmpty() && myPetName.isEmpty();
|
||||
}
|
||||
|
||||
public IdDt getCustomId() {
|
||||
if (myCustomId == null) {
|
||||
myCustomId = new IdDt();
|
||||
}
|
||||
return myCustomId;
|
||||
}
|
||||
|
||||
public void setCustomId(final IdDt myCustomId) {
|
||||
this.myCustomId = myCustomId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
package ca.uhn.fhir.parser;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import org.hl7.fhir.dstu3.model.StringType;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Sébastien Rivière 12/04/2017
|
||||
*/
|
||||
public class ElementWithExtensionDstu3Test {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ca.uhn.fhir.parser.ElementWithExtensionDstu3Test.class);
|
||||
private static final FhirContext ctx = FhirContext.forDstu3();
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullFlavorPrimitiveExtensionJson() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getPetName().addExtension("http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringType("UNK"));
|
||||
final IParser parser = ctx.newJsonParser().setPrettyPrint(true);
|
||||
final String json = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(json);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, json);
|
||||
assertEquals(1, patient.getPetName().getExtension().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullFlavorPrimitiveExtensionXml() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getPetName().addExtension("http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringType("UNK"));
|
||||
final IParser parser = ctx.newXmlParser().setPrettyPrint(true);
|
||||
final String xml = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(xml);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, xml);
|
||||
assertEquals(1, patient.getPetName().getExtension().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullFlavorIDDatatypeJson() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getIdElement().addExtension("http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringType("UNK"));
|
||||
final IParser parser = ctx.newJsonParser().setPrettyPrint(true);
|
||||
final String json = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(json);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, json);
|
||||
assertEquals(1, patient.getIdElement().getExtension().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullFlavorIDDatatypeXml() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getIdElement().addExtension("http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringType("UNK"));
|
||||
final IParser parser = ctx.newXmlParser().setPrettyPrint(true);
|
||||
final String xml = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(xml);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, xml);
|
||||
assertEquals(1, patient.getIdElement().getExtension().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullFlavorExtensionIDDatatypeJson() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getCustomId().addExtension("http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringType("UNK"));
|
||||
final IParser parser = ctx.newJsonParser().setPrettyPrint(true);
|
||||
final String json = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(json);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, json);
|
||||
assertEquals(1, patient.getCustomId().getExtension().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullFlavorExtensionIDDatatypeXml() throws Exception {
|
||||
MyPatientWithCustomUrlExtension patient = new MyPatientWithCustomUrlExtension();
|
||||
patient.setId("1");
|
||||
patient.getCustomId().addExtension("http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor", new StringType("UNK"));
|
||||
final IParser parser = ctx.newXmlParser().setPrettyPrint(true);
|
||||
final String xml = parser.encodeResourceToString(patient);
|
||||
|
||||
ourLog.info(xml);
|
||||
|
||||
patient = parser.parseResource(MyPatientWithCustomUrlExtension.class, xml);
|
||||
assertEquals(1, patient.getCustomId().getExtension().size());
|
||||
}
|
||||
}
|
||||
|
|
@ -4,8 +4,9 @@ import ca.uhn.fhir.model.api.annotation.Child;
|
|||
import ca.uhn.fhir.model.api.annotation.Description;
|
||||
import ca.uhn.fhir.model.api.annotation.Extension;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import org.hl7.fhir.dstu3.model.StringType;
|
||||
import org.hl7.fhir.dstu3.model.IdType;
|
||||
import org.hl7.fhir.dstu3.model.Patient;
|
||||
import org.hl7.fhir.dstu3.model.StringType;
|
||||
|
||||
@ResourceDef()
|
||||
public class MyPatientWithCustomUrlExtension extends Patient {
|
||||
|
@ -17,7 +18,15 @@ public class MyPatientWithCustomUrlExtension extends Patient {
|
|||
@Description(shortDefinition = "The name of the patient's favourite pet")
|
||||
private StringType myPetName;
|
||||
|
||||
@Child(name = "customid")
|
||||
@Extension(url = "/customid", definedLocally = false, isModifier = false)
|
||||
@Description(shortDefinition = "The customid of the patient's ")
|
||||
private IdType myCustomId;
|
||||
|
||||
public StringType getPetName() {
|
||||
if (myPetName == null) {
|
||||
myPetName = new StringType();
|
||||
}
|
||||
return myPetName;
|
||||
}
|
||||
|
||||
|
@ -30,4 +39,14 @@ public class MyPatientWithCustomUrlExtension extends Patient {
|
|||
return super.isEmpty() && myPetName.isEmpty();
|
||||
}
|
||||
|
||||
public IdType getCustomId() {
|
||||
if (myCustomId == null) {
|
||||
myCustomId = new IdType();
|
||||
}
|
||||
return myCustomId;
|
||||
}
|
||||
|
||||
public void setCustomId(final IdType myCustomId) {
|
||||
this.myCustomId = myCustomId;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue