Work on #105 - Should have it working

This commit is contained in:
jamesagnew 2015-02-16 22:37:47 -05:00
parent e845ab7a40
commit 54be2634cd
6 changed files with 77 additions and 65 deletions

View File

@ -12,7 +12,7 @@
<bean class="ca.uhn.fhir.to.TesterConfig"> <bean class="ca.uhn.fhir.to.TesterConfig">
<property name="servers"> <property name="servers">
<list> <list>
<value>home , DSTU2 , Local Server , http://localhost:8080/hapi-fhir-jpaserver-example/base</value> <value>home , DSTU2 , Local Server , ${serverBase}/base</value>
</list> </list>
</property> </property>
</bean> </bean>

View File

@ -12,7 +12,7 @@
/WEB-INF/hapi-fhir-server-database-config.xml /WEB-INF/hapi-fhir-server-database-config.xml
/WEB-INF/hapi-fhir-server-config.xml /WEB-INF/hapi-fhir-server-config.xml
classpath:hapi-fhir-server-resourceproviders-dstu1.xml classpath:hapi-fhir-server-resourceproviders-dstu1.xml
classpath:hapi-fhir-server-resourceproviders-dev.xml classpath:hapi-fhir-server-resourceproviders-dstu2.xml
/WEB-INF/hapi-fhir-tester-application-context.xml /WEB-INF/hapi-fhir-tester-application-context.xml
/WEB-INF/hapi-fhir-tester-config.xml /WEB-INF/hapi-fhir-tester-config.xml
</param-value> </param-value>

View File

