Skip to content

This example(Events.java) cannot be run! #283

Open

Description

@ZYunf

I have a Exception:

javax.websocket.DeploymentException: The HTTP response from the server [404] did not permit the HTTP upgrade to WebSocket

It comes from WebSocketEventStream,I don't know how to solve this problem,I hope to get your advice!Thank you in advance!
@dmacvicar

Activity

  1. renner commented on Apr 23, 2020

    @renner
    Member

    Hey @ZYunf, thanks for reaching out! I just tried to run the Events.java example and in fact it is working here as expected. You need both salt-master and salt-api services to be running with a proper configuration, and then you would change Events.java to match that configuration. For instance if your master configuration has:

    rest_cherrypy:
      port: 9080
      host: 0.0.0.0
      ...
    
    external_auth:
      auto:
        admin:
          - .*
    

    Your java code should look like this (please replace hostname with yours):

    private static final String SALT_API_URL = "http://hostname:9080";
    private static final String USER = "admin";
    private static final String PASSWORD = "";
    

    And one more important hint: the ws4py websocket library for Python needs to be installed on the machine where salt-api is running. In openSUSE distributions you can install it to your system via zypper in python3-ws4py, but other distributions should have that package as well under a similar name or you can get it from PyPi (pip install ws4py).

    I hope that might help you, otherwise feel free to provide some more details about your setup, for example the configuration you are using for running the API.

  2. ZYunf commented on Apr 24, 2020

    @ZYunf
    Author

    @renner Thank you for your prompt reply! I've already installed ws4py,and then I have restarted salt-master and salt-minion.But it seems that ws4py is not working.I run the other modules in Java that work very well.I have got the token.But running Events.java, the following error occurred:

    Token: a7ea83b912b273fdcbbd3ae0ce37d3523f03c217
    Exception: javax.websocket.DeploymentException: Handshake error.
    

    ws4py and cherrypy has been installed like this:

    image-20200424100822718

    The following is my configuration file in /etc/salt/master.d/
    filename:api.config

    rest_cherrypy:
      port: 8000
      host: 0.0.0.0
      disable_ssl: True
      debug: True
      ssl_crt: /etc/pki/tls/certs/localhost.crt
      ssl_key: /etc/pki/tls/certs/localhost.key
    

    Filename:auth.config

    external_auth:
      pam:
        saltapi:
          - .*
          - '@wheel'
          - '@runner'
          - '@jobs'
    

    Description of my operating environment
    My salt-master is in docker and code runs on the host machine.The port(8000) of the salt-api has been mapped to the host port(8088).so my code like this:

        private static final String SALT_API_URL = "http://localhost:8088";
        private static final String USER = "saltapi";
        private static final String PASSWORD = "saltapi";
    

    I'm not sure if websocket can't be connected due to port problems,or because ws4py doesn't work.Up to now, the error(Handshake error) has not been resolved.I'm looking forward to your help!Thanks!

  3. reopened this on Apr 24, 2020
  4. NemanyaM commented on Mar 29, 2021

    @NemanyaM

    @ZYunf If you make ws4py set up correctly, and try to obtain AuthModule.PAM when obtaining a login token, shouldn't give you a Handshake error.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions