Better logging for public server

This commit is contained in:
James Agnew 2014-12-23 15:44:54 -05:00
parent 81851f4808
commit b856c2386b
4 changed files with 29 additions and 16 deletions

View File

@ -68,6 +68,10 @@ import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
* <td>${requestParameters}</td>
* <td>The HTTP request parameters (or "")</td>
* </tr>
* <tr>
* <td>${servletPath}</td>
* <td>The part of thre requesting URL that corresponds to the particular Servlet being called (see {@link HttpServletRequest#getServletPath()})</td>
* </tr>
* </table>
*/
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<String, String[]> 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!";

View File

@ -49,6 +49,7 @@ public class TestRestfulServer extends RestfulServer {
List<IResourceProvider> 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);
}

View File

@ -13,7 +13,7 @@
<property name="servers">
<list>
<value>home , DSTU1 , UHN/HAPI Server (DSTU1 FHIR) , http://fhirtest.uhn.ca/baseDstu1</value>
<value>home_dev , DEV , UHN/HAPI Server (DSTU2 FHIR) , http://fhirtest.uhn.ca/baseDev</value>
<value>home_dev , DEV , UHN/HAPI Server (DSTU2 FHIR) , http://fhirtest.uhn.ca/baseDstu2</value>
<value>hi , DSTU1 , Health Intersections (DSTU1 FHIR) , http://fhir.healthintersections.com.au/open</value>
<value>hidev , DEV , Health Intersections (DSTU2 FHIR) , http://fhir-dev.healthintersections.com.au/open</value>
<value>furore , DSTU1 , Spark - Furore , http://spark.furore.com/fhir</value>

View File

@ -71,6 +71,11 @@
<url-pattern>/baseDstu1/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>fhirServletDev</servlet-name>
<url-pattern>/baseDstu2/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>fhirServletDev</servlet-name>
<url-pattern>/baseDev/*</url-pattern>