play.routing.Router Java Examples

The following examples show how to use play.routing.Router. 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: ParsedRoutes.java    From commercetools-sunrise-java with Apache License 2.0 5 votes vote down vote up
private static ParsedRoute parseRoute(final Router.RouteDocumentation routeDocumentation) {
    final String controllerMethodInvocation = routeDocumentation.getControllerMethodInvocation();
    if (countMatches(controllerMethodInvocation, '@') == 2) {
        final String controllerMethod = StringUtils.removeStart(controllerMethodInvocation, "@");
        final String controllerClassName = controllerMethod.substring(0, controllerMethod.indexOf("@"));
        try {
            return ParsedRoute.of(routeDocumentation, getClassByName(controllerClassName));
        } catch (ClassNotFoundException e) {
            throw new CompletionException(e);
        }
    }
    return ParsedRoute.of(routeDocumentation, null);
}
 
Example #2
Source File: HttpAuthenticationFilterTest.java    From commercetools-sunrise-java with Apache License 2.0 5 votes vote down vote up
private TestServer testServer(final boolean isAuthEnabled) {
    final Router router = new RoutingDsl()
            .GET(URI).routeTo(() -> ok())
            .build();
    final Application app = new GuiceApplicationBuilder()
            .configure("play.http.filters", "com.commercetools.sunrise.httpauth.basic.BasicHttpAuthenticationFilters")
            .overrides(
                    bind(HttpAuthentication.class).toInstance(httpAuthentication(isAuthEnabled)),
                    bind(play.api.routing.Router.class).toInstance(router.asScala()))
            .build();
    return Helpers.testServer(app);
}
 
Example #3
Source File: BasicHttpAuthenticationFilterTest.java    From commercetools-sunrise-java with Apache License 2.0 5 votes vote down vote up
@Override
protected Application provideApplication() {
    final Router router = new RoutingDsl()
            .GET(URI).routeTo(() -> ok())
            .build();
    return new GuiceApplicationBuilder()
            .configure("play.http.filters", "com.commercetools.sunrise.httpauth.basic.BasicHttpAuthenticationFilters")
            .overrides(
                    bind(HttpAuthentication.class).toInstance(new BasicHttpAuthentication(REALM, USERNAME + ":" + PASSWORD)),
                    bind(play.api.routing.Router.class).toInstance(router.asScala()))
            .build();
}
 
Example #4
Source File: StatusServer.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
protected static Router createRouter(StatusStorage statusStorage, BuiltInComponents builtInComponents){
    RoutingDsl dsl = RoutingDsl.fromComponents(builtInComponents);
    dsl.GET("/ids/").routingTo(request -> ok(toJson(statusStorage.ids())));
    dsl.GET("/state/:id").routingTo((request, id) -> ok(toJson(statusStorage.getState(Integer.parseInt(id.toString())))));
    dsl.GET("/opType/:id").routingTo((request, id) -> ok(toJson(ServerTypeJson.builder()
            .type(statusStorage.getState(Integer.parseInt(id.toString())).serverType()))));
    dsl.GET("/started/:id").routingTo((request, id) -> {
        boolean isMaster = statusStorage.getState(Integer.parseInt(id.toString())).isMaster();
        if(isMaster){
            return ok(toJson(MasterStatus.builder().master(statusStorage.getState(Integer.parseInt(id.toString())).getServerState())
                    //note here that a responder is id + 1
                    .responder(statusStorage.getState(Integer.parseInt(id.toString()) + 1).getServerState())
                    .responderN(statusStorage.getState(Integer.parseInt(id.toString())).getTotalUpdates())
                    .build()));
        } else {
            return ok(toJson(SlaveStatus.builder().slave(statusStorage.getState(Integer.parseInt(id.toString())).serverType()).build()));
        }
    });
    dsl.GET("/connectioninfo/:id").routingTo((request, id) -> ok(toJson(statusStorage.getState(Integer.parseInt(id.toString())).getConnectionInfo())));

    dsl.POST("/updatestatus/:id").routingTo((request, id) -> {
        SubscriberState subscriberState = Json.fromJson(request.body().asJson(), SubscriberState.class);
        statusStorage.updateState(subscriberState);
        return ok(toJson(subscriberState));
    });

    return dsl.build();
}
 
Example #5
Source File: TracingFilterTest.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
public TypedMap attrs() {
    HandlerDef def = new HandlerDef(null, null, null, "GET", null, null, "/projects/$projectId<[^/]+>", null, null);
    return TypedMap.empty().put(Router.Attrs.HANDLER_DEF, def);
}
 
Example #6
Source File: ParsedRoutes.java    From commercetools-sunrise-java with Apache License 2.0 4 votes vote down vote up
@Inject
ParsedRoutes(final Router router) {
    this.routes = router.documentation().stream()
            .map(ParsedRoutes::parseRoute)
            .collect(Collectors.toList());
}
 
Example #7
Source File: ParsedRoute.java    From commercetools-sunrise-java with Apache License 2.0 4 votes vote down vote up
private ParsedRoute(final Router.RouteDocumentation routeDocumentation, @Nullable final Class<?> controllerClass) {
    this.routeDocumentation = routeDocumentation;
    this.controllerClass = controllerClass;
}
 
Example #8
Source File: ParsedRoute.java    From commercetools-sunrise-java with Apache License 2.0 4 votes vote down vote up
public Router.RouteDocumentation getRouteDocumentation() {
    return routeDocumentation;
}
 
Example #9
Source File: ParsedRoute.java    From commercetools-sunrise-java with Apache License 2.0 4 votes vote down vote up
public static ParsedRoute of(final Router.RouteDocumentation routeDocumentation, @Nullable final Class<?> controllerClass) {
    return new ParsedRoute(routeDocumentation, controllerClass);
}