Search in sources :

Example 1 with Status

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VersionCompatibility.getStatus(com.spotify.helios.common.VersionCompatibility.getStatus) Status(com.spotify.helios.common.VersionCompatibility.Status) PomVersion(com.spotify.helios.common.PomVersion) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Aggregations

PomVersion (com.spotify.helios.common.PomVersion)1 Status (com.spotify.helios.common.VersionCompatibility.Status)1 VersionCompatibility.getStatus (com.spotify.helios.common.VersionCompatibility.getStatus)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1