Skip to content

Commit

Permalink
Use more compatible Accept header in STU3 client. Also fixes missing
Browse files Browse the repository at this point in the history
Woodstox library in android builds per #450)
  • Loading branch information
jamesagnew committed Sep 17, 2016
1 parent a3108eb commit 364c18e
Show file tree
Hide file tree
Showing 14 changed files with 1,463 additions and 116 deletions.
103 changes: 81 additions & 22 deletions hapi-fhir-android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand All @@ -59,6 +55,11 @@
<version>2.1-SNAPSHOT</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-android</artifactId>
Expand All @@ -75,10 +76,6 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand All @@ -98,25 +95,59 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<!--
<classpathDependencyScopeExclude>compile+runtime+test+provided</classpathDependencyScopeExclude>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.directory}/hapi-fhir-android-${project.version}-dstu2.jar</additionalClasspathElement>
</additionalClasspathElements>
<classpathDependencyExcludes>
<classpathDependencyExclude>ca.uhn.hapi.fhir:hapi-fhir-base</classpathDependencyExclude>
<classpathDependencyExclude>org.codehaus.woodstox:*</classpathDependencyExclude>
<classpathDependencyExclude>javax.json:*</classpathDependencyExclude>
<classpathDependencyExclude>org.glassfish:javax.json</classpathDependencyExclude>
</classpathDependencyExcludes>
-->
</configuration>
<executions>
<execution>
<id>dstu2_shade</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>**/*Dstu2ShadeIT.java</include>
</includes>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/target/hapi-fhir-android-${project.version}-dstu2.jar</additionalClasspathElement>
</additionalClasspathElements>
<classpathDependencyExcludes>
<classpathDependencyExclude>ca.uhn.hapi.fhir:*</classpathDependencyExclude>
<classpathDependencyExclude>org.codehaus.woodstox:woodstox-core-asl</classpathDependencyExclude>
<classpathDependencyExclude>org.codehaus.woodstox:stax2-api</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
</execution>
<execution>
<id>dstu2</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>**/*Dstu2IT.java</include>
</includes>
<classpathDependencyExcludes>
<classpathDependencyExclude>org.codehaus.woodstox:woodstox-core-asl</classpathDependencyExclude>
<classpathDependencyExclude>org.codehaus.woodstox:stax2-api</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
</execution>
<execution>
<id>dstu3</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>**/*Dstu3IT.java</include>
</includes>
<classpathDependencyExcludes>
<classpathDependencyExclude>org.codehaus.woodstox:woodstox-core-asl</classpathDependencyExclude>
<classpathDependencyExclude>org.codehaus.woodstox:stax2-api</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
</execution>
</executions>
</plugin>
Expand All @@ -130,6 +161,9 @@
<artifactSet>
<includes combine.children="append">
<include>ca.uhn.hapi.fhir:hapi-fhir-base</include>
<include>org.codehaus.woodstox:woodstox-core-asl</include>
<include>javax.xml.stream:stax-api</include>
<include>org.codehaus.woodstox:stax2-api</include>
</includes>
</artifactSet>
<relocations>
Expand All @@ -141,6 +175,10 @@
<pattern>javax.json</pattern>
<shadedPattern>ca.uhn.fhir.repackage.javax.json</shadedPattern>
</relocation>
<relocation>
<pattern>com.ctc.wstx.stax</pattern>
<shadedPattern>ca.uhn.fhir.repackage.com.ctc.wstx.stax</shadedPattern>
</relocation>
</relocations>
<filters combine.children="append">
<!-- Exclude server side stuff, except exceptions which are used clientside -->
Expand Down Expand Up @@ -182,8 +220,8 @@
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</goals>
</execution>
<!-- dstu jar -->
<execution>
<id>dstu</id>
Expand Down Expand Up @@ -261,6 +299,27 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<classFolders>
<classFolder>${basedir}/target/classes</classFolder>
</classFolders>
<sourceFolders>
<sourceFolder>${basedir}/src/main/java</sourceFolder>
</sourceFolders>
<dumpOnExit>true</dumpOnExit>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package ca.uhn.fhir.android;

import static org.junit.Assert.*;

import java.io.File;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import javax.naming.ConfigurationException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.junit.BeforeClass;
import org.junit.Test;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
import ca.uhn.fhir.model.dstu2.resource.Observation;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.rest.client.IGenericClient;
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;

public class BuiltJarDstu2IT {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BuiltJarDstu2IT.class);

@BeforeClass
public static void beforeClass() {
System.setProperty("javax.xml.stream.XMLInputFactory", "FOO");
System.setProperty("javax.xml.stream.XMLOutputFactory", "FOO");
}

@Test
public void testParserXml() throws Exception {

FhirContext ctx = FhirContext.forDstu2();

Patient p = new Patient();
p.addIdentifier().setSystem("system");

try {
ctx.newXmlParser().encodeResourceToString(p);
fail();
} catch (ca.uhn.fhir.context.ConfigurationException e) {
assertEquals("Unable to initialize StAX - XML processing is disabled",e.getMessage());
}
}

@Test
public void testParserJson() {

FhirContext ctx = FhirContext.forDstu2();

Observation o = new Observation();
o.getCode().setText("TEXT");
o.setValue(new QuantityDt(123));
o.addIdentifier().setSystem("system");

String str = ctx.newJsonParser().encodeResourceToString(o);
Observation p2 = ctx.newJsonParser().parseResource(Observation.class, str);

assertEquals("TEXT", p2.getCode().getText());

QuantityDt dt = (QuantityDt) p2.getValue();
dt.getComparatorElement().getValueAsEnum();

}

/**
* A simple client test - We try to connect to a server that doesn't exist, but
* if we at least get the right exception it means we made it up to the HTTP/network stack
*
* Disabled for now - TODO: add the old version of the apache client (the one that
* android uses) and see if this passes
*/
@SuppressWarnings("deprecation")
public void testClient() {
FhirContext ctx = FhirContext.forDstu2();
try {
IGenericClient client = ctx.newRestfulGenericClient("http://127.0.0.1:44442/SomeBase");
client.conformance();
} catch (FhirClientConnectionException e) {
// this is good
}
}

