Search in sources :

Example 1 with WsHandlerMetaInfo

use of io.javalin.core.event.WsHandlerMetaInfo in project javalin by tipsy.

the class Javalin method addWsHandler.

/**
 * Adds a specific WebSocket handler for the given path to the instance.
 * Requires an access manager to be set on the instance.
 */
private Javalin addWsHandler(@NotNull WsHandlerType handlerType, @NotNull String path, @NotNull Consumer<WsConfig> wsConfig, @NotNull RouteRole... roles) {
    Set<RouteRole> roleSet = new HashSet<>(Arrays.asList(roles));
    javalinJettyServlet.addHandler(handlerType, path, wsConfig, roleSet);
    eventManager.fireWsHandlerAddedEvent(new WsHandlerMetaInfo(handlerType, Util.prefixContextPath(javalinServlet.getConfig().contextPath, path), wsConfig, roleSet));
    return this;
}
Also used : RouteRole(io.javalin.core.security.RouteRole) WsHandlerMetaInfo(io.javalin.core.event.WsHandlerMetaInfo) HashSet(java.util.HashSet)

Example 2 with WsHandlerMetaInfo

use of io.javalin.core.event.WsHandlerMetaInfo in project BlackOnion-Bot by Black0nion.

the class Paths method handle.

@Override
public Object handle(Context ctx, JSONObject body, Map<String, String> headers, @Nullable BlackSession session, DiscordUser user) throws Exception {
    PathListener instance = PathListener.getInstance();
    Map<HandlerType, List<String>> collected = instance.handlerMetaInfoList.stream().collect(Collectors.groupingBy(HandlerMetaInfo::getHttpMethod, mapping(HandlerMetaInfo::getPath, toList())));
    return new JSONObject(collected).put("WS", new JSONArray(instance.wsHandlerMetaInfoList.stream().map(WsHandlerMetaInfo::getPath).toList()));
}
Also used : JSONObject(org.json.JSONObject) WsHandlerMetaInfo(io.javalin.core.event.WsHandlerMetaInfo) HandlerMetaInfo(io.javalin.core.event.HandlerMetaInfo) HandlerType(io.javalin.http.HandlerType) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Aggregations

WsHandlerMetaInfo (io.javalin.core.event.WsHandlerMetaInfo)2 HandlerMetaInfo (io.javalin.core.event.HandlerMetaInfo)1 RouteRole (io.javalin.core.security.RouteRole)1 HandlerType (io.javalin.http.HandlerType)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1