Merge pull request #613 from SRiviere/jaxrs-sever-evolution

Changing with stackTrace paramter without server restart
This commit is contained in:
James Agnew 2017-04-17 17:56:33 -04:00 committed by GitHub
commit c66e147ec8
5 changed files with 274 additions and 22 deletions

View File

@ -64,8 +64,6 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
private final FhirContext CTX; 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 PROCESSING = "processing";
private static final String ERROR = "error"; 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) public Response handleException(final JaxRsRequest theRequest, final Throwable theException)
throws IOException { throws IOException {
if (theException instanceof JaxRsResponseException) { if (theException instanceof JaxRsResponseException) {
return DEFAULT_EXCEPTION_HANDLER.convertExceptionIntoResponse(theRequest, (JaxRsResponseException) theException); return new JaxRsExceptionInterceptor().convertExceptionIntoResponse(theRequest, (JaxRsResponseException) theException);
} else if (theException instanceof DataFormatException) { } 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)))); new InvalidRequestException(theException.getMessage(), createOutcome((DataFormatException) theException))));
} else { } else {
return DEFAULT_EXCEPTION_HANDLER.convertExceptionIntoResponse(theRequest, return new JaxRsExceptionInterceptor().convertExceptionIntoResponse(theRequest,
DEFAULT_EXCEPTION_HANDLER.convertException(this, theException)); new JaxRsExceptionInterceptor().convertException(this, theException));
} }
} }

View File

@ -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());
}
}

View File

@ -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.Extension;
import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.StringDt;
@ResourceDef() @ResourceDef()
@ -17,11 +18,19 @@ public class MyPatientWithCustomUrlExtension extends Patient {
@Description(shortDefinition = "The name of the patient's favourite pet") @Description(shortDefinition = "The name of the patient's favourite pet")
private StringDt myPetName; 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() { public StringDt getPetName() {
if (myPetName == null) {
myPetName = new StringDt();
}
return myPetName; return myPetName;
} }
public void setPetName(StringDt thePetName) { public void setPetName(final StringDt thePetName) {
myPetName = thePetName; myPetName = thePetName;
} }
@ -30,4 +39,14 @@ public class MyPatientWithCustomUrlExtension extends Patient {
return super.isEmpty() && myPetName.isEmpty(); 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;
}
} }

View File

@ -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());
}
}

View File

@ -4,30 +4,49 @@ import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.Extension; import ca.uhn.fhir.model.api.annotation.Extension;
import ca.uhn.fhir.model.api.annotation.ResourceDef; 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.Patient;
import org.hl7.fhir.dstu3.model.StringType;
@ResourceDef() @ResourceDef()
public class MyPatientWithCustomUrlExtension extends Patient { public class MyPatientWithCustomUrlExtension extends Patient {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Child(name = "petName") @Child(name = "petName")
@Extension(url = "/petname", definedLocally = false, isModifier = false) @Extension(url = "/petname", definedLocally = false, isModifier = false)
@Description(shortDefinition = "The name of the patient's favourite pet") @Description(shortDefinition = "The name of the patient's favourite pet")
private StringType myPetName; private StringType myPetName;
public StringType getPetName() { @Child(name = "customid")
return myPetName; @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;
}
public void setPetName(final StringType thePetName) { public void setPetName(final StringType thePetName) {
myPetName = thePetName; myPetName = thePetName;
} }
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {
return super.isEmpty() && myPetName.isEmpty(); 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;
}
} }