/**
* Android does not like duplicate entries in the JAR
*/
@Test
public void testJarContents() throws Exception {
String wildcard = "hapi-fhir-android-*.jar";
Collection<File> files = FileUtils.listFiles(new File("target"), new WildcardFileFilter(wildcard), null);
if (files.isEmpty()) {
throw new Exception("No files matching " + wildcard);
}

for (File file : files) {
if (file.getName().endsWith("sources.jar")) {
continue;
}
if (file.getName().endsWith("javadoc.jar")) {
continue;
}
if (file.getName().contains("original.jar")) {
continue;
}

ourLog.info("Testing file: {}", file);

ZipFile zip = new ZipFile(file);

int totalClasses = 0;
int totalMethods = 0;
TreeSet<ClassMethodCount> topMethods = new TreeSet<ClassMethodCount>();

try {
Set<String> names = new HashSet<String>();
for (Enumeration<? extends ZipEntry> iter = zip.entries(); iter.hasMoreElements();) {
ZipEntry next = iter.nextElement();
String nextName = next.getName();
if (!names.add(nextName)) {
throw new Exception("File " + file + " contains duplicate contents: " + nextName);
}

if (nextName.contains("$") == false) {
if (nextName.endsWith(".class")) {
String className = nextName.replace("/", ".").replace(".class", "");
try {
Class<?> clazz = Class.forName(className);
int methodCount = clazz.getMethods().length;
topMethods.add(new ClassMethodCount(className, methodCount));
totalClasses++;
totalMethods += methodCount;
} catch (NoClassDefFoundError e) {
// ignore
} catch (ClassNotFoundException e) {
// ignore
}
}
}
}

ourLog.info("File {} contains {} entries", file, names.size());
ourLog.info("Total classes {} - Total methods {}", totalClasses, totalMethods);
ourLog.info("Top classes {}", new ArrayList<ClassMethodCount>(topMethods).subList(Math.max(0, topMethods.size() - 10), topMethods.size()));

} finally {
zip.close();
}
}
}

private static class ClassMethodCount implements Comparable<ClassMethodCount> {

private String myClassName;
private int myMethodCount;

public ClassMethodCount(String theClassName, int theMethodCount) {
myClassName = theClassName;
myMethodCount = theMethodCount;
}

@Override
public String toString() {
return myClassName + "[" + myMethodCount + "]";
}

@Override
public int compareTo(ClassMethodCount theO) {
return myMethodCount - theO.myMethodCount;
}

public String getClassName() {
return myClassName;
}

public void setClassName(String theClassName) {
myClassName = theClassName;
}

public int getMethodCount() {
return myMethodCount;
}

public void setMethodCount(int theMethodCount) {
myMethodCount = theMethodCount;
}

}

}

0 comments on commit 364c18e

Please sign in to comment.