diff --git a/ballerina-tests/http-service-tests/Ballerina.toml b/ballerina-tests/http-service-tests/Ballerina.toml index 8e0c6e7c56..b97b4e9ea2 100644 --- a/ballerina-tests/http-service-tests/Ballerina.toml +++ b/ballerina-tests/http-service-tests/Ballerina.toml @@ -15,3 +15,4 @@ graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" path = "../../test-utils/build/libs/http-test-utils-2.10.3.jar" + diff --git a/changelog.md b/changelog.md index 724a1d1a3f..c30823b203 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,11 @@ This file contains all the notable changes done to the Ballerina HTTP package th The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Changed +- [Make some of the Java classes proper utility classes](https://github.com/ballerina-platform/ballerina-standard-library/issues/4923) + ## [2.10.3] - 2023-10-13 ### Fixed diff --git a/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/http/compiler/CompilerPluginTestConstants.java b/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/http/compiler/CompilerPluginTestConstants.java index 65aac2f2ab..6eb81f72d8 100644 --- a/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/http/compiler/CompilerPluginTestConstants.java +++ b/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/http/compiler/CompilerPluginTestConstants.java @@ -21,7 +21,9 @@ /** * Constants related to compiler plugin tests. */ -public class CompilerPluginTestConstants { +public final class CompilerPluginTestConstants { + private CompilerPluginTestConstants() {} + public static final String HTTP_101 = "HTTP_101"; public static final String HTTP_102 = "HTTP_102"; public static final String HTTP_103 = "HTTP_103"; diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/Constants.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/Constants.java index e9a982e2bb..17f43a34ee 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/Constants.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/Constants.java @@ -21,7 +21,9 @@ /** * Constants related to compiler plugin implementation. */ -public class Constants { +public final class Constants { + private Constants() {} + public static final String BALLERINA = "ballerina"; public static final String HTTP = "http"; public static final String SERVICE_KEYWORD = "service"; diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpCompilerPluginUtil.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpCompilerPluginUtil.java index 21b014b2ab..bb8d59bafa 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpCompilerPluginUtil.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpCompilerPluginUtil.java @@ -93,7 +93,9 @@ /** * Utility class providing http compiler plugin utility methods. */ -public class HttpCompilerPluginUtil { +public final class HttpCompilerPluginUtil { + + private HttpCompilerPluginUtil() {} public static void updateDiagnostic(SyntaxNodeAnalysisContext ctx, Location location, HttpDiagnosticCodes httpDiagnosticCodes) { diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpInterceptorResourceValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpInterceptorResourceValidator.java index baa7db7db0..7c54ae8bc2 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpInterceptorResourceValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpInterceptorResourceValidator.java @@ -35,7 +35,9 @@ /** * Validates a ballerina http interceptor resource. */ -public class HttpInterceptorResourceValidator { +public final class HttpInterceptorResourceValidator { + private HttpInterceptorResourceValidator() {} + public static void validateResource(SyntaxNodeAnalysisContext ctx, FunctionDefinitionNode member, String type, Map typeSymbols) { checkResourceAnnotation(ctx, member); diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpResourceValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpResourceValidator.java index a0b2feb6ee..8250cfc39e 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpResourceValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpResourceValidator.java @@ -128,7 +128,9 @@ /** * Validates a ballerina http resource. */ -public class HttpResourceValidator { +public final class HttpResourceValidator { + + private HttpResourceValidator() {} static void validateResource(SyntaxNodeAnalysisContext ctx, FunctionDefinitionNode member, LinksMetaData linksMetaData, Map typeSymbols) { diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/codeaction/Constants.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/codeaction/Constants.java index dbd9333b3e..d1cd8715bf 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/codeaction/Constants.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/codeaction/Constants.java @@ -21,7 +21,9 @@ /** * Constants related to compiler plugin code-action implementation. */ -public class Constants { +public final class Constants { + private Constants () {} + public static final String NODE_LOCATION_KEY = "node.location"; public static final String IS_ERROR_INTERCEPTOR_TYPE = "node.errorInterceptor"; diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/completion/Constants.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/completion/Constants.java index 4f3263c0a5..eb30ec55fe 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/completion/Constants.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/completion/Constants.java @@ -23,7 +23,9 @@ /** * Constants related to compiler plugin completion implementation. */ -public class Constants { +public final class Constants { + private Constants() {} + public static final String GET = "get"; public static final String POST = "post"; diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/HttpConstants.java b/native/src/main/java/io/ballerina/stdlib/http/api/HttpConstants.java index 88928a6a88..dc5f4fc2f6 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/HttpConstants.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/HttpConstants.java @@ -30,7 +30,7 @@ * * @since 0.8.0 */ -public class HttpConstants { +public final class HttpConstants { public static final String HTTPS_ENDPOINT_STARTED = "[ballerina/http] started HTTPS/WSS listener "; public static final String HTTP_ENDPOINT_STARTED = "[ballerina/http] started HTTP/WS listener "; diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/logging/util/LogLevelMapper.java b/native/src/main/java/io/ballerina/stdlib/http/api/logging/util/LogLevelMapper.java index abac2eb0cc..f05c0fe578 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/logging/util/LogLevelMapper.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/logging/util/LogLevelMapper.java @@ -25,7 +25,9 @@ * * @since 0.89 */ -public class LogLevelMapper { +public final class LogLevelMapper { + + private LogLevelMapper() {} public static String getBallerinaLogLevel(Level level) { switch (level.getName()) { diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternRequestContext.java b/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternRequestContext.java index cb87e87cc3..a59d559fb4 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternRequestContext.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternRequestContext.java @@ -33,7 +33,9 @@ /** * Utilities related to HTTP request context. */ -public class ExternRequestContext { +public final class ExternRequestContext { + + private ExternRequestContext() {} public static Object getWithType(BObject requestCtx, BString key, BTypedesc targetType) { BMap members = requestCtx.getMapValue(HttpConstants.REQUEST_CTX_MEMBERS); diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternUtils.java b/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternUtils.java index f6f5b96394..ccf6873f56 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternUtils.java @@ -23,7 +23,9 @@ /** * Contains external utility functions. */ -public class ExternUtils { +public final class ExternUtils { + + private ExternUtils() {} /** * Provides the relevant reason phrase for a given status code. diff --git a/native/src/main/java/io/ballerina/stdlib/http/transport/contractimpl/common/states/Http2StateUtil.java b/native/src/main/java/io/ballerina/stdlib/http/transport/contractimpl/common/states/Http2StateUtil.java index 9dd7225e15..55b52c9822 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/transport/contractimpl/common/states/Http2StateUtil.java +++ b/native/src/main/java/io/ballerina/stdlib/http/transport/contractimpl/common/states/Http2StateUtil.java @@ -85,7 +85,9 @@ * * @since 6.0.241 */ -public class Http2StateUtil { +public final class Http2StateUtil { + + private Http2StateUtil() {} private static final Logger LOG = LoggerFactory.getLogger(Http2StateUtil.class); diff --git a/native/src/main/java/io/ballerina/stdlib/http/uri/DispatcherUtil.java b/native/src/main/java/io/ballerina/stdlib/http/uri/DispatcherUtil.java index f72809f3f0..f0e710ad9c 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/uri/DispatcherUtil.java +++ b/native/src/main/java/io/ballerina/stdlib/http/uri/DispatcherUtil.java @@ -33,7 +33,9 @@ /** * Utilities related to dispatcher processing. */ -public class DispatcherUtil { +public final class DispatcherUtil { + + private DispatcherUtil() {} private static String[] allMethods = new String[]{HttpConstants.HTTP_METHOD_GET, HttpConstants.HTTP_METHOD_HEAD , HttpConstants.HTTP_METHOD_POST, HttpConstants.HTTP_METHOD_DELETE, HttpConstants.HTTP_METHOD_PATCH diff --git a/native/src/test/java/io/ballerina/stdlib/http/api/TestUtils.java b/native/src/test/java/io/ballerina/stdlib/http/api/TestUtils.java index fba5ffd650..c96790fcea 100644 --- a/native/src/test/java/io/ballerina/stdlib/http/api/TestUtils.java +++ b/native/src/test/java/io/ballerina/stdlib/http/api/TestUtils.java @@ -35,7 +35,9 @@ /** * A test utils for http unit test classes. */ -public class TestUtils { +public final class TestUtils { + + private TestUtils() {} public static final int SOCKET_SERVER_PORT = 8001; diff --git a/native/src/test/java/io/ballerina/stdlib/http/transport/http2/expect100continue/Continue100Util.java b/native/src/test/java/io/ballerina/stdlib/http/transport/http2/expect100continue/Continue100Util.java index 910c11d25e..0577d6e0c6 100644 --- a/native/src/test/java/io/ballerina/stdlib/http/transport/http2/expect100continue/Continue100Util.java +++ b/native/src/test/java/io/ballerina/stdlib/http/transport/http2/expect100continue/Continue100Util.java @@ -24,7 +24,9 @@ import static io.ballerina.stdlib.http.transport.contract.Constants.HTTP_2_0; -class Continue100Util { +public final class Continue100Util { + private Continue100Util() {} + static ListenerConfiguration getListenerConfigs() { ListenerConfiguration listenerConfiguration = new ListenerConfiguration(); listenerConfiguration.setPort(TestUtil.SERVER_CONNECTOR_PORT); diff --git a/native/src/test/java/io/ballerina/stdlib/http/transport/proxyserver/ProxyServerUtil.java b/native/src/test/java/io/ballerina/stdlib/http/transport/proxyserver/ProxyServerUtil.java index fd0e897ef9..e94f62f807 100644 --- a/native/src/test/java/io/ballerina/stdlib/http/transport/proxyserver/ProxyServerUtil.java +++ b/native/src/test/java/io/ballerina/stdlib/http/transport/proxyserver/ProxyServerUtil.java @@ -53,7 +53,9 @@ /** * A util class to use in both http and https proxy scenarios. */ -public class ProxyServerUtil { +public final class ProxyServerUtil { + private ProxyServerUtil() {} + private static HttpClientConnector httpClientConnector; private static ServerConnector serverConnector; private static HttpWsConnectorFactory httpWsConnectorFactory; diff --git a/native/src/test/java/io/ballerina/stdlib/http/transport/util/Http2Util.java b/native/src/test/java/io/ballerina/stdlib/http/transport/util/Http2Util.java index 66742df288..6175283354 100644 --- a/native/src/test/java/io/ballerina/stdlib/http/transport/util/Http2Util.java +++ b/native/src/test/java/io/ballerina/stdlib/http/transport/util/Http2Util.java @@ -48,7 +48,9 @@ * * @since 6.0.273 */ -public class Http2Util { +public final class Http2Util { + + private Http2Util() {} public static final String HTTP2_RESPONSE_PAYLOAD = "Final Response"; diff --git a/native/src/test/java/io/ballerina/stdlib/http/transport/util/TestUtil.java b/native/src/test/java/io/ballerina/stdlib/http/transport/util/TestUtil.java index 1c872d76df..66f2f8057e 100644 --- a/native/src/test/java/io/ballerina/stdlib/http/transport/util/TestUtil.java +++ b/native/src/test/java/io/ballerina/stdlib/http/transport/util/TestUtil.java @@ -69,7 +69,9 @@ /** * A util class to be used for tests. */ -public class TestUtil { +public final class TestUtil { + + private TestUtil() {} private static final Logger LOG = LoggerFactory.getLogger(TestUtil.class); diff --git a/native/src/test/java/io/ballerina/stdlib/http/transport/util/client/http2/MessageGenerator.java b/native/src/test/java/io/ballerina/stdlib/http/transport/util/client/http2/MessageGenerator.java index 953608402e..0886b55844 100644 --- a/native/src/test/java/io/ballerina/stdlib/http/transport/util/client/http2/MessageGenerator.java +++ b/native/src/test/java/io/ballerina/stdlib/http/transport/util/client/http2/MessageGenerator.java @@ -46,7 +46,9 @@ /** * A utility class which generates HTTP/2.0 requests. */ -public class MessageGenerator { +public final class MessageGenerator { + private MessageGenerator() {} + public static HttpCarbonMessage generateRequest(HttpMethod httpMethod, String payload) { HttpCarbonMessage httpCarbonMessage = new HttpCarbonRequest(new DefaultHttpRequest( new HttpVersion(Constants.DEFAULT_VERSION_HTTP_1_1, true), httpMethod, diff --git a/native/src/test/java/io/ballerina/stdlib/http/transport/util/client/websocket/WebSocketTestConstants.java b/native/src/test/java/io/ballerina/stdlib/http/transport/util/client/websocket/WebSocketTestConstants.java index 8e192a2ace..c744751767 100644 --- a/native/src/test/java/io/ballerina/stdlib/http/transport/util/client/websocket/WebSocketTestConstants.java +++ b/native/src/test/java/io/ballerina/stdlib/http/transport/util/client/websocket/WebSocketTestConstants.java @@ -22,7 +22,9 @@ /** * WebSocket constants for testing purposes. */ -public class WebSocketTestConstants { +public final class WebSocketTestConstants { + private WebSocketTestConstants() {} + public static final String PAYLOAD_NEW_CLIENT_CONNECTED = "NEW_CLIENT_CONNECTED"; public static final String PAYLOAD_CLIENT_LEFT = "CLIENT_LEFT"; } diff --git a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/Assert.java b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/Assert.java index aad6997297..c4b8573cff 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/Assert.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/Assert.java @@ -21,7 +21,9 @@ /** * Contains assert functions used by mime test cases. */ -public class Assert { +public final class Assert { + + private Assert() {} public static void assertEquals(Object actual, Object expected) { if (!areEqual(actual, expected)) { diff --git a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/ExternPipeliningTestUtil.java b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/ExternPipeliningTestUtil.java index bb5139f76f..6913c9ca54 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/ExternPipeliningTestUtil.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/ExternPipeliningTestUtil.java @@ -40,7 +40,9 @@ * * @since 0.982.0 */ -public class ExternPipeliningTestUtil { +public final class ExternPipeliningTestUtil { + + private ExternPipeliningTestUtil() {} private static final Logger log = LoggerFactory.getLogger(ExternPipeliningTestUtil.class); diff --git a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/ExternRetryMultipartTestutil.java b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/ExternRetryMultipartTestutil.java index e7f782b7b1..fc2efba04a 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/ExternRetryMultipartTestutil.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/ExternRetryMultipartTestutil.java @@ -33,7 +33,9 @@ /** * Contains utility functions used for the retry test. */ -public class ExternRetryMultipartTestutil { +public final class ExternRetryMultipartTestutil { + + private ExternRetryMultipartTestutil() {} private static final Logger log = LoggerFactory.getLogger(ExternRetryMultipartTestutil.class); private static final String RETRY_HEADER = "x-retry"; diff --git a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/TestConstant.java b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/TestConstant.java index c1e8dc4ae6..4b6a3fd9eb 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/TestConstant.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/TestConstant.java @@ -22,7 +22,9 @@ /** * Constants used in test cases. */ -public class TestConstant { +public final class TestConstant { + private TestConstant() {} + public static final String CONTENT_TYPE_JSON = "application/json"; public static final String CONTENT_TYPE_XML = "application/xml"; public static final String CONTENT_TYPE_TEXT_PLAIN = "text/plain"; diff --git a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/Utils.java b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/Utils.java index ba227d220f..89528384dd 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/Utils.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/Utils.java @@ -36,7 +36,9 @@ /** * A utility class for keep payloads. */ -public class Utils { +public final class Utils { + + private Utils() {} public static String getEntityBodyFrom(FullHttpResponse httpResponse) { ByteBuffer content = httpResponse.content().nioBuffer(); diff --git a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/client/HttpUrlClient.java b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/client/HttpUrlClient.java index 0e01284dcd..0c21f6e35e 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/client/HttpUrlClient.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/http/testutils/client/HttpUrlClient.java @@ -43,7 +43,9 @@ /** * A simple URL connection HTTP client to be used in test cases. */ -public class HttpUrlClient { +public final class HttpUrlClient { + + private HttpUrlClient() {} private static final Logger log = LoggerFactory.getLogger(HttpUrlClient.class); private static final int DEFAULT_READ_TIMEOUT = 30000;