
vertx-stomp-js.stomp_server_handler.js Maven / Gradle / Ivy
/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
/** @module vertx-stomp-js/stomp_server_handler */
var utils = require('vertx-js/util/utils');
var Destination = require('vertx-stomp-js/destination');
var User = require('vertx-auth-common-js/user');
var DestinationFactory = require('vertx-stomp-js/destination_factory');
var Acknowledgement = require('vertx-stomp-js/acknowledgement');
var Vertx = require('vertx-js/vertx');
var ServerFrame = require('vertx-stomp-js/server_frame');
var StompServerConnection = require('vertx-stomp-js/stomp_server_connection');
var AuthProvider = require('vertx-auth-common-js/auth_provider');
var io = Packages.io;
var JsonObject = io.vertx.core.json.JsonObject;
var JStompServerHandler = Java.type('io.vertx.ext.stomp.StompServerHandler');
var BridgeOptions = Java.type('io.vertx.ext.stomp.BridgeOptions');
var Frame = Java.type('io.vertx.ext.stomp.Frame');
/**
STOMP server handler implements the behavior of the STOMP server when a specific event occurs. For instance, if
let customize the behavior when specific STOMP frames arrives or when a connection is closed. This class has been
designed to let you customize the server behavior. The default implementation is compliant with the STOMP
specification. In this default implementation, not acknowledge frames are dropped.
@class
*/
var StompServerHandler = function(j_val) {
var j_stompServerHandler = j_val;
var that = this;
/**
@public
@param arg0 {ServerFrame}
*/
this.handle = function(arg0) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'object' && __args[0]._jdel) {
j_stompServerHandler["handle(io.vertx.ext.stomp.ServerFrame)"](arg0._jdel);
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures a handler that get notified when a STOMP frame is received by the server.
This handler can be used for logging, debugging or ad-hoc behavior.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.receivedFrameHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["receivedFrameHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a CONNECT
frame is received.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.connectHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["connectHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a STOMP
frame is received.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.stompHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["stompHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a SUBSCRIBE
frame is received.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.subscribeHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["subscribeHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a UNSUBSCRIBE
frame is received.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.unsubscribeHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["unsubscribeHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a SEND
frame is received.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.sendHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["sendHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a connection with the client is closed.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.closeHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["closeHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(StompServerConnection, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Called when the connection is closed. This method executes a default behavior and must calls the configured
{@link StompServerHandler#closeHandler} if any.
@public
@param connection {StompServerConnection} the connection
*/
this.onClose = function(connection) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'object' && __args[0]._jdel) {
j_stompServerHandler["onClose(io.vertx.ext.stomp.StompServerConnection)"](connection._jdel);
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a COMMIT
frame is received.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.commitHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["commitHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a ABORT
frame is received.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.abortHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["abortHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a BEGIN
frame is received.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.beginHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["beginHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a DISCONNECT
frame is received.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.disconnectHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["disconnectHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a ACK
frame is received.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.ackHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["ackHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the action to execute when a NACK
frame is received.
@public
@param handler {function} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.nackHandler = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'function') {
j_stompServerHandler["nackHandler(io.vertx.core.Handler)"](function(jVal) {
handler(utils.convReturnVertxGen(ServerFrame, jVal));
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Called when the client connects to a server requiring authentication. It invokes the configured
using {@link StompServerHandler#authProvider}.
@public
@param connection {StompServerConnection} server connection that contains session ID
@param login {string} the login
@param passcode {string} the password
@param handler {function} handler receiving the authentication result
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.onAuthenticationRequest = function(connection, login, passcode, handler) {
var __args = arguments;
if (__args.length === 4 && typeof __args[0] === 'object' && __args[0]._jdel && typeof __args[1] === 'string' && typeof __args[2] === 'string' && typeof __args[3] === 'function') {
j_stompServerHandler["onAuthenticationRequest(io.vertx.ext.stomp.StompServerConnection,java.lang.String,java.lang.String,io.vertx.core.Handler)"](connection._jdel, login, passcode, function(ar) {
if (ar.succeeded()) {
handler(ar.result(), null);
} else {
handler(null, ar.cause());
}
});
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Provides for authorization matches on a destination level, this will return the User created by the .
@public
@param session {string} session ID for the server connection.
@return {User} null if not authenticated.
*/
this.getUserBySession = function(session) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'string') {
return utils.convReturnVertxGen(User, j_stompServerHandler["getUserBySession(java.lang.String)"](session));
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Configures the to be used to authenticate the user.
@public
@param handler {AuthProvider} the handler
@return {StompServerHandler} the current {@link StompServerHandler}
*/
this.authProvider = function(handler) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'object' && __args[0]._jdel) {
j_stompServerHandler["authProvider(io.vertx.ext.auth.AuthProvider)"](handler._jdel);
return that;
} else throw new TypeError('function invoked with invalid arguments');
};
/**
@public
@return {Array.} the list of destination managed by the STOMP server. Don't forget the STOMP interprets destination as opaque Strings.
*/
this.getDestinations = function() {
var __args = arguments;
if (__args.length === 0) {
return utils.convReturnListSetVertxGen(j_stompServerHandler["getDestinations()"](), Destination);
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Gets the destination with the given name.
@public
@param destination {string} the destination
@return {Destination} the {@link Destination}, null
if not existing.
*/
this.getDestination = function(destination) {
var __args = arguments;
if (__args.length === 1 && typeof __args[0] === 'string') {
return utils.convReturnVertxGen(Destination, j_stompServerHandler["getDestination(java.lang.String)"](destination));
} else throw new TypeError('function invoked with invalid arguments');
};
/**
Method called by single message (client-individual policy) or a set of message (client policy) are acknowledged.
Implementations must call the handler configured using {@link StompServerHandler#onAckHandler}.
@public
@param connection {StompServerConnection} the connection
@param subscribe {Object} the SUBSCRIBE
frame
@param messages {Array.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy