package example.spring.filter;

import org.apache.commons.lang.RandomStringUtils;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class VersionFilter extends OncePerRequestFilter {

    private String version = RandomStringUtils.randomAlphanumeric(7);

    public void setVersion(String version) {
        this.version = version;
    }

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {

        request.setAttribute("version", version);
        filterChain.doFilter(request, response);
    }
}

@@ -29,58 +29,8 @@
 r;%0A%0A
-import org.apache.commons.lang.RandomStringUtils;%0A
 impo
@@ -281,16 +281,159 @@
 ption;%0A%0A
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;%0Aimport static org.apache.commons.lang.StringUtils.defaultIfEmpty;%0A%0A
 public c
@@ -513,50 +513,8 @@
 sion
- = RandomStringUtils.randomAlphanumeric(7)
 ;%0A%0A 
@@ -821,23 +821,62 @@
 rsion%22, 
-version
+defaultIfEmpty(version, randomAlphanumeric(7))
 );%0A     

version per-request or whatever you set in web.xml