neo4j / neo4j-browser

Neo4j Browser is the general purpose user interface for working with Neo4j. Query, visualize, administrate and monitor the database.
https://neo4j.com
GNU General Public License v3.0
677 stars 346 forks source link

"not a WebSocket handshake request: missing upgrade" On Mac #994

Open ArmenLevoni opened 4 years ago

ArmenLevoni commented 4 years ago

Description

I am trying to run a java embedded instance of neo4j. The actual code is:

public class GraphDatabaseApi {

private static final Logger logger = LoggerFactory.getLogger(GraphDatabaseApi.class);

private static GraphDatabaseApi singleton;
private GraphDatabaseService graphDb;

public static void main(String[] args) {
    Path f = Paths.get("./path1");
    Path g = Paths.get("./path2");
    GraphDatabaseApi.create(f,g).waitAndShutdown();
}

public GraphDatabaseApi(Path graphDbPath, Path graphConfPath) {

    //http://neo4j-contrib.github.io/neo4j-jdbc/
    logger.info("Opening graphdb in: "+graphDbPath);

    Config config = Config.builder()
            .withServerDefaults()
            .build();
    BoltConnector bolt = config.boltConnectors().get(0);
    graphDb = new GraphDatabaseFactory()
            .newEmbeddedDatabaseBuilder( graphDbPath.toFile() )
            .setConfig( bolt.type, "BOLT" )
            .setConfig( bolt.enabled, "true" )
            .setConfig( bolt.listen_address, "localhost:7687" )
            .newGraphDatabase();

    Runtime.getRuntime().addShutdownHook( new Thread()
    {
        @Override
        public void run()
        {
            waitAndShutdown();
        }
    } );
}

public void shutdown() {
    if (graphDb != null && graphDb.isAvailable(1)) {
        graphDb.shutdown();
        graphDb = null;
    }
    logger.info("graphDb is shutdown");
}

public void waitAndShutdown() {
    if (graphDb != null && graphDb.isAvailable(1)) {
        System.out.println("Press Enter key to shutdown neo4j...");
        try
        {
            System.in.read();
        }
        catch(Exception e)
        {}
        graphDb.shutdown();
        logger.info("graphDb is shutdown");
    }
}

public GraphDatabaseService get() {return graphDb;}

public static GraphDatabaseApi create(Path graphDbPath, Path graphConfPath) {
    if (singleton == null) singleton = new GraphDatabaseApi(graphDbPath, graphConfPath);
    return singleton;
}

public static GraphDatabaseApi create(Path graphDbPath) {
    if (singleton == null) singleton = new GraphDatabaseApi(graphDbPath, null);
    return singleton;
}

public static GraphDatabaseService db() {
    if (singleton == null) throw new NotInitialisedException();
    return singleton.get();
}

public static class NotInitialisedException extends RuntimeException {}

}

It runs without any problem, the log is: INFO: Opening graphdb in: ./path1 Press Enter key to shutdown neo4j...

However, when I am trying to get access to the server, I am getting the following message in the browser (tired Chrome, Firefox, Safari): "not a WebSocket handshake request: missing upgrade"

The Environment

software name version
OS MacOS Mojave
Web browser Chrome, Firefox, Safari
neo4j-3.5.12

Can you please suggest what is wrong?

tyey commented 3 years ago

I have the same issue with neo4j-4.1.1

rbramley commented 3 years ago

This message (as per #1247) is seen when you connect a web browser to the Bolt connector, instead of the HTTP connector on port 7474 for the Neo4j Browser.

If you have this problem, try port 7474 first. If it's not enabled, see https://neo4j.com/docs/operations-manual/current/configuration/connectors/

For the issue detailed above, withServerDefaults should enable HTTP, HTTPS and Bolt connectors.