ninjaframework / ninja

Ninja is a full stack web framework for Java. Rock solid, fast and super productive.
http://www.ninjaframework.org
Apache License 2.0
1.91k stars 518 forks source link

Websockets are not initialised error #743

Open SebastianFilip101 opened 2 years ago

SebastianFilip101 commented 2 years ago

I am trying to create a WebSocket endpoint with Ninja and by following the documentation provided here I keep getting the same error. I followed the entire documentation step by step. This is the error:

[INFO] GCLOUD: java.lang.IllegalStateException: WebSockets are not enabled. Unable to configure route /api/websocketExample. Using implementation ninja.websockets.DefaultWebSockets

Because of this error the Routes are not initialised either. Any Ideas?

thibaultmeyer commented 2 years ago

Hello,

you are using the default implementation which is disabled by default. You have to create your own implementation.

https://github.com/ninjaframework/ninja/blob/develop/ninja-core/src/main/java/ninja/websockets/DefaultWebSockets.java

public class DefaultWebSockets implements WebSockets {

    @Override
    public boolean isEnabled() {
        return false;
    }

    @Override
    public void compileRoute(Route route) {
        throw new IllegalStateException("WebSockets are not enabled." + 
            " Unable to add websocket route to " + route.getUri() + "." + 
            " Are you running in a websocket-enabled HTTP server?");
    }
}
SebastianFilip101 commented 2 years ago

Is there a practical example of how a custom implementation should look like? Or how websockets are enabled?

jjlauer commented 2 years ago

It feels like you aren't using a websocket enabled web container to run it in, thus Ninja is falling back to the default implementation, which basically warns you that you aren't running a websocket enabled container.

You can solve this with either adding the dependencies to your project, or using a different container to run it in. Without knowing much about your project, what you're running it in, etc., I can't help much more than that. If you wanna share those details, we can probably point you in a better direction.

On Thu, Feb 24, 2022, 10:32 AM SebastianFilip101 @.***> wrote:

Is there a practical example of how a custom implementation should look like? Or how websockets are enabled?

— Reply to this email directly, view it on GitHub https://github.com/ninjaframework/ninja/issues/743#issuecomment-1049979593, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEPAAUWPDBKIDLIZEEZS7LU4ZFRJANCNFSM5PHHFQSA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>