5

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" ;     
2
  • 1
    Nicely analyzed issue! Please report such issues on GitHub: github.com/sdl/dxa-web-application-java/issues if it's feasible to include an Accept header in the probe request, I would recommend that as a work-around rather than modifying the DXA framework code yourself. Commented Jan 4, 2016 at 18:52
  • reported this as an issue Commented Jan 5, 2016 at 9:30

1 Answer 1

4

Fixed the above said null pointer issue by doing null check on Accept header. Changes needs to be done in DefaultDataFormatter's getHtmlAcceptScore() and BaseFormatter's getValidTypes(List<String> allowedTypes) operations.

Now Varnish cache is able to probe the application successfully. We do not need to change @RequestMapping or in Varnish cache now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.