After recently upgrading to DXA 1.2, have noticed that new PageController
introduced handleGetPageFormatted()
which is suppose to be used for responding with formatted (mostly other than text/html) output for a requested resource.
This works fine almost most of the time except in case, there is no Accept header parameter in request. DefaultDataFormatter
's getHtmlAcceptScore()
gives null pointer exception, in absence of Accept
header parameter.
In our we are using Varnish Cache, which is configured as part of our load balancer setup. This varnish cache probes the application boxes for availability. If the servers fails to respond the probe they are marked sick and not reachable. After investigation understood that by default it doesn't send any header. Settings below for a probe:
backend www1 {
.host = "xx.xx.xx.xx";
.port = "80";
.probe = {
.url = "/";
.interval = 5s;
.timeout = 3s;
.window = 5;
.threshold = 3;
}
}
By having a consumes attribute set on handleGetPageFormatted()
's @RequestMapping
, could solve problem. As it would mean only map the request which accepts a particular type of Media Type.
Will try this and update this case.
Has anyone faced the similar issue.
Edit: Another way to address could be by sending the Accept header as part of Probe request itself, which was not the requirement in earlier version of DXA. Example below:
.request =
"GET /probe.cgi HTTP/1.1"
"Host: 127.0.0.2"
"Connection: close"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
"Accept-Encoding: foo/bar" ;