/*
 * Copyright 2017-2020 original authors
 *
 * Licensed 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
 *
 * https://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.
 */
package io.micronaut.web.router.version;

import io.micronaut.context.annotation.Requires;
import io.micronaut.context.event.BeanCreatedEvent;
import io.micronaut.context.event.BeanCreatedEventListener;
import io.micronaut.core.util.StringUtils;
import io.micronaut.web.router.Router;
import io.micronaut.web.router.filter.FilteredRouter;

import javax.inject.Inject;
import javax.inject.Singleton;

import static io.micronaut.web.router.version.RoutesVersioningConfiguration.PREFIX;

Configuration to decorate Router with version matching logic.
Author:Bogdan Oros
Since:1.1.0
/** * Configuration to decorate {@link Router} with version matching logic. * * @author Bogdan Oros * @since 1.1.0 */
@Singleton @Requires(property = PREFIX + ".enabled", value = StringUtils.TRUE) @Requires(beans = RoutesVersioningConfiguration.class) public class VersionAwareRouterListener implements BeanCreatedEventListener<Router> { private final RouteVersionFilter routeVersionFilter;
Creates a configuration to decorate existing Router beans with a FilteredRouter.
Params:
/** * Creates a configuration to decorate existing {@link Router} beans with a {@link FilteredRouter}. * * @param filter A {@link io.micronaut.web.router.filter.RouteMatchFilter} to delegate routes filtering */
@Inject public VersionAwareRouterListener(RouteVersionFilter filter) { this.routeVersionFilter = filter; }
Returns a wrapped Router to FilteredRouter.
Params:
  • event – The Router bean created event
Returns:The wrapper router bean
/** * Returns a wrapped {@link Router} to {@link FilteredRouter}. * * @param event The {@link Router} bean created event * @return The wrapper router bean */
@Override public Router onCreated(BeanCreatedEvent<Router> event) { return new FilteredRouter(event.getBean(), routeVersionFilter); } }