Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ZYunf opened this issue Apr 23, 2020 · 3 comments
Open

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

ZYunf opened this issue Apr 23, 2020 · 3 comments

Comments

@ZYunf
Copy link

ZYunf commented Apr 23, 2020

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

@renner
Copy link
Member

renner commented Apr 23, 2020

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.

@ZYunf
Copy link
Author

ZYunf commented Apr 24, 2020

@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!

@ZYunf ZYunf closed this as completed Apr 24, 2020
@ZYunf ZYunf reopened this Apr 24, 2020
@NemanyaM
Copy link

NemanyaM commented Mar 29, 2021

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants