diff --git a/README.md b/README.md index 0ed35098..d861f5bc 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ Core lib's Maven group ID is `io.apimatic`, and its artifact ID is `core`. | [`Or`](./src/main/java/io/apimatic/core/authentication/multiple/Or.java) | A class to hold the algorithm for `Or` combination of auth schemes | | [`Single`](./src/main/java/io/apimatic/core/authentication/multiple/Single.java) | A class to hold the logic for single auth scheme, it is used as leaf node for auth combination or it could be used directly to apply one auth only to the http request | | [`CoreHttpClientConfiguration`](./src/main/java/io/apimatic/core/configurations/http/client/CoreHttpClientConfiguration.java) | To hold HTTP Client Configuration | +| [`CoreProxyConfiguration`](./src/main/java/io/apimatic/core/configurations/http/client/CoreProxyConfiguration.java) | To hold the Proxy configuration for the underlying HTTP client instance. | | [`EndpointConfiguration`](./src/main/java/io/apimatic/core/configurations/http/request/EndpointConfiguration.java) | The configuration for an endpoint | | [`AsyncExecutor`](./src/main/java/io/apimatic/core/request/async/AsyncExecutor.java) | Executor service for asynchronous HTTP endpoint call | | [`OptionalNullable`](./src/main/java/io/apimatic/core/types/OptionalNullable.java) | Class to encapsulate fields which are Optional as well as Nullable | @@ -56,12 +57,12 @@ Core lib's Maven group ID is `io.apimatic`, and its artifact ID is `core`. | [`CoreApiException`](./src/main/java/io/apimatic/core/types/CoreApiException.java) | This is the base class for all exceptions that represent an error response from the server | | [`MultipartFileWrapper`](./src/main/java/io/apimatic/core/types/http/request/MultipartFileWrapper.java) | To wrap file and headers to be sent as part of a multipart request | | [`MultipartWrapper`](./src/main/java/io/apimatic/core/types/http/request/MultipartWrapper.java) | To wrap byteArray and headers to be sent as part of a multipart request | -| [`PaginatedData`](./src/main/java/io/apimatic/core/types/pagination/PaginatedData.java) | To provide pagination functionality for both synchronous and asynchronous pagination types | -| [`PageWrapper`](./src/main/java/io/apimatic/core/types/pagination/PageWrapper.java) | To wrap a single page along with its items and meta-data in the paginated data | -| [`CursorPagination`](./src/main/java/io/apimatic/core/types/pagination/CursorPagination.java) | Provides cursor based pagination strategy | -| [`LinkPagination`](./src/main/java/io/apimatic/core/types/pagination/LinkPagination.java) | Provides link based pagination strategy | -| [`OffsetPagination`](./src/main/java/io/apimatic/core/types/pagination/OffsetPagination.java) | Provides offset based pagination strategy | -| [`PagePagination`](./src/main/java/io/apimatic/core/types/pagination/PagePagination.java) | Provides page based pagination strategy | +| [`PaginatedData`](./src/main/java/io/apimatic/core/types/pagination/PaginatedData.java) | To provide pagination functionality for both synchronous and asynchronous pagination types | +| [`PageWrapper`](./src/main/java/io/apimatic/core/types/pagination/PageWrapper.java) | To wrap a single page along with its items and meta-data in the paginated data | +| [`CursorPagination`](./src/main/java/io/apimatic/core/types/pagination/CursorPagination.java) | Provides cursor based pagination strategy | +| [`LinkPagination`](./src/main/java/io/apimatic/core/types/pagination/LinkPagination.java) | Provides link based pagination strategy | +| [`OffsetPagination`](./src/main/java/io/apimatic/core/types/pagination/OffsetPagination.java) | Provides offset based pagination strategy | +| [`PagePagination`](./src/main/java/io/apimatic/core/types/pagination/PagePagination.java) | Provides page based pagination strategy | | [`CoreHelper`](./src/main/java/io/apimatic/core/utilities/CoreHelper.java) | This is a Helper class with commonly used utilities for the SDK | | [`DateHelper`](./src/main/java/io/apimatic/core/utilities/DateHelper.java) | This is a utility class for LocalDate operations | | [`LocalDateTimeHelper`](./src/main/java/io/apimatic/core/utilities/LocalDateTimeHelper.java) | This is a utility class for LocalDateTime operations | @@ -72,7 +73,7 @@ Core lib's Maven group ID is `io.apimatic`, and its artifact ID is `core`. | [`CoreJsonObject`](./src/main/java/io/apimatic/core/utilities/CoreJsonObject.java) | Wrapper class for JSON object | | [`CoreJsonValue`](./src/main/java/io/apimatic/core/utilities/CoreJsonValue.java) | Wrapper class for JSON value | | [`TestHelper`](./src/main/java/io/apimatic/core/utilities/TestHelper.java) | Contains utility methods for comparing objects, arrays and files | -| [`AdditionalProperties`](./src/main/java/io/apimatic/core/types/AdditionalProperties.java) | A generic class for managing additional properties in a model. | +| [`AdditionalProperties`](./src/main/java/io/apimatic/core/types/AdditionalProperties.java) | A generic class for managing additional properties in a model. | | [`ConversionHelper`](./src/main/java/io/apimatic/core/utilities/ConversionHelper.java) | A Helper class for the coversion of type (provided as function) for all structures (array, map, array of map, n-dimensional arrays etc) supported in the SDK. | ## Interfaces diff --git a/src/main/java/io/apimatic/core/configurations/http/client/CoreHttpClientConfiguration.java b/src/main/java/io/apimatic/core/configurations/http/client/CoreHttpClientConfiguration.java index 02f022dd..7577c041 100644 --- a/src/main/java/io/apimatic/core/configurations/http/client/CoreHttpClientConfiguration.java +++ b/src/main/java/io/apimatic/core/configurations/http/client/CoreHttpClientConfiguration.java @@ -1,5 +1,6 @@ package io.apimatic.core.configurations.http.client; +import io.apimatic.coreinterfaces.http.proxy.ProxyConfiguration; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -122,6 +123,12 @@ public final class CoreHttpClientConfiguration implements ClientConfiguration { */ private final boolean skipSslCertVerification; + /** + * The proxy configuration used to route network requests through a proxy server. + * Contains details such as address, port, and optional authentication credentials. + */ + private final ProxyConfiguration proxyConfiguration; + /** * @param timeout * @param numberOfRetries @@ -134,13 +141,15 @@ public final class CoreHttpClientConfiguration implements ClientConfiguration { * @param shouldRetryOnTimeout * @param httpClientInstance * @param overrideHttpClientConfigurations + * @param proxyConfiguration */ private CoreHttpClientConfiguration(final long timeout, final int numberOfRetries, final int backOffFactor, final long retryInterval, final boolean skipSslCertVerification, final Set httpStatusCodesToRetry, final Set httpMethodsToRetry, final long maximumRetryWaitTime, final boolean shouldRetryOnTimeout, final okhttp3.OkHttpClient httpClientInstance, - final boolean overrideHttpClientConfigurations) { + final boolean overrideHttpClientConfigurations, + final ProxyConfiguration proxyConfiguration) { this.timeout = timeout; this.numberOfRetries = numberOfRetries; this.backOffFactor = backOffFactor; @@ -152,6 +161,7 @@ private CoreHttpClientConfiguration(final long timeout, final int numberOfRetrie this.httpClientInstance = httpClientInstance; this.overrideHttpClientConfigurations = overrideHttpClientConfigurations; this.skipSslCertVerification = skipSslCertVerification; + this.proxyConfiguration = proxyConfiguration; } /** @@ -243,6 +253,15 @@ public boolean skipSslCertVerification() { return skipSslCertVerification; } + /** + * Returns the proxy configuration used to route requests through a proxy server. + * This includes the proxy address, port, and any authentication credentials. + * @return the {@link ProxyConfiguration} + */ + public ProxyConfiguration getProxyConfiguration() { + return proxyConfiguration; + } + /** * Converts this HttpClientConfiguration into string format. * @return String representation of this class. @@ -255,7 +274,8 @@ public String toString() { + ", httpMethodsToRetry=" + httpMethodsToRetry + ", maximumRetryWaitTime=" + maximumRetryWaitTime + ", shouldRetryOnTimeout=" + shouldRetryOnTimeout + ", httpClientInstance=" + httpClientInstance - + ", overrideHttpClientConfigurations=" + overrideHttpClientConfigurations + "]"; + + ", overrideHttpClientConfigurations=" + overrideHttpClientConfigurations + + ", proxyConfiguration=" + proxyConfiguration + "]"; } /** @@ -269,7 +289,8 @@ public Builder newBuilder() { .httpStatusCodesToRetry(httpStatusCodesToRetry) .httpMethodsToRetry(httpMethodsToRetry).maximumRetryWaitTime(maximumRetryWaitTime) .shouldRetryOnTimeout(shouldRetryOnTimeout) - .httpClientInstance(httpClientInstance, overrideHttpClientConfigurations); + .httpClientInstance(httpClientInstance, overrideHttpClientConfigurations) + .proxyConfiguration(proxyConfiguration); } /** @@ -322,6 +343,11 @@ public static class Builder { * Skip Ssl certification. */ private boolean skipSslCertVerification; + /** + * The proxy configuration used to route network requests through a proxy server. + * Contains details such as address, port, and optional authentication credentials. + */ + private ProxyConfiguration proxyConfiguration; /** * Default Constructor to initiate builder with default properties. @@ -463,6 +489,17 @@ public Builder skipSslCertVerification(boolean skipSslCertVerification) { return this; } + /** + * Sets the proxy configuration to be used for routing requests through a proxy server. + * + * @param proxyConfiguration the {@link ProxyConfiguration} instance to use + * @return the builder instance + */ + public Builder proxyConfiguration(ProxyConfiguration proxyConfiguration) { + this.proxyConfiguration = proxyConfiguration; + return this; + } + /** * Builds a new HttpClientConfiguration object using the set fields. * @return {@link CoreHttpClientConfiguration}. @@ -471,7 +508,7 @@ public CoreHttpClientConfiguration build() { return new CoreHttpClientConfiguration(timeout, numberOfRetries, backOffFactor, retryInterval, skipSslCertVerification, httpStatusCodesToRetry, httpMethodsToRetry, maximumRetryWaitTime, shouldRetryOnTimeout, - httpClientInstance, overrideHttpClientConfigurations); + httpClientInstance, overrideHttpClientConfigurations, proxyConfiguration); } } } diff --git a/src/main/java/io/apimatic/core/configurations/http/client/CoreProxyConfiguration.java b/src/main/java/io/apimatic/core/configurations/http/client/CoreProxyConfiguration.java new file mode 100644 index 00000000..e1c719d9 --- /dev/null +++ b/src/main/java/io/apimatic/core/configurations/http/client/CoreProxyConfiguration.java @@ -0,0 +1,141 @@ +package io.apimatic.core.configurations.http.client; + +import io.apimatic.coreinterfaces.http.proxy.ProxyConfiguration; + +/** + * Represents a proxy configuration with address, port, and optional authentication credentials. + * This class is an implementation of the {@link ProxyConfiguration} interface. + */ +public final class CoreProxyConfiguration implements ProxyConfiguration { + + /** + * The proxy server address (e.g., IP or domain name). + */ + private final String address; + + /** + * The port on which the proxy server is listening. + */ + private final int port; + + /** + * The username for proxy authentication, if required. + */ + private final String username; + + /** + * The password for proxy authentication, if required. + */ + private final String password; + + /** + * Creates a new instance of {@code CoreProxyConfiguration} with the specified address, + * port, and optional authentication credentials. + * + * @param address The proxy server address. + * @param port The proxy server port. + * @param username The username for proxy authentication (can be {@code null}). + * @param password The password for proxy authentication (can be {@code null}). + */ + private CoreProxyConfiguration(final String address, final int port, + final String username, final String password) { + this.address = address; + this.port = port; + this.username = username; + this.password = password; + } + + @Override + public String getAddress() { + return address; + } + + @Override + public int getPort() { + return port; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public String getPassword() { + return password; + } + + /** + * Creates a new builder initialized with the current configuration's values. + * @return a new {@link Builder} instance + */ + public Builder newBuilder() { + return new Builder(this.address, this.port) + .username(this.username) + .password(this.password); + } + + /** + * Returns a string representation of this proxy configuration. + * @return string representation of this object + */ + @Override + public String toString() { + return "CoreProxyConfiguration [" + + "address=" + address + + ", port=" + port + + ", username=" + username + + ", password=" + password + + "]"; + } + + /** + * Builder class for constructing {@link CoreProxyConfiguration} instances. + */ + public static class Builder { + + private final String address; + private final int port; + private String username; + private String password; + + /** + * Creates a new {@code Builder} instance with the specified proxy server details. + * + * @param address the hostname or IP address of the proxy server + * @param port the port number of the proxy server + */ + public Builder(final String address, final int port) { + this.address = address; + this.port = port; + } + + /** + * Sets the proxy username for authentication. + * @param username the username to set + * @return the builder instance + */ + public Builder username(String username) { + this.username = username; + return this; + } + + /** + * Sets the proxy password for authentication. + * @param password the password to set + * @return the builder instance + */ + public Builder password(String password) { + this.password = password; + return this; + } + + /** + * Builds a new {@link CoreProxyConfiguration} instance using the set fields. + * @return the built {@link CoreProxyConfiguration} + */ + public CoreProxyConfiguration build() { + return new CoreProxyConfiguration(address, port, username, password); + } + } +}