private static Result wrapScalaResult(scala.concurrent.Future<play.api.mvc.Result> result, long timeout) { if (result == null) { return null; } else { try { final play.api.mvc.Result scalaResult = FutureConverters.toJava(result).toCompletableFuture().get(timeout, TimeUnit.MILLISECONDS); return scalaResult.asJava(); } catch (ExecutionException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } else { throw new RuntimeException(e.getCause()); } } catch (InterruptedException | TimeoutException e) { throw new RuntimeException(e); } } }
@SuppressWarnings(value = "unchecked") private static Result invokeHandler(play.api.Application app, 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.asScala()), timeout); } else if (handler instanceof JavaHandler) { final play.api.inject.Injector injector = app.injector(); final JavaHandlerComponents handlerComponents = injector.instanceOf(JavaHandlerComponents.class); return invokeHandler( app, ((JavaHandler) handler).withComponents(handlerComponents), requestBuilder, timeout ); } else { throw new RuntimeException("This is not a JavaAction and can't be invoked this way."); } }
/** * @return the underlying body, if present otherwise null */ public RequestBody body() { return underlying != null ? underlying.body() : null; }
/** * @return the version */ public String version() { return req.version(); }
/** * Sets the transient language. * * @param lang The language to use. * @return the builder instance */ public RequestBuilder transientLang(Lang lang) { req = req.withTransientLang(lang); return this; }
/** * @return the id of the request */ public Long id() { return req.id(); }
/** * @return gives the uri of the request */ public String uri() { return req.uri(); }
/** * Removes the transient language. * * @return the builder instance */ public RequestBuilder withoutTransientLang() { req = req.withoutTransientLang(); return this; }
/** * @param method sets the method * @return the builder instance */ public RequestBuilder method(String method) { req = req.withMethod(method); return this; }
/** * @param version the version * @return the builder instance */ public RequestBuilder version(String version) { req = req.withVersion(version); return this; }
/** * Change the Content-Type header for this result. */ public Status as(String contentType) { wrappedResult = wrappedResult.as(contentType); return this; }
@SuppressWarnings(value = "unchecked") private static Result invokeHandler(play.api.Application app, 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.asScala()), timeout); } else if (handler instanceof JavaHandler) { final play.api.inject.Injector injector = app.injector(); final JavaHandlerComponents handlerComponents = injector.instanceOf(JavaHandlerComponents.class); return invokeHandler( app, ((JavaHandler) handler).withComponents(handlerComponents), requestBuilder, timeout ); } else { throw new RuntimeException("This is not a JavaAction and can't be invoked this way."); } }
private static Result wrapScalaResult(scala.concurrent.Future<play.api.mvc.Result> result, long timeout) { if (result == null) { return null; } else { try { final play.api.mvc.Result scalaResult = FutureConverters.toJava(result).toCompletableFuture().get(timeout, TimeUnit.MILLISECONDS); return scalaResult.asJava(); } catch (ExecutionException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } else { throw new RuntimeException(e.getCause()); } } catch (InterruptedException | TimeoutException e) { throw new RuntimeException(e); } } }
/** * @return the version */ public String version() { return req.version(); }
/** * Sets the transient language. * * @param code The language to use. * @return the builder instance */ public RequestBuilder transientLang(String code) { req = req.withTransientLang(code); return this; }
@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."); } }