All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.isomorphism.dropwizard.version.VersionServlet Maven / Gradle / Ivy

package org.isomorphism.dropwizard.version;

import com.google.common.base.Supplier;
import com.google.common.io.Closeables;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static com.google.common.base.Preconditions.checkNotNull;

class VersionServlet extends HttpServlet {
  private final Supplier supplier;

  VersionServlet(Supplier supplier) {
    this.supplier = checkNotNull(supplier);
  }

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String version = supplier.get();
    if (version == null) {
      resp.sendError(500, "Unable to determine version.");
      return;
    }

    resp.setStatus(200);
    resp.setContentType("text/plain");

    ServletOutputStream out = resp.getOutputStream();
    try {
      out.print(version);
    } finally {
      Closeables.close(out, false);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy