Refactor HTTP request methods and update Javadoc language.

Refactored HTTP request methods by removing explicit `responseType` parameters where possible and adjusting to specific response mapping needs. Additionally, updated Javadoc documentation language from German to English for consistency, improving clarity and accessibility.
This commit is contained in:
2025-03-23 18:39:36 +01:00
parent af757714f4
commit e415dc1106
69 changed files with 3278 additions and 3743 deletions
@@ -106,29 +106,29 @@ abstract class CfBasicHttpClient {
}
/** Sends a GET request to the given endpoint and maps the response. */
protected <T extends AbstractResponse> T getRequest(String endpoint, Class<T> responseType)
<T extends AbstractResponse> T getRequest(String endpoint, Class<T> responseType)
throws CloudflareApiException {
HttpGet request = new HttpGet(buildUrl(endpoint));
return executeRequest(request, responseType);
}
/** Sends a DELETE request to the given endpoint and maps the response. */
protected <T extends AbstractResponse> T deleteRequest(String endpoint, Class<T> responseType)
<T extends AbstractResponse> T deleteRequest(String endpoint)
throws CloudflareApiException {
HttpDelete request = new HttpDelete(buildUrl(endpoint));
return executeRequest(request, responseType);
return executeRequest(request, (Class<T>) codes.thischwa.cf.model.RecordSingleResponse.class);
}
/** Sends a POST request with a payload to the given endpoint and maps the response. */
protected <T extends AbstractResponse, R extends AbstractEntity> T postRequest(
String endpoint, R requestPayload, Class<T> responseType) throws CloudflareApiException {
<T extends AbstractResponse, R extends AbstractEntity> T postRequest(
String endpoint, R requestPayload) throws CloudflareApiException {
HttpPost request = new HttpPost(buildUrl(endpoint));
setRequestPayload(request, requestPayload);
return executeRequest(request, responseType);
return executeRequest(request, (Class<T>) codes.thischwa.cf.model.RecordSingleResponse.class);
}
/** Sends a PUT request with a payload to the given endpoint and maps the response. */
protected <T extends AbstractResponse, R extends AbstractEntity> T putRequest(
<T extends AbstractResponse, R extends AbstractEntity> T putRequest(
String endpoint, R requestPayload, Class<T> responseType) throws CloudflareApiException {
HttpPut request = new HttpPut(buildUrl(endpoint));
setRequestPayload(request, requestPayload);
@@ -136,11 +136,11 @@ abstract class CfBasicHttpClient {
}
/** Sends a PATCH request with a payload to the given endpoint and maps the response. */
protected <T extends AbstractResponse, R extends AbstractEntity> T patchRequest(
String endpoint, R requestPayload, Class<T> responseType) throws CloudflareApiException {
<T extends AbstractResponse, R extends AbstractEntity> T patchRequest(
String endpoint, R requestPayload) throws CloudflareApiException {
HttpPatch request = new HttpPatch(buildUrl(endpoint));
setRequestPayload(request, requestPayload);
return executeRequest(request, responseType);
return executeRequest(request, (Class<T>) codes.thischwa.cf.model.RecordSingleResponse.class);
}
/** Sets the JSON payload for a request. */
@@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
* deleting DNS records.
*
* <p>Example:
*
* <pre><code>
* // Create a new CfDnsClient instance
* CfDnsClient client = new CfDnsClient(
@@ -94,9 +95,7 @@ public class CfDnsClient extends CfBasicHttpClient {
}
/**
* Retrieves a list of all zones from the Cloudflare API. <br>
* This method sends a GET request to the Cloudflare API endpoint for listing zones, processes the
* response, and returns the resulting list of ZoneEntity objects.
* Retrieves a list of all zones from the Cloudflare API.
*
* @return A list of ZoneEntity objects representing the zones retrieved from the Cloudflare API.
* @throws CloudflareApiException If an error occurs during the API request or response handling.
@@ -106,12 +105,13 @@ public class CfDnsClient extends CfBasicHttpClient {
}
/**
* Retrieves a list of all zones from the Cloudflare API. <br>
* This method sends a GET request to the Cloudflare API endpoint for listing zones, processes the
* response, and returns the resulting list of ZoneEntity objects.
* Retrieves a list of all DNS zones using the provided paging request parameters.
*
* @return A list of ZoneEntity objects representing the zones retrieved from the Cloudflare API.
* @throws CloudflareApiException If an error occurs during the API request or response handling.
* @param pagingRequest the pagination request object containing parameters for paging and
* filtering zone data
* @return a list of {@code ZoneEntity} objects representing the DNS zones retrieved from the API
* @throws CloudflareApiException if there is an error during the API request or response
* processing
*/
public List<ZoneEntity> zoneListAll(PagingRequest pagingRequest) throws CloudflareApiException {
String endpoint = pagingRequest.addQueryString(CfRequest.ZONE_LIST.buildPath());
@@ -200,7 +200,7 @@ public class CfDnsClient extends CfBasicHttpClient {
public RecordEntity recordCreate(ZoneEntity zone, RecordEntity rec)
throws CloudflareApiException {
String endpoint = CfRequest.RECORD_CREATE.buildPath(zone.getId());
RecordSingleResponse resp = postRequest(endpoint, rec, RecordSingleResponse.class);
RecordSingleResponse resp = postRequest(endpoint, rec);
checkResponse(resp);
return resp.getResult();
}
@@ -235,7 +235,7 @@ public class CfDnsClient extends CfBasicHttpClient {
*/
public boolean recordDelete(ZoneEntity zone, String id) throws CloudflareApiException {
String endpoint = CfRequest.RECORD_DELETE.buildPath(zone.getId(), id);
RecordSingleResponse resp = deleteRequest(endpoint, RecordSingleResponse.class);
RecordSingleResponse resp = deleteRequest(endpoint);
checkResponse(resp);
return resp.getResult().getId().equals(id);
}
@@ -255,7 +255,7 @@ public class CfDnsClient extends CfBasicHttpClient {
rec.setModifiedOn(null);
rec.setCreatedOn(null);
String endpoint = CfRequest.RECORD_UPDATE.buildPath(zone.getId(), rec.getId());
RecordSingleResponse resp = patchRequest(endpoint, rec, RecordSingleResponse.class);
RecordSingleResponse resp = patchRequest(endpoint, rec);
checkResponse(resp);
return resp.getResult();
}
+34 -2
View File
@@ -9,15 +9,47 @@ import lombok.Getter;
@Getter
public enum CfRequest {
// for handling zones
/**
* Represents the API endpoint path for retrieving the list of DNS zones.
*/
ZONE_LIST("/zones"),
/**
* Represents the API endpoint path for retrieving information about a specific DNS zone
* by its name. The endpoint path supports a placeholder for the zone name, which needs
* to be provided to construct the complete path.
*/
ZONE_INFO("/zones?name=%s"),
// for handling records
/**
* Represents the API endpoint path for creating a new DNS record within a specific DNS zone.
* The endpoint path includes a placeholder for the zone identifier, which needs to
* be provided to construct the complete path.
*/
RECORD_CREATE("/zones/%s/dns_records"),
/**
* Represents the API endpoint path for retrieving information about a DNS record within a specific
* DNS zone by its name. The endpoint path includes placeholders for the zone identifier and
* the record name, which need to be provided to construct the complete path.
*/
RECORD_INFO_NAME("/zones/%s/dns_records?name=%s"),
/**
* Represents the API endpoint path for retrieving information about a DNS record within a specific
* DNS zone by its name and type.
* The endpoint path includes placeholders for the zone identifier, record name, and record type,
* which need to be provided to construct the complete path.
*/
RECORD_INFO_NAME_TYPE("/zones/%s/dns_records?name=%s&type=%s"),
/**
* Represents the API endpoint path for updating an existing DNS record within a specific DNS zone.
* The endpoint path includes placeholders for the zone identifier and the record identifier,
* which need to be provided to construct the complete path.
*/
RECORD_UPDATE("/zones/%s/dns_records/%s"),
/**
* Represents the API endpoint path for deleting an existing DNS record within a specific DNS zone.
* The endpoint path includes placeholders for the zone identifier and the record identifier,
* which need to be provided to construct the complete path.
*/
RECORD_DELETE("/zones/%s/dns_records/%s");
private static final char varIdentification = '%';
@@ -22,10 +22,24 @@ import lombok.EqualsAndHashCode;
* </ul>
*
* <p>Subclasses can be created by specifying the entity type that the response should handle.
*
* @param <T> Represents the type of entities contained within the response. For this class, it is
* expected to be {@code ResponseEntity}.
*/
@EqualsAndHashCode(callSuper = true)
@Data
public abstract class AbstractMultipleResponse<T extends ResponseEntity> extends AbstractResponse {
private ResultInfo resultInfo;
private List<T> result;
/**
* Default constructor for the {@code AbstractMultipleResponse} class.
*
* <p>Initializes a new instance of {@code AbstractMultipleResponse}, invoking the default
* constructor of the superclass {@code AbstractResponse}. This constructor is typically used for
* deserialization or subclass instantiation.
*/
public AbstractMultipleResponse() {
super();
}
}
@@ -39,6 +39,16 @@ public class RecordEntity extends AbstractEntity {
@Nullable private LocalDateTime modifiedOn;
@Nullable private LocalDateTime createdOn;
/**
* Initializes a new instance of the RecordEntity class and invokes the parent constructor
* from the AbstractEntity class. The RecordEntity class represents a DNS record entity
* within a specific zone, encapsulating attributes such as type, name, content, TTL,
* and other related metadata.
*/
public RecordEntity() {
super();
}
/**
* Builds and returns a {@link RecordEntity} instance with the specified attributes.
*
@@ -1,4 +1,16 @@
package codes.thischwa.cf.model;
/** Represents the API response of the Cloudflare API containing multiple DNS record entities. */
public class RecordMultipleResponse extends AbstractMultipleResponse<RecordEntity> {}
public class RecordMultipleResponse extends AbstractMultipleResponse<RecordEntity> {
/**
* Constructs an instance of RecordMultipleResponse.
*
* <p>This class represents a response containing multiple DNS record entities from the Cloudflare
* API. It inherits functionality from AbstractMultipleResponse to handle multiple records of type
* RecordEntity.
*/
public RecordMultipleResponse() {
super();
}
}
@@ -1,4 +1,17 @@
package codes.thischwa.cf.model;
/** Represents the API response of the Cloudflare API containing a single DNS record entity. */
public class RecordSingleResponse extends AbstractSingleResponse<RecordEntity> {}
public class RecordSingleResponse extends AbstractSingleResponse<RecordEntity> {
/**
* Constructs a new instance of the RecordSingleResponse class.
*
* <p>This constructor initializes the RecordSingleResponse object by invoking the superclass
* constructor. The RecordSingleResponse represents a specific API response structure that
* encapsulates a single DNS record entity, providing mechanisms to interact with such data in the
* context of the Cloudflare API.
*/
public RecordSingleResponse() {
super();
}
}
@@ -11,26 +11,183 @@ import lombok.Getter;
*/
@Getter
public enum RecordType {
/**
* Represents the DNS A record type.
*
* <p>The "A" record type is used to map a domain name to an IPv4 address.
*/
A("A"),
/**
* Represents the DNS AAAA record type.
*
* <p>The "AAAA" record type maps a domain name to an IPv6 address.
*/
AAAA("AAAA"),
/**
* Represents the DNS CAA (Certificate Authority Authorization) record type.
*
* <p>The "CAA" record type is used to specify which certificate authorities (CAs) are allowed to
* issue SSL/TLS certificates for a domain.
*/
CAA("CAA"),
/**
* Represents the DNS CERT record type.
*
* <p>The "CERT" record type is used to store certificates and related certificate revocation
* lists or certificate authority data in DNS zones.
*/
CERT("CERT"),
/**
* Represents the DNS CNAME (Canonical Name) record type.
*
* <p>The "CNAME" record type is used to alias one domain name to another.
*/
CNAME("CNAME"),
/**
* Represents the DNSKEY record type.
*
* <p>The "DNSKEY" record type is used for storing public keys in DNS, as part of the DNS Security
* Extensions (DNSSEC). It helps in verifying the authenticity of DNS responses through digital
* signatures.
*/
DNSKEY("DNSKEY"),
/**
* Represents the DNS DS (Delegation Signer) record type.
*
* <p>The "DS" record type is used in the DNSSEC (Domain Name System Security Extensions)
* protocol. It contains a hash of a DNSKEY record which is utilized in establishing a chain of
* trust from a parent zone to a child zone.
*/
DS("DS"),
/**
* Represents the DNS HTTPS (HTTP Service) record type.
*
* <p>The "HTTPS" record type is used to specify information about the HTTP/3 and related services
* offered by a domain.
*/
HTTPS("HTTPS"),
/**
* Represents the DNS LOC (Location) record type.
*
* <p>The "LOC" record type is used to store geographical location information for a domain,
* including latitude, longitude, altitude, and other details. It enables associating domains with
* physical locations.
*/
LOC("LOC"),
/**
* Represents the DNS MX (Mail Exchange) record type.
*
* <p>The "MX" record type is used to specify the mail servers responsible for receiving email
* messages on behalf of a domain.
*/
MX("MX"),
/**
* Represents the NAPTR record type for DNS configurations.
*
* <p>This constant is used to specify NAPTR (Naming Authority Pointer) DNS records, which allow
* for service discovery through flexible DNS-based mechanisms. NAPTR records are commonly used in
* applications such as VoIP and ENUM (Telephone Number Mapping) for resolving information about
* available services.
*/
NAPTR("NAPTR"),
/**
* Represents the namespace or identifier `"NS"` within the domain model.
*
* <p>This variable typically designates elements related to name server operations or
* configurations in the context of the Cloudflare DNS system. It may be used as an identifier or
* constant throughout the application for operations involving name servers.
*/
NS("NS"),
/**
* Represents the "OPENPGPKEY" DNS record type.
*
* <p>This constant is primarily used to identify DNS records of the type "OPENPGPKEY". It may be
* utilized within the system for operations such as creating, retrieving, updating, or managing
* DNS records specific to the "OPENPGPKEY" type.
*/
OPENPGPKEY("OPENPGPKEY"),
/**
* Represents a DNS record type.
*
* <p>The `PTR` value specifically refers to a "pointer record" in the DNS system, which is
* typically used for reverse DNS lookups.
*/
PTR("PTR"),
/**
* Represents the SMIMEA DNS record type.
*
* <p>The SMIMEA resource record is used to associate a user's certificate information for email
* message signing or encryption. This type of DNS record is part of the DNS-based Authentication
* of Named Entities (DANE) protocol.
*
* <p>SMIMEA records provide a mechanism for utilizing certificates in email communication
* securely by publishing their information in DNS. They ensure integrity and authenticity of
* encrypted or signed email exchanges.
*
* <p>Key features include:
* <ul>
* <li>Use in Secure/Multipurpose Internet Mail Extensions (S/MIME)-based messaging.
* <li>Facilitating secure email communications by publishing certificates in DNS.
* <li>Enhancing security by eliminating dependency on third-party certificate authorities.
* </ul>
*/
SMIMEA("SMIMEA"),
/**
* Represents a service record (SRV) type in the DNS configuration model.
*
* <p>This constant may be used to identify and work with SRV record types in various DNS-related
* operations or integrations.
*/
SRV("SRV"),
/**
* Represents the DNS record type "SSHFP" (SSH Fingerprint), used in DNS to store cryptographic
* fingerprints associated with SSH host keys.
*
* <p>This DNS record type provides a mechanism for verifying the authenticity of an SSH server
* before initiating a connection, enhancing the security of SSH communications.
*/
SSHFP("SSHFP"),
/**
* Represents the Service Binding (SVCB) DNS record type.
*
* <p>The SVCB record is a DNS resource record used to indicate alternative endpoints or specific
* configuration details for services. It is commonly applied in service discovery and
* protocol-specific configurations.
*/
SVCB("SVCB"),
/**
* Represents a constant for the DNS-based Authentication of Named Entities (DANE) TLSA record
* type.
*
* <p>The TLSA record is used to associate a TLS server certificate or public key with the domain
* name (e.g., via DNSSEC). It enables cryptographically secured connections by attaching
* certificate and key constraints to the specific domain.
*/
TLSA("TLSA"),
/**
* Represents the TXT DNS record type.
*
* <p>The TXT DNS record type is commonly used to store text-based information for various
* verification and configuration purposes, such as domain ownership verification or email
* authentication protocols (e.g., SPF, DKIM).
*/
TXT("TXT"),
/**
* Represents a Uniform Resource Identifier (URI).
*
* <p>This variable is used to define and manage URIs, which are string identifiers commonly
* utilized to specify the location of resources in various network-based systems.
*
* <p>Features and usage:
*
* <ul>
* <li>Provides a standard way of identifying resources via URI syntax.
* <li>Can encapsulate support for schemes such as HTTP, HTTPS, FTP, etc.
* </ul>
*
* <p>This variable serves as a critical component for resource identification and communication
* operations within the application.
*/
URI("URI");
private final String type;
@@ -37,4 +37,15 @@ public class ZoneEntity extends AbstractEntity {
private String status;
private Boolean paused;
private String type;
/**
* Default no-argument constructor for the ZoneEntity class.
*
* <p>This constructor initializes a new instance of the ZoneEntity class and invokes the parent
* constructor from the AbstractEntity class. The ZoneEntity class represents a domain model for a
* DNS zone within the Cloudflare DNS system.
*/
public ZoneEntity() {
super();
}
}
@@ -1,4 +1,15 @@
package codes.thischwa.cf.model;
/** Represents a response model that contains multiple {@link ZoneEntity} instances. */
public class ZoneMultipleResponse extends AbstractMultipleResponse<ZoneEntity> {}
public class ZoneMultipleResponse extends AbstractMultipleResponse<ZoneEntity> {
/**
* Constructs a new ZoneMultipleResponse object.
*
* <p>This constructor initializes an instance of ZoneMultipleResponse, which serves as a response
* model containing multiple {@link ZoneEntity} instances.
*/
public ZoneMultipleResponse() {
super();
}
}