0

I'm trying to create a websocket in java that listens to a local application on the endpoint f.ex. "wss://localhost.localapp.com:8080/".

The application do send through that websocket information about what is happening.

When I run the web-application and it tries to connect to the secure websocket it throws this error:

XNIO000100: 'https' URL scheme chosen but no SSL provider given

Here is my code for connecting to the client endpoint:

@ClientEndpoint
public class ClientEndpoint {

    private Logger logger = Logger.getLogger(getClass().getName());

    public ClientEndpoint() {
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        try {
            container.connectToServer(this, new URI("wss://localhost.localapp.com:8080/"));
        } catch (DeploymentException | URISyntaxException | InterruptedException | IOException e) {
            System.out.println("Connection error occured!: " + e);
        }
    }

    @OnOpen
    public void onOpen(Session session) {
        this.logger.info("New websocket session opened: " + session.getId());
    }

    @OnClose
    public void onClose(Session session) {
        this.logger.info("Websoket session closed: " + session.getId());
    }

    @OnMessage
    public void onMessage(Session session, String message) throws IOException, EncodeException {
        this.logger.info("Message recieved: " + message);
    }

    @OnError
    public void error(Session session, Throwable t) {
        t.printStackTrace();
    }
}

So the errors happends on this code line:

container.connectToServer(this, new URI("wss://localhost.localapp.com:8080/"));

And the stack trace output this:

ERROR localhost jboss7.1 [RunnerReadFacade] Application was stopped due to exception. Transaction is rollbacked.: java.lang.IllegalArgumentException: XNIO000100: 'https' URL scheme chosen but no SSL provider given
    at org.xnio.http.HttpUpgrade$HttpUpgradeState.doUpgrade(HttpUpgrade.java:253)
    at org.xnio.http.HttpUpgrade$HttpUpgradeState.access$100(HttpUpgrade.java:165)
    at org.xnio.http.HttpUpgrade.performUpgrade(HttpUpgrade.java:129)
    at io.undertow.websockets.client.WebSocketClient$ConnectionBuilder.connectImpl(WebSocketClient.java:323)
    at io.undertow.websockets.client.WebSocketClient$ConnectionBuilder.connect(WebSocketClient.java:211)
    at io.undertow.websockets.jsr.ServerWebSocketContainer.connectToServerInternal(ServerWebSocketContainer.java:463)
    at io.undertow.websockets.jsr.ServerWebSocketContainer.connectToServerInternal(ServerWebSocketContainer.java:457)
    at io.undertow.websockets.jsr.ServerWebSocketContainer.connectToServer(ServerWebSocketContainer.java:211)

How should I solve this?

With JavaScript I do not need a SSL provider and can simply create the connection with the websocket just by running:

websocket = new WebSocket("wss://localhost.localapp.com:8080/");

Why does the error only occure to Java?

UPDATE:

This probably cannot be done because the application is on your local computer and the server is not local.

But could this be done if you would use a local server?

OuuGiii
  • 1,053
  • 1
  • 11
  • 31

1 Answers1

0

You can either switch to Programmatic Client Endpoint or define Thread local SSL Context. See details at https://issues.jboss.org/browse/THORN-2131 (wsstest-master.zip includes demo app). 'Implement io.undertow.websockets.jsr.WebsocketClientSslProvider and add a META-INF/services entry' didn't work for me.

Anatoly Shipov
  • 484
  • 3
  • 5