src/main/java/zoot/tube/websocketserver/Server.java
/**
     * Creates a greeting handler.
     *
     * @param server   the server to send the message through.
     * @param greeting the message to send as the greeting.
     * @return the message handler.
     */
Creates a greeting handler.
@param server   the server to send the message through.
@param greeting the message to send as the greeting.
@return the message handler.
Creates a greeting handler . @param server the server to send the message through . @param greeting the message to send as the greeting . @return the message handler .
public static Consumer<String> createDefaultGreeting(Server server, String greeting) {
        return message -> {
            try {
                Gson gson = new GsonBuilder().create();
                ApiRequest request = gson.fromJson(message, ApiRequest.class);
                if (request.getHeader().equals("getGreeting")) {
                    server.sendMessage(String.format("{\"header\":\"greeting\",\"data\":\"%s\"}", greeting));
                }
            } catch (Exception e) {
                System.err.println("Message was not a standard request");
            }
        };
    }
public static Consumer < String > createDefaultGreeting ( Server server , String greeting ) { return message -> { try { Gson gson = new GsonBuilder ( ) . create ( ) ; ApiRequest request = gson . fromJson ( message , ApiRequest . class ) ; if ( request . getHeader ( ) . equals ( "getGreeting" ) ) { server . sendMessage ( String . format ( "{\"header\":\"greeting\",\"data\":\"%s\"}" , greeting ) ) ; } } catch ( Exception e ) { System . err . println ( "Message was not a standard request" ) ; } } ; }
Creates a greeting handler.
Creates a greeting handler .
// Make sure the message is asking for the greeting. // Send back the greeting.