mirror of
https://github.com/google/nomulus.git
synced 2025-06-26 22:34:55 +02:00
Reduce duplicate code in the servlets
Currently, all 4 servlets (backend, frontend, pubapi, tools) have duplicates of the same exact code. That's an anti-pattern! Created a ServletBase they can all extend which has the duplicate code. As a bonus, the tools servlet now runs the metric reporter, meaning tool related metrics will now be reported! ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=219792176
This commit is contained in:
parent
545b68ad9a
commit
3f6585fccc
10 changed files with 31 additions and 183 deletions
|
@ -14,39 +14,18 @@
|
|||
|
||||
package google.registry.module.tools;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import google.registry.util.SystemClock;
|
||||
import java.io.IOException;
|
||||
import java.security.Security;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.joda.time.DateTime;
|
||||
import com.google.monitoring.metrics.MetricReporter;
|
||||
import dagger.Lazy;
|
||||
import google.registry.module.ServletBase;
|
||||
|
||||
/** Servlet that should handle all requests to our "tools" App Engine module. */
|
||||
public final class ToolsServlet extends HttpServlet {
|
||||
public final class ToolsServlet extends ServletBase {
|
||||
|
||||
private static final ToolsComponent component = DaggerToolsComponent.create();
|
||||
private static final ToolsRequestHandler requestHandler = component.requestHandler();
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
private static final SystemClock clock = new SystemClock();
|
||||
private static final Lazy<MetricReporter> metricReporter = component.metricReporter();
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void service(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
|
||||
logger.atInfo().log("Received tools request");
|
||||
DateTime startTime = clock.nowUtc();
|
||||
try {
|
||||
requestHandler.handleRequest(req, rsp);
|
||||
} finally {
|
||||
logger.atInfo().log(
|
||||
"Finished tools request. Latency: %.3fs",
|
||||
(clock.nowUtc().getMillis() - startTime.getMillis()) / 1000d);
|
||||
}
|
||||
public ToolsServlet() {
|
||||
super(requestHandler, metricReporter);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue