Fix #100 - HAPI failed to initialize in an environment without Woodstox

on the classpath. Will deploy a new snapshot shortly.
This commit is contained in:
James Agnew 2015-02-04 14:15:11 -05:00
parent a474870a1e
commit 37e2abb4e2
7 changed files with 74 additions and 11 deletions

View File

@ -210,10 +210,14 @@ public class XmlUtil {
* Note that these properties are Woodstox specific and they cause a crash in environments where SJSXP is
* being used (e.g. glassfish) so we don't set them there.
*/
if (inputFactory instanceof com.ctc.wstx.stax.WstxInputFactory) {
// inputFactory.setProperty(WstxInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
inputFactory.setProperty(WstxInputProperties.P_UNDECLARED_ENTITY_RESOLVER, XML_RESOLVER);
try {
Class.forName("com.ctc.wstx.stax.WstxOutputFactory");
if (inputFactory instanceof com.ctc.wstx.stax.WstxInputFactory) {
// inputFactory.setProperty(WstxInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
inputFactory.setProperty(WstxInputProperties.P_UNDECLARED_ENTITY_RESOLVER, XML_RESOLVER);
}
} catch (ClassNotFoundException e) {
ourLog.debug("WstxOutputFactory (Woodstox) not found on classpath");
}
ourInputFactory = inputFactory;
}
@ -317,8 +321,13 @@ public class XmlUtil {
* Note that these properties are Woodstox specific and they cause a crash in environments where SJSXP is
* being used (e.g. glassfish) so we don't set them there.
*/
if (outputFactory instanceof WstxOutputFactory) {
outputFactory.setProperty(XMLOutputFactory2.P_TEXT_ESCAPER, new MyEscaper());
try {
Class.forName("com.ctc.wstx.stax.WstxOutputFactory");
if (outputFactory instanceof WstxOutputFactory) {
outputFactory.setProperty(XMLOutputFactory2.P_TEXT_ESCAPER, new MyEscaper());
}
} catch (ClassNotFoundException e) {
ourLog.debug("WstxOutputFactory (Woodstox) not found on classpath");
}
ourOutputFactory = outputFactory;
}

View File

@ -41,17 +41,43 @@
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>0.9-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>woodstox-core-asl</artifactId>
<groupId>org.codehaus.woodstox</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu</artifactId>
<version>0.9-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>woodstox-core-asl</artifactId>
<groupId>org.codehaus.woodstox</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dev</artifactId>
<version>0.9-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>woodstox-core-asl</artifactId>
<groupId>org.codehaus.woodstox</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>${hamcrest_version}</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -2,6 +2,7 @@ package ca.uhn.fhir.parser;
import static org.junit.Assert.assertThat;
import org.hamcrest.Matchers;
import org.hamcrest.core.StringContains;
import org.junit.Test;
@ -11,9 +12,9 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
public class MultiVersionXmlParserTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(MultiVersionXmlParserTest.class);
@Test
public void testEncodeExtensionFromDifferentVersion() {
Patient p = new Patient();
@ -23,11 +24,13 @@ public class MultiVersionXmlParserTest {
String str;
str = FhirContext.forDstu1().newXmlParser().encodeResourceToString(p);
ourLog.info(str);
assertThat(str,StringContains.containsString("<extension url=\"http://foo#ext\"><valueQuantity><value value=\"2.2\"/><comparator value=\"&lt;\"/><units value=\"g/L\"/></valueQuantity></extension>"));
assertThat(str, Matchers.stringContainsInOrder("<extension url=\"http://foo#ext\"><valueQuantity><value value=\"2.2\"", "<comparator value=\"&lt;\"", "<units value=\"g/L\"",
"</valueQuantity></extension>"));
str = FhirContext.forDev().newXmlParser().encodeResourceToString(p);
ourLog.info(str);
assertThat(str,StringContains.containsString("<extension url=\"http://foo#ext\"><valueQuantity><value value=\"2.2\"/><comparator value=\"&lt;\"/><units value=\"g/L\"/></valueQuantity></extension>"));
assertThat(str, Matchers.stringContainsInOrder("<extension url=\"http://foo#ext\"><valueQuantity><value value=\"2.2\"", "<comparator value=\"&lt;\"", "<units value=\"g/L\"",
"</valueQuantity></extension>"));
}
}

View File

@ -0,0 +1,16 @@
package ca.uhn.fhir.testmindeps;
import org.junit.Test;
public class SetupTest {
/**
* Ensure that Woodstox is not on the classpath (we're testing that the library works ok without it
* elsewhere)
*/
@Test(expected=ClassNotFoundException.class)
public void testValidateEnvironment() throws ClassNotFoundException {
Class.forName("com.ctc.wstx.stax.WstxOutputFactory");
}
}

View File

@ -118,7 +118,7 @@ public class TinderJpaRestServerMojo extends AbstractMojo {
throw new MojoFailureException("Failed to generate server", e);
}
myProject.addCompileSourceRoot(directoryBase.getAbsolutePath());
myProject.addCompileSourceRoot(targetDirectory.getAbsolutePath());
try {
VelocityContext ctx = new VelocityContext();

View File

@ -123,6 +123,10 @@
<id>twilson650</id>
<name>Tom Wilson</name>
</developer>
<developer>
<id>sweetnavelorange</id>
<name>James Butler</name>
</developer>
</developers>
<licenses>

View File

@ -96,6 +96,11 @@
DateClientParam#second() incorrectly used DAY precision instead
of SECOND precision. Thanks to Tom Wilson for the pull request!
</action>
<action type="fix" issue="100" due-to="sweetnavelorange">
Fix issue where HAPI failed to initialize correctly if Woodstox library was not on the classpath, even
if StAX API was configured to use a different provider. Thanks to
James Butler for reporting and figuring out where the issue was!
</action>
</release>
<release version="0.8" date="2014-Dec-17">
<action type="add">