use of com.spotify.helios.common.VersionCompatibility.Status in project helios by spotify.
the class VersionResponseFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// If ever there was a valid use of goto, this would be it... if Java had it.
if (!(request instanceof HttpServletRequest)) {
log.debug("request is not HTTP");
chain.doFilter(request, response);
return;
}
final HttpServletRequest httpReq = (HttpServletRequest) request;
final HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.addHeader(HELIOS_SERVER_VERSION_HEADER, SERVER_VERSION.toString());
final String header = httpReq.getHeader(HELIOS_VERSION_HEADER);
if (header == null) {
log.debug("No header " + HELIOS_VERSION_HEADER);
httpResponse.addHeader(HELIOS_VERSION_STATUS_HEADER, MISSING.toString());
chain.doFilter(request, response);
return;
}
final PomVersion clientVersion;
try {
clientVersion = PomVersion.parse(header);
} catch (RuntimeException e) {
log.debug("failure to parse version header " + header);
httpResponse.addHeader(HELIOS_VERSION_STATUS_HEADER, INVALID.toString());
httpResponse.sendError(400, "Helios client version format is bogus - expect n.n.n");
return;
}
metrics.clientVersion(clientVersion.toString());
final Status status = getStatus(SERVER_VERSION, clientVersion);
httpResponse.addHeader(HELIOS_VERSION_STATUS_HEADER, status.toString());
if (status == Status.INCOMPATIBLE) {
log.debug("version " + clientVersion + " is incompatible");
httpResponse.sendError(426, "Your client version is incompatible with the server version " + POM_VERSION);
} else {
log.debug("version " + clientVersion + " state " + status);
chain.doFilter(request, response);
}
}
Aggregations