Skip to content

Conversation

@Itz-Agasta
Copy link

@Itz-Agasta Itz-Agasta commented Oct 9, 2025

Purpose

Fix handling of enum (finite) types in WebSocket resource query parameters. Previously, enum typed query parameters were rejected at runtime and resulted in a 404 handshake failure. This change adds native support (Java) for detecting and converting enum query parameter values so that services can accept and receive enum values from the WebSocket upgrade request.

Fixes: ballerina-platform/ballerina-library#4765

Examples

Before (failed at runtime):

enum wsType {
    ORDER_TYPE,
    CARGO_TYPE
}

service /ws on wsListener {
    resource function get .(string id, wsType 'type) returns websocket:Service {
        if 'type == ORDER_TYPE {
            return new OrderService(id);
        } else {
            return new CargoService(id);
        }
    }
}

Failed Connection: ws://localhost:9090?type=ORDER_TYPE404 Not Found
Error Message: "Invalid query param type 'wsType'"

After (works):

# Same request after fix
HTTP/1.1 101 Switching Protocols 
Connection: upgrade
Upgrade: websocket
# WebSocket connection established successfully

Checklist

  • Linked to an issue
  • Updated the specification
  • Updated the changelog
  • Added tests
  • Checked native-image compatibility

Signed-off-by: Itz-Agasta [email protected]

@Itz-Agasta
Copy link
Author

Itz-Agasta commented Oct 9, 2025

HI @ThisaruGuruge, As mentioned in the issue i updated the QueryParam.java's Type Validation. can y pls review it. Thanks

@Itz-Agasta Itz-Agasta changed the title WebSocket Enum Query Parameter Fix fix(websocket): add support for enum (finite) types in query parameters Oct 9, 2025
@CLAassistant
Copy link

CLAassistant commented Oct 9, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@ThisaruGuruge ThisaruGuruge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add tests for test this functionality.

@Itz-Agasta
Copy link
Author

Hi @ThisaruGuruge, I'm having some issue while trying to test the enum query param test file. The Gradle build is failing with authentication errors for GitHub Maven packages:

Could not resolve io.ballerina:plugin-gradle:2.3.0.
> Could not get resource 'https://maven.pkg.github.com/ballerina-platform/plugin-gradle/io/ballerina/plugin-gradle/2.3.0/plugin-gradle-2.3.0.pom'.
> Username must not be null!

This is preventing me from building the native JARs and running the tests. Ig as a contributor, I don't have access to the necessary tokens or permissions for the Ballerina organization's private packages.

can y tell me how cam i set up their environment for testing? Or run the tests on your end to verify the enum query param functionality works?

@ThisaruGuruge
Copy link
Member

Hi @ThisaruGuruge, I'm having some issue while trying to test the enum query param test file. The Gradle build is failing with authentication errors for GitHub Maven packages:

Could not resolve io.ballerina:plugin-gradle:2.3.0.
> Could not get resource 'https://maven.pkg.github.com/ballerina-platform/plugin-gradle/io/ballerina/plugin-gradle/2.3.0/plugin-gradle-2.3.0.pom'.
> Username must not be null!

This is preventing me from building the native JARs and running the tests. Ig as a contributor, I don't have access to the necessary tokens or permissions for the Ballerina organization's private packages.

can y tell me how cam i set up their environment for testing? Or run the tests on your end to verify the enum query param functionality works?

Hi, I am extremely sorry, the repo is missing this on the README. (Can you please create an issue for this as well?)

The issue you are facing is due to GitHub package resolution. To pull packages from GitHub packages, you need to set up your GitHub username and a Personal Access Token (PAT).

These should be saved as environment variables so that the Gradle script picks them. You should have the following environment variables:

packageUser="<your GitHub username>"
packagePAT="<your GitHub PAT>"

When you are creating the GitHub PAT, make sure to include package (read) permissions in order to build script to pull packages from the GitHub packages.

Thanks.

@Itz-Agasta
Copy link
Author

Itz-Agasta commented Oct 19, 2025

Hi, I am extremely sorry, the repo is missing this on the README. (Can you please create an issue for this as well?)

sure i will.... but where im supposed to rise the issue? i mean this repo has no issue section? so in ballerina lang repo?

so now i added test cases in http_query_param_binding_test.bal you can check it, i believe they are correct but i thought the 404 issue was resolved but im having some issue , classically All enum query parameter tests are failing with conversion errors

Error: {ballerina/lang.value}ConversionError` during test execution
image

idk is this has some issue?

Should enums be handled differently from other union/finite types? Are there any specific enum conversion utilities in Ballerina runtime that should be used instead? I'm relatively new to Ballerina's type system and WebSocket internals, so I might be missing some context. any leads will be great. Thanks

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed to connect to a websocket connection which accept a parameter with an Enum type

3 participants