Search in sources :

Example 1 with HandlerMetaInfo

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

the class Javalin method addHandler.

/**
 * Adds a request handler for the specified handlerType and path to the instance.
 * Requires an access manager to be set on the instance.
 * This is the method that all the verb-methods (get/post/put/etc) call.
 *
 * @see AccessManager
 * @see <a href="https://javalin.io/documentation#handlers">Handlers in docs</a>
 */
public Javalin addHandler(@NotNull HandlerType handlerType, @NotNull String path, @NotNull Handler handler, @NotNull RouteRole... roles) {
    Set<RouteRole> roleSet = new HashSet<>(Arrays.asList(roles));
    javalinServlet.addHandler(handlerType, path, handler, roleSet);
    eventManager.fireHandlerAddedEvent(new HandlerMetaInfo(handlerType, Util.prefixContextPath(javalinServlet.getConfig().contextPath, path), handler, roleSet));
    return this;
}
Also used : RouteRole(io.javalin.core.security.RouteRole) WsHandlerMetaInfo(io.javalin.core.event.WsHandlerMetaInfo) HandlerMetaInfo(io.javalin.core.event.HandlerMetaInfo) HashSet(java.util.HashSet)

Example 2 with HandlerMetaInfo

use of io.javalin.core.event.HandlerMetaInfo 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

HandlerMetaInfo (io.javalin.core.event.HandlerMetaInfo)2 WsHandlerMetaInfo (io.javalin.core.event.WsHandlerMetaInfo)2 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