Better logging for public server
This commit is contained in:
parent
81851f4808
commit
b856c2386b
|
@ -68,6 +68,10 @@ import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
||||||
* <td>${requestParameters}</td>
|
* <td>${requestParameters}</td>
|
||||||
* <td>The HTTP request parameters (or "")</td>
|
* <td>The HTTP request parameters (or "")</td>
|
||||||
* </tr>
|
* </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>
|
* </table>
|
||||||
*/
|
*/
|
||||||
public class LoggingInterceptor extends InterceptorAdapter {
|
public class LoggingInterceptor extends InterceptorAdapter {
|
||||||
|
@ -76,7 +80,7 @@ public class LoggingInterceptor extends InterceptorAdapter {
|
||||||
|
|
||||||
private Logger myLogger = ourLog;
|
private Logger myLogger = ourLog;
|
||||||
private String myMessageFormat = "${operationType} - ${idOrResourceName}";
|
private String myMessageFormat = "${operationType} - ${idOrResourceName}";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean incomingRequestPostProcessed(final RequestDetails theRequestDetails, final HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
|
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 myRequestDetails.getOtherOperationType().getCode();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
} else if ("id".equals(theKey)) {
|
||||||
if ("id".equals(theKey)) {
|
|
||||||
if (myRequestDetails.getId() != null) {
|
if (myRequestDetails.getId() != null) {
|
||||||
return myRequestDetails.getId().getValue();
|
return myRequestDetails.getId().getValue();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
} else if ("servletPath".equals(theKey)) {
|
||||||
if ("idOrResourceName".equals(theKey)) {
|
return StringUtils.defaultString(myRequest.getServletPath());
|
||||||
|
} else if ("idOrResourceName".equals(theKey)) {
|
||||||
if (myRequestDetails.getId() != null) {
|
if (myRequestDetails.getId() != null) {
|
||||||
return myRequestDetails.getId().getValue();
|
return myRequestDetails.getId().getValue();
|
||||||
}
|
}
|
||||||
|
@ -147,8 +151,7 @@ public class LoggingInterceptor extends InterceptorAdapter {
|
||||||
return myRequestDetails.getResourceName();
|
return myRequestDetails.getResourceName();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
} else if (theKey.equals("requestParameters")) {
|
||||||
if (theKey.equals("requestParameters")) {
|
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
for (Entry<String, String[]> next : myRequestDetails.getParameters().entrySet()) {
|
for (Entry<String, String[]> next : myRequestDetails.getParameters().entrySet()) {
|
||||||
for (String nextValue : next.getValue()) {
|
for (String nextValue : next.getValue()) {
|
||||||
|
@ -167,12 +170,10 @@ public class LoggingInterceptor extends InterceptorAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return b.toString();
|
return b.toString();
|
||||||
}
|
} else if (theKey.startsWith("requestHeader.")) {
|
||||||
if (theKey.startsWith("requestHeader.")) {
|
|
||||||
String val = myRequest.getHeader(theKey.substring("requestHeader.".length()));
|
String val = myRequest.getHeader(theKey.substring("requestHeader.".length()));
|
||||||
return StringUtils.defaultString(val);
|
return StringUtils.defaultString(val);
|
||||||
}
|
} else if (theKey.startsWith("remoteAddr")) {
|
||||||
if (theKey.startsWith("remoteAddr")) {
|
|
||||||
return StringUtils.defaultString(myRequest.getRemoteAddr());
|
return StringUtils.defaultString(myRequest.getRemoteAddr());
|
||||||
}
|
}
|
||||||
return "!VAL!";
|
return "!VAL!";
|
||||||
|
|
|
@ -49,6 +49,7 @@ public class TestRestfulServer extends RestfulServer {
|
||||||
List<IResourceProvider> beans;
|
List<IResourceProvider> beans;
|
||||||
JpaSystemProvider systemProvider;
|
JpaSystemProvider systemProvider;
|
||||||
IFhirSystemDao systemDao;
|
IFhirSystemDao systemDao;
|
||||||
|
String baseUrlProperty;
|
||||||
switch (fhirVersionParam.trim().toUpperCase()) {
|
switch (fhirVersionParam.trim().toUpperCase()) {
|
||||||
case "DSTU":
|
case "DSTU":
|
||||||
case "DSTU1": {
|
case "DSTU1": {
|
||||||
|
@ -59,6 +60,7 @@ public class TestRestfulServer extends RestfulServer {
|
||||||
JpaConformanceProviderDstu1 confProvider = new JpaConformanceProviderDstu1(this, systemDao);
|
JpaConformanceProviderDstu1 confProvider = new JpaConformanceProviderDstu1(this, systemDao);
|
||||||
confProvider.setImplementationDescription(implDesc);
|
confProvider.setImplementationDescription(implDesc);
|
||||||
setServerConformanceProvider(confProvider);
|
setServerConformanceProvider(confProvider);
|
||||||
|
baseUrlProperty = "fhir.baseurl.dstu1";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "DEV": {
|
case "DEV": {
|
||||||
|
@ -69,6 +71,7 @@ public class TestRestfulServer extends RestfulServer {
|
||||||
JpaConformanceProviderDev confProvider = new JpaConformanceProviderDev(this, systemDao);
|
JpaConformanceProviderDev confProvider = new JpaConformanceProviderDev(this, systemDao);
|
||||||
confProvider.setImplementationDescription(implDesc);
|
confProvider.setImplementationDescription(implDesc);
|
||||||
setServerConformanceProvider(confProvider);
|
setServerConformanceProvider(confProvider);
|
||||||
|
baseUrlProperty = "fhir.baseurl.dstu2";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -83,12 +86,16 @@ public class TestRestfulServer extends RestfulServer {
|
||||||
|
|
||||||
FhirContext ctx = getFhirContext();
|
FhirContext ctx = getFhirContext();
|
||||||
ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
|
ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
|
||||||
|
|
||||||
setUseBrowserFriendlyContentTypes(true);
|
setUseBrowserFriendlyContentTypes(true);
|
||||||
|
|
||||||
String baseUrl = System.getProperty("fhir.baseurl");
|
String baseUrl = System.getProperty(baseUrlProperty);
|
||||||
if (StringUtils.isBlank(baseUrl)) {
|
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));
|
setServerAddressStrategy(new HardcodedServerAddressStrategy(baseUrl));
|
||||||
|
@ -96,7 +103,7 @@ public class TestRestfulServer extends RestfulServer {
|
||||||
|
|
||||||
LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
|
LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
|
||||||
loggingInterceptor.setLoggerName("fhirtest.access");
|
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);
|
this.registerInterceptor(loggingInterceptor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<property name="servers">
|
<property name="servers">
|
||||||
<list>
|
<list>
|
||||||
<value>home , DSTU1 , UHN/HAPI Server (DSTU1 FHIR) , http://fhirtest.uhn.ca/baseDstu1</value>
|
<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>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>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>
|
<value>furore , DSTU1 , Spark - Furore , http://spark.furore.com/fhir</value>
|
||||||
|
|
|
@ -71,6 +71,11 @@
|
||||||
<url-pattern>/baseDstu1/*</url-pattern>
|
<url-pattern>/baseDstu1/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>fhirServletDev</servlet-name>
|
||||||
|
<url-pattern>/baseDstu2/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>fhirServletDev</servlet-name>
|
<servlet-name>fhirServletDev</servlet-name>
|
||||||
<url-pattern>/baseDev/*</url-pattern>
|
<url-pattern>/baseDev/*</url-pattern>
|
||||||
|
|
Loading…
Reference in New Issue