Example #1
0
 public static Result routeAndCall(Router router, RequestBuilder requestBuilder, long timeout) {
   try {
     Request request = requestBuilder.build();
     if (router.routes().isDefinedAt(request._underlyingRequest())) {
       return invokeHandler(router.routes().apply(request._underlyingRequest()), request, timeout);
     } else {
       return null;
     }
   } catch (RuntimeException e) {
     throw e;
   } catch (Throwable t) {
     throw new RuntimeException(t);
   }
 }
Example #2
0
 public static Result routeAndCall(
     Class<? extends Router> router, RequestBuilder requestBuilder, long timeout) {
   try {
     Request request = requestBuilder.build();
     Router routes =
         (Router)
             router
                 .getClassLoader()
                 .loadClass(router.getName() + "$")
                 .getDeclaredField("MODULE$")
                 .get(null);
     if (routes.routes().isDefinedAt(request._underlyingRequest())) {
       return invokeHandler(routes.routes().apply(request._underlyingRequest()), request, timeout);
     } else {
       return null;
     }
   } catch (RuntimeException e) {
     throw e;
   } catch (Throwable t) {
     throw new RuntimeException(t);
   }
 }
Example #3
0
 // --
 @SuppressWarnings(value = "unchecked")
 private static Result invokeHandler(
     play.api.mvc.Handler handler, Request requestBuilder, long timeout) {
   if (handler instanceof play.api.mvc.Action) {
     play.api.mvc.Action action = (play.api.mvc.Action) handler;
     return wrapScalaResult(action.apply(requestBuilder._underlyingRequest()), timeout);
   } else if (handler instanceof JavaHandler) {
     return invokeHandler(
         ((JavaHandler) handler)
             .withComponents(
                 Play.application().injector().instanceOf(JavaHandlerComponents.class)),
         requestBuilder,
         timeout);
   } else {
     throw new RuntimeException("This is not a JavaAction and can't be invoked this way.");
   }
 }