@ -1,9 +1,6 @@
package ca.uhn.fhir.to; package ca.uhn.fhir.to;
import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; import static org.apache.commons.lang3.StringUtils.*;
import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
@ -94,8 +91,8 @@ public class Controller {
private TemplateEngine myTemplateEngine; private TemplateEngine myTemplateEngine;
@RequestMapping(value = { "/about" }) @RequestMapping(value = { "/about" })
public String actionAbout(final HomeRequest theRequest, final ModelMap theModel) { public String actionAbout(HttpServletRequest theServletRequest, final HomeRequest theRequest, final ModelMap theModel) {
addCommonParams(theRequest, theModel); addCommonParams(theServletRequest, theRequest, theModel);
theModel.put("notHome", true); theModel.put("notHome", true);
theModel.put("extraBreadcrumb", "About"); theModel.put("extraBreadcrumb", "About");
@ -106,11 +103,11 @@ public class Controller {
} }
@RequestMapping(value = { "/conformance" }) @RequestMapping(value = { "/conformance" })
public String actionConformance(final HomeRequest theRequest, final BindingResult theBindingResult, final ModelMap theModel) { public String actionConformance(HttpServletRequest theServletRequest, final HomeRequest theRequest, final BindingResult theBindingResult, final ModelMap theModel) {
addCommonParams(theRequest, theModel); addCommonParams(theServletRequest, theRequest, theModel);
CaptureInterceptor interceptor = new CaptureInterceptor(); CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(getContext(theRequest), myConfig, interceptor); GenericClient client = theRequest.newClient(theServletRequest, getContext(theRequest), myConfig, interceptor);
ResultType returnsResource = ResultType.RESOURCE; ResultType returnsResource = ResultType.RESOURCE;
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
@ -137,10 +134,10 @@ public class Controller {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequestMapping(value = { "/delete" }) @RequestMapping(value = { "/delete" })
public String actionDelete(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) { public String actionDelete(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) {
addCommonParams(theRequest, theModel); addCommonParams(theReq, theRequest, theModel);
CaptureInterceptor interceptor = new CaptureInterceptor(); CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(getContext(theRequest), myConfig, interceptor); GenericClient client = theRequest.newClient(theReq, getContext(theRequest), myConfig, interceptor);
RuntimeResourceDefinition def; RuntimeResourceDefinition def;
try { try {
@ -175,10 +172,10 @@ public class Controller {
@RequestMapping(value = { "/get-tags" }) @RequestMapping(value = { "/get-tags" })
public String actionGetTags(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) { public String actionGetTags(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) {
addCommonParams(theRequest, theModel); addCommonParams(theReq, theRequest, theModel);
CaptureInterceptor interceptor = new CaptureInterceptor(); CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(getContext(theRequest), myConfig, interceptor); GenericClient client = theRequest.newClient(theReq, getContext(theRequest), myConfig, interceptor);
Class<? extends IResource> resType = null; Class<? extends IResource> resType = null;
ResultType returnsResource = ResultType.TAGLIST; ResultType returnsResource = ResultType.TAGLIST;
@ -238,17 +235,17 @@ public class Controller {
@RequestMapping(value = { "/", "/home" }) @RequestMapping(value = { "/", "/home" })
public String actionHome(HttpServletRequest theServletRequest, final HomeRequest theRequest, final BindingResult theBindingResult, final ModelMap theModel) { public String actionHome(HttpServletRequest theServletRequest, final HomeRequest theRequest, final BindingResult theBindingResult, final ModelMap theModel) {
addCommonParams(theRequest, theModel); addCommonParams(theServletRequest, theRequest, theModel);
ourLog.info(theServletRequest.toString()); ourLog.info(theServletRequest.toString());
return "home"; return "home";
} }
@RequestMapping(value = { "/page" }) @RequestMapping(value = { "/page" })
public String actionPage(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) { public String actionPage(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) {
addCommonParams(theRequest, theModel); addCommonParams(theReq, theRequest, theModel);
CaptureInterceptor interceptor = new CaptureInterceptor(); CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(getContext(theRequest), myConfig, interceptor); GenericClient client = theRequest.newClient(theReq, getContext(theRequest), myConfig, interceptor);
String url = defaultString(theReq.getParameter("page-url")); String url = defaultString(theReq.getParameter("page-url"));
if (!url.startsWith(theModel.get("base").toString())) { if (!url.startsWith(theModel.get("base").toString())) {
@ -279,10 +276,10 @@ public class Controller {
@RequestMapping(value = { "/read" }) @RequestMapping(value = { "/read" })
public String actionRead(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) { public String actionRead(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) {
addCommonParams(theRequest, theModel); addCommonParams(theReq, theRequest, theModel);
CaptureInterceptor interceptor = new CaptureInterceptor(); CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(getContext(theRequest), myConfig, interceptor); GenericClient client = theRequest.newClient(theReq, getContext(theRequest), myConfig, interceptor);
RuntimeResourceDefinition def; RuntimeResourceDefinition def;
try { try {
@ -323,11 +320,11 @@ public class Controller {
} }
@RequestMapping({ "/resource" }) @RequestMapping({ "/resource" })
public String actionResource(final ResourceRequest theRequest, final BindingResult theBindingResult, final ModelMap theModel) { public String actionResource(HttpServletRequest theServletRequest, final ResourceRequest theRequest, final BindingResult theBindingResult, final ModelMap theModel) {
IResource conformance = addCommonParams(theRequest, theModel); IResource conformance = addCommonParams(theServletRequest, theRequest, theModel);
CaptureInterceptor interceptor = new CaptureInterceptor(); CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(getContext(theRequest), myConfig, interceptor); GenericClient client = theRequest.newClient(null, getContext(theRequest), myConfig, interceptor);
String resourceName = theRequest.getResource(); String resourceName = theRequest.getResource();
RuntimeResourceDefinition def = getContext(theRequest).getResourceDefinition(theRequest.getResource()); RuntimeResourceDefinition def = getContext(theRequest).getResourceDefinition(theRequest.getResource());
@ -447,7 +444,7 @@ public class Controller {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequestMapping(value = { "/search" }) @RequestMapping(value = { "/search" })
public String actionSearch(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) { public String actionSearch(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) {
addCommonParams(theRequest, theModel); addCommonParams(theReq, theRequest, theModel);
StringWriter clientCodeJsonStringWriter = new StringWriter(); StringWriter clientCodeJsonStringWriter = new StringWriter();
JsonGenerator clientCodeJsonWriter = Json.createGenerator(clientCodeJsonStringWriter); JsonGenerator clientCodeJsonWriter = Json.createGenerator(clientCodeJsonStringWriter);
@ -456,7 +453,7 @@ public class Controller {
clientCodeJsonWriter.write("base", (String) theModel.get("base")); clientCodeJsonWriter.write("base", (String) theModel.get("base"));
CaptureInterceptor interceptor = new CaptureInterceptor(); CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(getContext(theRequest), myConfig, interceptor); GenericClient client = theRequest.newClient(theReq, getContext(theRequest), myConfig, interceptor);
IUntypedQuery search = client.search(); IUntypedQuery search = client.search();
IQuery query; IQuery query;
@ -548,11 +545,11 @@ public class Controller {
} }
@RequestMapping(value = { "/transaction" }) @RequestMapping(value = { "/transaction" })
public String actionTransaction(final TransactionRequest theRequest, final BindingResult theBindingResult, final ModelMap theModel) { public String actionTransaction(HttpServletRequest theServletRequest, final TransactionRequest theRequest, final BindingResult theBindingResult, final ModelMap theModel) {
addCommonParams(theRequest, theModel); addCommonParams(theServletRequest, theRequest, theModel);
CaptureInterceptor interceptor = new CaptureInterceptor(); CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(getContext(theRequest), myConfig, interceptor); GenericClient client = theRequest.newClient(theServletRequest, getContext(theRequest), myConfig, interceptor);
String body = preProcessMessageBody(theRequest.getTransactionBody()); String body = preProcessMessageBody(theRequest.getTransactionBody());
@ -599,13 +596,13 @@ public class Controller {
return "result"; return "result";
} }
private IResource addCommonParams(final HomeRequest theRequest, final ModelMap theModel) { private IResource addCommonParams(HttpServletRequest theServletRequest, final HomeRequest theRequest, final ModelMap theModel) {
if (myConfig.getDebugTemplatesMode()) { if (myConfig.getDebugTemplatesMode()) {
myTemplateEngine.getCacheManager().clearAllCaches(); myTemplateEngine.getCacheManager().clearAllCaches();
} }
final String serverId = theRequest.getServerIdWithDefault(myConfig); final String serverId = theRequest.getServerIdWithDefault(myConfig);
final String serverBase = theRequest.getServerBase(myConfig); final String serverBase = theRequest.getServerBase(theServletRequest, myConfig);
final String serverName = theRequest.getServerName(myConfig); final String serverName = theRequest.getServerName(myConfig);
theModel.put("serverId", serverId); theModel.put("serverId", serverId);
theModel.put("base", serverBase); theModel.put("base", serverBase);
@ -615,7 +612,7 @@ public class Controller {
theModel.put("pretty", theRequest.getPretty()); theModel.put("pretty", theRequest.getPretty());
theModel.put("serverEntries", myConfig.getIdToServerName()); theModel.put("serverEntries", myConfig.getIdToServerName());
return loadAndAddConf(theRequest, theModel); return loadAndAddConf(theServletRequest, theRequest, theModel);
} }
private Header[] applyHeaderFilters(Header[] theAllHeaders) { private Header[] applyHeaderFilters(Header[] theAllHeaders) {
@ -634,10 +631,10 @@ public class Controller {
private void doActionCreateOrValidate(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel, String theMethod) { private void doActionCreateOrValidate(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel, String theMethod) {
boolean validate = "validate".equals(theMethod); boolean validate = "validate".equals(theMethod);
addCommonParams(theRequest, theModel); addCommonParams(theReq, theRequest, theModel);
CaptureInterceptor interceptor = new CaptureInterceptor(); CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(getContext(theRequest), myConfig, interceptor); GenericClient client = theRequest.newClient(theReq, getContext(theRequest), myConfig, interceptor);
Class<? extends IResource> type = null; // def.getImplementingClass(); Class<? extends IResource> type = null; // def.getImplementingClass();
if ("history-type".equals(theMethod)) { if ("history-type".equals(theMethod)) {
@ -716,10 +713,10 @@ public class Controller {
} }
private void doActionHistory(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel, String theMethod, String theMethodDescription) { private void doActionHistory(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel, String theMethod, String theMethodDescription) {
addCommonParams(theRequest, theModel); addCommonParams(theReq, theRequest, theModel);
CaptureInterceptor interceptor = new CaptureInterceptor(); CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(getContext(theRequest), myConfig, interceptor); GenericClient client = theRequest.newClient(theReq, getContext(theRequest), myConfig, interceptor);
String id = null; String id = null;
Class<? extends IResource> type = null; // def.getImplementingClass(); Class<? extends IResource> type = null; // def.getImplementingClass();
@ -1009,20 +1006,20 @@ public class Controller {
return true; return true;
} }
private IResource loadAndAddConf(final HomeRequest theRequest, final ModelMap theModel) { private IResource loadAndAddConf(HttpServletRequest theServletRequest, final HomeRequest theRequest, final ModelMap theModel) {
switch (theRequest.getFhirVersion(myConfig)) { switch (theRequest.getFhirVersion(myConfig)) {
case DEV: case DEV:
return loadAndAddConfDev(theRequest, theModel); return loadAndAddConfDev(theServletRequest, theRequest, theModel);
case DSTU1: case DSTU1:
return loadAndAddConfDstu1(theRequest, theModel); return loadAndAddConfDstu1(theServletRequest, theRequest, theModel);
case DSTU2: case DSTU2:
return loadAndAddConfDev(theRequest, theModel); return loadAndAddConfDev(theServletRequest, theRequest, theModel);
} }
throw new IllegalStateException("Unknown version: " + theRequest.getFhirVersion(myConfig)); throw new IllegalStateException("Unknown version: " + theRequest.getFhirVersion(myConfig));
} }
private Conformance loadAndAddConfDstu1(final HomeRequest theRequest, final ModelMap theModel) { private Conformance loadAndAddConfDstu1(HttpServletRequest theServletRequest, final HomeRequest theRequest, final ModelMap theModel) {
IGenericClient client = getContext(theRequest).newRestfulGenericClient(theRequest.getServerBase(myConfig)); IGenericClient client = getContext(theRequest).newRestfulGenericClient(theRequest.getServerBase(theServletRequest, myConfig));
Conformance conformance; Conformance conformance;
try { try {
@ -1080,8 +1077,8 @@ public class Controller {
return conformance; return conformance;
} }
private IResource loadAndAddConfDev(final HomeRequest theRequest, final ModelMap theModel) { private IResource loadAndAddConfDev(HttpServletRequest theServletRequest, final HomeRequest theRequest, final ModelMap theModel) {
IGenericClient client = getContext(theRequest).newRestfulGenericClient(theRequest.getServerBase(myConfig)); IGenericClient client = getContext(theRequest).newRestfulGenericClient(theRequest.getServerBase(theServletRequest, myConfig));
ca.uhn.fhir.model.dstu2.resource.Conformance conformance; ca.uhn.fhir.model.dstu2.resource.Conformance conformance;
try { try {

View File

@ -1,7 +1,8 @@
package ca.uhn.fhir.to.model; package ca.uhn.fhir.to.model;
import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.*;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import javax.servlet.http.HttpServletRequest;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpRequestBase;
@ -38,12 +39,23 @@ public class HomeRequest {
return myResource; return myResource;
} }
public String getServerBase(TesterConfig theConfig) { public String getServerBase(HttpServletRequest theRequest, TesterConfig theConfig) {
String retVal;
if (isBlank(myServerId) && !theConfig.getIdToServerBase().containsKey(myServerId)) { if (isBlank(myServerId) && !theConfig.getIdToServerBase().containsKey(myServerId)) {
return theConfig.getIdToServerBase().entrySet().iterator().next().getValue(); retVal = theConfig.getIdToServerBase().entrySet().iterator().next().getValue();
} else { } else {
return theConfig.getIdToServerBase().get(myServerId); retVal = theConfig.getIdToServerBase().get(myServerId);
} }
if (retVal.contains("${serverBase}")) {
String base = theRequest.getRequestURL().toString();
if (base.endsWith("/")) {
base = base.substring(0, base.length() - 1);
}
retVal = retVal.replace("${serverBase}", base);
}
return retVal;
} }
@ModelAttribute("serverId") @ModelAttribute("serverId")
@ -91,8 +103,8 @@ public class HomeRequest {
myServerId = theServerId; myServerId = theServerId;
} }
public GenericClient newClient(FhirContext theContext, TesterConfig theConfig, Controller.CaptureInterceptor theInterceptor) { public GenericClient newClient(HttpServletRequest theRequest, FhirContext theContext, TesterConfig theConfig, Controller.CaptureInterceptor theInterceptor) {
GenericClient retVal = (GenericClient) theContext.newRestfulGenericClient(getServerBase(theConfig)); GenericClient retVal = (GenericClient) theContext.newRestfulGenericClient(getServerBase(theRequest, theConfig));
retVal.setKeepResponses(true); retVal.setKeepResponses(true);
if ("true".equals(getPretty())) { if ("true".equals(getPretty())) {
@ -125,7 +137,6 @@ public class HomeRequest {
} }
}); });
return retVal; return retVal;
} }
@ -136,5 +147,4 @@ public class HomeRequest {
return theCtx.newXmlParser(); return theCtx.newXmlParser();
} }
} }

8
vagrant/Vagrantfile vendored
View File

@ -84,7 +84,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
base_version: 7, base_version: 7,
proxy_port: 80, proxy_port: 80,
# ssl_port: 443, # ssl_port: 443,
authbind: 'yes' authbind: 'yes',
java_options: '-Dfhir.logdir=/var/log/fhir -Dfhir.db.location=/var/fhirdb'
}, },
mysql: { mysql: {
version: '5.6', version: '5.6',
@ -107,6 +108,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
FileUtils.cp(f, 'build') FileUtils.cp(f, 'build')
end end
config.vm.provision 'shell', inline: 'mkdir /var/log/fhir'
config.vm.provision 'shell', inline: 'chmod 777 /var/log/fhir'
config.vm.provision 'shell', inline: 'mkdir /var/fhirdb'
config.vm.provision 'shell', inline: 'chmod 777 /var/fhirdb'
# puts "Deploying any/all built .war files."" # puts "Deploying any/all built .war files.""
config.vm.provision 'shell', inline: 'cp /build/*.war /var/lib/tomcat7/webapps' config.vm.provision 'shell', inline: 'cp /build/*.war /var/lib/tomcat7/webapps'

View File

@ -43,7 +43,6 @@ v0.15.4 (2014-02-18)
### Bug ### Bug
- **[COOK-4257](https://tickets.opscode.com/browse/COOK-4257)** - tomcat: broken on SmartOS SmartMachine images 13.3.0+ - **[COOK-4257](https://tickets.opscode.com/browse/COOK-4257)** - tomcat: broken on SmartOS SmartMachine images 13.3.0+
- **[COOK-4097](https://tickets.opscode.com/browse/COOK-4097)** - default["tomcat"]["keytool"] is set to non-existent file on Debian/Ubuntu
v0.15.2 v0.15.2