/** * Build a new fake request. */ public static RequestBuilder fakeRequest(String method, String uri) { return new RequestBuilder().method(method).uri(uri); }
/** * Builds a new Http.Context from a new request * @return a new Http.Context using the default request * * @deprecated Deprecated as of 2.7.0. See <a href="https://www.playframework.com/documentation/latest/JavaHttpContextMigration27">migration guide</a>. */ @Deprecated public static Http.Context httpContext() { return httpContext(new Http.RequestBuilder().build()); }
/** * Route the request considering the given timeout. * * @param app The application used while routing and executing the request * @param requestBuilder the request builder * @param timeout the amount of time, in milliseconds, to wait for the body to be produced. * @return the result */ @SuppressWarnings("unchecked") public static Result route(Application app, RequestBuilder requestBuilder, long timeout) { final scala.Option<scala.concurrent.Future<play.api.mvc.Result>> opt = play.api.test.Helpers.jRoute( app.asScala(), requestBuilder.build().asScala(), requestBuilder.body() ); return wrapScalaResult(Scala.orNull(opt), timeout); }
@SuppressWarnings("unchecked") public static Result route(Application app, RequestBuilder requestBuilder, long timeout) { final scala.Option<scala.concurrent.Future<play.api.mvc.Result>> opt = play.api.test.Helpers.jRoute( app.getWrappedApplication(), requestBuilder.build()._underlyingRequest(), requestBuilder.bodyAsAnyContent()); return wrapScalaResult(Scala.orNull(opt), timeout); }
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); } }
@Deprecated public static Result route(Application app, RequestBuilder requestBuilder, byte[] body, long timeout) { return wrapScalaResult(Scala.orNull(play.api.test.Helpers.jRoute(app.getWrappedApplication(), requestBuilder.build()._underlyingRequest(), body)), timeout); }
/** * Builds a new Http.Context for a specific request * @param request the Request you want to use for this Context * @return a new Http.Context for this request * * @deprecated Deprecated as of 2.7.0. See <a href="https://www.playframework.com/documentation/latest/JavaHttpContextMigration27">migration guide</a>. */ @Deprecated public static Http.Context httpContext(Http.Request request) { return new Http.Context(request, contextComponents()); }
/** * @deprecated use {@link Result#cookie(String)} instead. */ @Deprecated public static Cookie cookie(String name, Result result) { return JavaResultExtractor.getCookies(result).get(name); }
/** * Extracts the content as a String. * * @param result The result to extract the content from. * @param mat The materializer to use to extract the body from the result stream. * @return The content of the result as a String. */ public static String contentAsString(Result result, Materializer mat) { return contentAsBytes(result, mat, DEFAULT_TIMEOUT) .decodeString(result.charset().orElse("utf-8")); }
/** * Extracts the content as a {@link akka.util.ByteString}. * <p> * This method is only capable of extracting the content of results with strict entities. To extract the content of * results with streamed entities, use {@link Helpers#contentAsBytes(Result, Materializer)}. * * @param result The result to extract the content from. * @return The content of the result as a ByteString. * @throws UnsupportedOperationException if the result does not have a strict entity. */ public static ByteString contentAsBytes(Result result) { if (result.body() instanceof HttpEntity.Strict) { return ((HttpEntity.Strict) result.body()).data(); } else { throw new UnsupportedOperationException("Tried to extract body from a non strict HTTP entity without a materializer, use the version of this method that accepts a materializer instead"); } }
/** * @deprecated use {@link Result#status()} instead. */ @Deprecated public static int status(Result result) { return result.toScala().header().status(); }
/** * Builds a new fake request. * @param method the request method. * @param uri the relative URL. * @return the request builder. */ public static RequestBuilder fakeRequest(String method, String uri) { return new RequestBuilder().method(method).uri(uri); }
/** * Route the request considering the given timeout. * * @param app The application used while routing and executing the request * @param requestBuilder the request builder * @param timeout the amount of time, in milliseconds, to wait for the body to be produced. * @return the result */ @SuppressWarnings("unchecked") public static Result route(Application app, RequestBuilder requestBuilder, long timeout) { final scala.Option<scala.concurrent.Future<play.api.mvc.Result>> opt = play.api.test.Helpers.jRoute( app.asScala(), requestBuilder.build().asScala(), requestBuilder.body() ); return wrapScalaResult(Scala.orNull(opt), timeout); }
/** * Builds a new Http.Context from a new request * @return a new Http.Context using the default request * * @deprecated Deprecated as of 2.7.0. See <a href="https://www.playframework.com/documentation/latest/JavaHttpContextMigration27">migration guide</a>. */ @Deprecated public static Http.Context httpContext() { return httpContext(new Http.RequestBuilder().build()); }
/** * Builds a new Http.Context for a specific request * @param request the Request you want to use for this Context * @return a new Http.Context for this request * * @deprecated Deprecated as of 2.7.0. See <a href="https://www.playframework.com/documentation/latest/JavaHttpContextMigration27">migration guide</a>. */ @Deprecated public static Http.Context httpContext(Http.Request request) { return new Http.Context(request, contextComponents()); }
/** * Extracts the content as a String. * * @param result The result to extract the content from. * @param mat The materializer to use to extract the body from the result stream. * @param timeout The amount of time, in milliseconds, to wait for the body to be produced. * @return The content of the result as a String. */ public static String contentAsString(Result result, Materializer mat, long timeout) { return contentAsBytes(result, mat, timeout) .decodeString(result.charset().orElse("utf-8")); }
/** * Builds a new fake request. * @param method the request method. * @param uri the relative URL. * @return the request builder. */ public static RequestBuilder fakeRequest(String method, String uri) { return new RequestBuilder().method(method).uri(uri); }