diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptor.java index 5dcdaa22e06..9ead6faca93 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptor.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptor.java @@ -68,6 +68,10 @@ import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; * ${requestParameters} * The HTTP request parameters (or "") * + * + * ${servletPath} + * The part of thre requesting URL that corresponds to the particular Servlet being called (see {@link HttpServletRequest#getServletPath()}) + * * */ public class LoggingInterceptor extends InterceptorAdapter { @@ -76,7 +80,7 @@ public class LoggingInterceptor extends InterceptorAdapter { private Logger myLogger = ourLog; private String myMessageFormat = "${operationType} - ${idOrResourceName}"; - + @Override public boolean incomingRequestPostProcessed(final RequestDetails theRequestDetails, final HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException { @@ -132,14 +136,14 @@ public class LoggingInterceptor extends InterceptorAdapter { return myRequestDetails.getOtherOperationType().getCode(); } return ""; - } - if ("id".equals(theKey)) { + } else if ("id".equals(theKey)) { if (myRequestDetails.getId() != null) { return myRequestDetails.getId().getValue(); } return ""; - } - if ("idOrResourceName".equals(theKey)) { + } else if ("servletPath".equals(theKey)) { + return StringUtils.defaultString(myRequest.getServletPath()); + } else if ("idOrResourceName".equals(theKey)) { if (myRequestDetails.getId() != null) { return myRequestDetails.getId().getValue(); } @@ -147,8 +151,7 @@ public class LoggingInterceptor extends InterceptorAdapter { return myRequestDetails.getResourceName(); } return ""; - } - if (theKey.equals("requestParameters")) { + } else if (theKey.equals("requestParameters")) { StringBuilder b = new StringBuilder(); for (Entry next : myRequestDetails.getParameters().entrySet()) { for (String nextValue : next.getValue()) { @@ -167,12 +170,10 @@ public class LoggingInterceptor extends InterceptorAdapter { } } return b.toString(); - } - if (theKey.startsWith("requestHeader.")) { + } else if (theKey.startsWith("requestHeader.")) { String val = myRequest.getHeader(theKey.substring("requestHeader.".length())); return StringUtils.defaultString(val); - } - if (theKey.startsWith("remoteAddr")) { + } else if (theKey.startsWith("remoteAddr")) { return StringUtils.defaultString(myRequest.getRemoteAddr()); } return "!VAL!"; diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java index f0d2b03043c..0c1820d5a19 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java @@ -49,6 +49,7 @@ public class TestRestfulServer extends RestfulServer { List beans; JpaSystemProvider systemProvider; IFhirSystemDao systemDao; + String baseUrlProperty; switch (fhirVersionParam.trim().toUpperCase()) { case "DSTU": case "DSTU1": { @@ -59,6 +60,7 @@ public class TestRestfulServer extends RestfulServer { JpaConformanceProviderDstu1 confProvider = new JpaConformanceProviderDstu1(this, systemDao); confProvider.setImplementationDescription(implDesc); setServerConformanceProvider(confProvider); + baseUrlProperty = "fhir.baseurl.dstu1"; break; } case "DEV": { @@ -69,6 +71,7 @@ public class TestRestfulServer extends RestfulServer { JpaConformanceProviderDev confProvider = new JpaConformanceProviderDev(this, systemDao); confProvider.setImplementationDescription(implDesc); setServerConformanceProvider(confProvider); + baseUrlProperty = "fhir.baseurl.dstu2"; break; } default: @@ -83,12 +86,16 @@ public class TestRestfulServer extends RestfulServer { FhirContext ctx = getFhirContext(); ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); - + setUseBrowserFriendlyContentTypes(true); - String baseUrl = System.getProperty("fhir.baseurl"); + String baseUrl = System.getProperty(baseUrlProperty); if (StringUtils.isBlank(baseUrl)) { - throw new ServletException("Missing system property: fhir.baseurl"); + // Fall back to the old URL + baseUrl = System.getProperty("fhir.baseurl"); + if (StringUtils.isBlank(baseUrl)) { + throw new ServletException("Missing system property: " + baseUrlProperty); + } } setServerAddressStrategy(new HardcodedServerAddressStrategy(baseUrl)); @@ -96,7 +103,7 @@ public class TestRestfulServer extends RestfulServer { LoggingInterceptor loggingInterceptor = new LoggingInterceptor(); loggingInterceptor.setLoggerName("fhirtest.access"); - loggingInterceptor.setMessageFormat("Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}]"); + loggingInterceptor.setMessageFormat("Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}]"); this.registerInterceptor(loggingInterceptor); } diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml index 5725f359e13..6731c447a37 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml @@ -13,7 +13,7 @@ home , DSTU1 , UHN/HAPI Server (DSTU1 FHIR) , http://fhirtest.uhn.ca/baseDstu1 - home_dev , DEV , UHN/HAPI Server (DSTU2 FHIR) , http://fhirtest.uhn.ca/baseDev + home_dev , DEV , UHN/HAPI Server (DSTU2 FHIR) , http://fhirtest.uhn.ca/baseDstu2 hi , DSTU1 , Health Intersections (DSTU1 FHIR) , http://fhir.healthintersections.com.au/open hidev , DEV , Health Intersections (DSTU2 FHIR) , http://fhir-dev.healthintersections.com.au/open furore , DSTU1 , Spark - Furore , http://spark.furore.com/fhir diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml index 07f1578b223..93a81b81e84 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml @@ -71,6 +71,11 @@ /baseDstu1/* + + fhirServletDev + /baseDstu2/* + + fhirServletDev /baseDev/*