Here are the examples of the java api play.libs.F.Promise taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
16
Source : Global.java
with MIT License
from vangav
with MIT License
from vangav
@Override
public F.Promise<SimpleResult> onHandlerNotFound(Http.RequestHeader requestHeader) {
// This is here to make sure that the context is set, there is a test that replacederts
// that this is true
Http.Context.current().session().put("onHandlerNotFound", "true");
return F.Promise.<SimpleResult>pure(Results.notFound());
}
15
Source : RequireCSRFCheckAction.java
with MIT License
from vangav
with MIT License
from vangav
@Override
public F.Promise<SimpleResult> call(Http.Context ctx) throws Throwable {
RequestHeader request = ctx._requestHeader();
// Check for bypreplaced
if (CSRFAction.checkCsrfBypreplaced(request)) {
return delegate.call(ctx);
} else {
// Get token from cookie/session
Option<String> headerToken = CSRFAction.getTokenFromHeader(request, tokenName, cookieName);
if (headerToken.isDefined()) {
String tokenToCheck = null;
// Get token from query string
Option<String> queryStringToken = CSRFAction.getTokenFromQueryString(request, tokenName);
if (queryStringToken.isDefined()) {
tokenToCheck = queryStringToken.get();
} else {
// Get token from body
if (ctx.request().body().asFormUrlEncoded() != null) {
String[] values = ctx.request().body().asFormUrlEncoded().get(tokenName);
if (values != null && values.length > 0) {
tokenToCheck = values[0];
}
} else if (ctx.request().body().asMultipartFormData() != null) {
String[] values = ctx.request().body().asMultipartFormData().asFormUrlEncoded().get(tokenName);
if (values != null && values.length > 0) {
tokenToCheck = values[0];
}
}
}
if (tokenToCheck != null) {
if (tokenProvider.compareTokens(tokenToCheck, headerToken.get())) {
return delegate.call(ctx);
} else {
return F.Promise.pure((SimpleResult) forbidden("CSRF tokens don't match"));
}
} else {
return F.Promise.pure((SimpleResult) forbidden("CSRF token not found in body or query string"));
}
} else {
return F.Promise.pure((SimpleResult) forbidden("CSRF token not found in session"));
}
}
}
14
Source : PromiseTest.java
with MIT License
from vangav
with MIT License
from vangav
@Test
public void zip() {
Promise<String> a = Promise.pure("a");
Promise<Integer> b = Promise.pure(10);
Tuple<String, Integer> ab = a.zip(b).get();
replacedertThat(ab._1).isEqualTo("a");
replacedertThat(ab._2).isEqualTo(10);
}