Simplify some of the RDAP Action classes

Overriding getter methods to change values is a bit overkill when these values
are static (don't change based on internal state).

Just setting them in the base class' constructor is simpler.

Also, we can read the PATH of an Action based on the Annotation instead
returning it manually for each Action.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=246135754
This commit is contained in:
guyben 2019-05-01 08:32:29 -07:00 committed by jianglai
parent 99aeedc598
commit 90c53152bf
21 changed files with 81 additions and 204 deletions

View file

@ -18,6 +18,7 @@ import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.net.HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.request.Actions.getPathForAction;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
@ -106,14 +107,25 @@ public abstract class RdapActionBase implements Runnable {
final RdapMetrics.RdapMetricInformation.Builder metricInformationBuilder =
RdapMetrics.RdapMetricInformation.builder();
/** Returns a string like "domain name" or "nameserver", used for error strings. */
abstract String getHumanReadableObjectTypeName();
private final String humanReadableObjectTypeName;
/** Returns the endpoint type used for recording metrics. */
abstract EndpointType getEndpointType();
/** Returns a string like "domain name" or "nameserver", used for error strings. */
final String getHumanReadableObjectTypeName() {
return humanReadableObjectTypeName;
}
/** The endpoint type used for recording metrics. */
private final EndpointType endpointType;
/** Returns the servlet action path; used to extract the search string from the incoming path. */
abstract String getActionPath();
final String getActionPath() {
return getPathForAction(getClass());
}
RdapActionBase(String humanReadableObjectTypeName, EndpointType endpointType) {
this.humanReadableObjectTypeName = humanReadableObjectTypeName;
this.endpointType = endpointType;
}
/**
* Does the actual search and returns an RDAP JSON object.
@ -135,7 +147,7 @@ public abstract class RdapActionBase implements Runnable {
metricInformationBuilder.setRegistrarSpecified(registrarParam.isPresent());
metricInformationBuilder.setRole(getAuthorization().role());
metricInformationBuilder.setRequestMethod(requestMethod);
metricInformationBuilder.setEndpointType(getEndpointType());
metricInformationBuilder.setEndpointType(endpointType);
try {
// Extract what we're searching for from the request path. Some RDAP commands use trailing
// data in the path itself (e.g. /rdap/domain/mydomain.com), and some use the query string