Java Code Examples for com.linecorp.armeria.server.Route#pathType()

The following examples show how to use com.linecorp.armeria.server.Route#pathType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EurekaUpdatingListener.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Nullable
private static String healthCheckUrl(String hostnameOrIpAddr, @Nullable String oldHealthCheckUrl,
                                     PortWrapper portWrapper,
                                     Optional<ServiceConfig> healthCheckService,
                                     SessionProtocol sessionProtocol) {
    if (oldHealthCheckUrl != null) {
        return oldHealthCheckUrl;
    }
    if (!portWrapper.isEnabled() || !healthCheckService.isPresent()) {
        return null;
    }
    final ServiceConfig healthCheckServiceConfig = healthCheckService.get();
    final Route route = healthCheckServiceConfig.route();
    if (route.pathType() != RoutePathType.EXACT && route.pathType() != RoutePathType.PREFIX) {
        return null;
    }

    return sessionProtocol.uriText() + "://" + hostnameOrIpAddr(hostnameOrIpAddr) +
           ':' + portWrapper.getPort() + route.paths().get(0);
}
 
Example 2
Source File: SamlService.java    From armeria with Apache License 2.0 5 votes vote down vote up
SamlService(SamlServiceProvider sp) {
    this.sp = requireNonNull(sp, "sp");
    portConfigHolder = sp.portConfigAutoFiller();

    final ImmutableMap.Builder<String, SamlServiceFunction> builder = new Builder<>();
    sp.acsConfigs().forEach(
            cfg -> builder.put(cfg.endpoint().uri().getPath(),
                               new SamlAssertionConsumerFunction(cfg,
                                                                 sp.entityId(),
                                                                 sp.idpConfigs(),
                                                                 sp.defaultIdpConfig(),
                                                                 sp.requestIdManager(),
                                                                 sp.ssoHandler())));
    sp.sloEndpoints().forEach(
            cfg -> builder.put(cfg.uri().getPath(),
                               new SamlSingleLogoutFunction(cfg,
                                                            sp.entityId(),
                                                            sp.signingCredential(),
                                                            sp.signatureAlgorithm(),
                                                            sp.idpConfigs(),
                                                            sp.defaultIdpConfig(),
                                                            sp.requestIdManager(),
                                                            sp.sloHandler())));
    final Route route = sp.metadataRoute();
    if (route.pathType() == RoutePathType.EXACT) {
        builder.put(route.paths().get(0),
                    new SamlMetadataServiceFunction(sp.entityId(),
                                                    sp.signingCredential(),
                                                    sp.encryptionCredential(),
                                                    sp.idpConfigs(),
                                                    sp.acsConfigs(),
                                                    sp.sloEndpoints()));
    }
    serviceMap = builder.build();
    routes = serviceMap.keySet()
                       .stream()
                       .map(path -> Route.builder().exact(path).build())
                       .collect(toImmutableSet());
}
 
Example 3
Source File: AbstractCompositeService.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
public void serviceAdded(ServiceConfig cfg) throws Exception {
    checkState(server == null, "cannot be added to more than one server");
    server = cfg.server();

    final Route route = cfg.route();
    if (route.pathType() != RoutePathType.PREFIX) {
        throw new IllegalStateException("The path type of the route must be " + RoutePathType.PREFIX +
                                        ", path type: " + route.pathType());
    }

    router = Routers.ofCompositeService(services);

    final MeterRegistry registry = server.meterRegistry();
    final MeterIdPrefix meterIdPrefix;
    if (Flags.useLegacyMeterNames()) {
        meterIdPrefix = new MeterIdPrefix("armeria.server.router.compositeServiceCache",
                                          "hostnamePattern", cfg.virtualHost().hostnamePattern(),
                                          "route", route.meterTag());
    } else {
        meterIdPrefix = new MeterIdPrefix("armeria.server.router.composite.service.cache",
                                          "hostname.pattern", cfg.virtualHost().hostnamePattern(),
                                          "route", route.meterTag());
    }

    router.registerMetrics(registry, meterIdPrefix);
    for (CompositeServiceEntry<T> e : services()) {
        ServiceCallbackInvoker.invokeServiceAdded(cfg, e.service());
    }
}
 
Example 4
Source File: AnnotatedDocServicePlugin.java    From armeria with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static EndpointInfo endpointInfo(Route route, String hostnamePattern) {
    final EndpointInfoBuilder builder;
    final RoutePathType pathType = route.pathType();
    final List<String> paths = route.paths();
    switch (pathType) {
        case EXACT:
            builder = EndpointInfo.builder(hostnamePattern, RouteUtil.EXACT + paths.get(0));
            break;
        case PREFIX:
            builder = EndpointInfo.builder(hostnamePattern, RouteUtil.PREFIX + paths.get(0));
            break;
        case PARAMETERIZED:
            builder = EndpointInfo.builder(hostnamePattern, normalizeParameterized(route));
            break;
        case REGEX:
            builder = EndpointInfo.builder(hostnamePattern, RouteUtil.REGEX + paths.get(0));
            break;
        case REGEX_WITH_PREFIX:
            builder = EndpointInfo.builder(hostnamePattern, RouteUtil.REGEX + paths.get(0));
            builder.regexPathPrefix(RouteUtil.PREFIX + paths.get(1));
            break;
        default:
            // Should never reach here.
            throw new Error();
    }

    builder.availableMimeTypes(availableMimeTypes(route));
    return builder.build();
}