Here are the examples of the java api play.libs.concurrent.HttpExecutionContext.current() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
23 Examples
19
View Complete Implementation : PostResourceHandler.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
public CompletionStage<Optional<PostResource>> update(Http.Request request, String id, PostResource resource) {
final PostData data = new PostData(resource.getreplacedle(), resource.getBody());
return repository.update(Long.parseLong(id), data).thenApplyAsync(optionalData -> {
return optionalData.map(op -> new PostResource(op, link(request, op)));
}, ec.current());
}
19
View Complete Implementation : PostResourceHandler.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
public CompletionStage<PostResource> create(Http.Request request, PostResource resource) {
final PostData data = new PostData(resource.getreplacedle(), resource.getBody());
return repository.create(data).thenApplyAsync(savedData -> {
return new PostResource(savedData, link(request, savedData));
}, ec.current());
}
19
View Complete Implementation : PostResourceHandler.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
public CompletionStage<Optional<PostResource>> lookup(Http.Request request, String id) {
return repository.get(Long.parseLong(id)).thenApplyAsync(optionalData -> {
return optionalData.map(data -> new PostResource(data, link(request, data)));
}, ec.current());
}
19
View Complete Implementation : PostResourceHandler.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
public CompletionStage<Stream<PostResource>> find(Http.Request request) {
return repository.list().thenApplyAsync(postDataStream -> {
return postDataStream.map(data -> new PostResource(data, link(request, data)));
}, ec.current());
}
18
View Complete Implementation : PersonController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
public CompletionStage<Result> getPersons() {
return personRepository.list().thenApplyAsync(personStream -> ok(toJson(personStream.collect(Collectors.toList()))), ec.current());
}
18
View Complete Implementation : PostController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
public CompletionStage<Result> show(Http.Request request, String id) {
return handler.lookup(request, id).thenApplyAsync(optionalResource -> {
return optionalResource.map(resource -> ok(Json.toJson(resource))).orElseGet(Results::notFound);
}, ec.current());
}
17
View Complete Implementation : CallbackController.java
Copyright Apache License 2.0
Author : pac4j
Copyright Apache License 2.0
Author : pac4j
public CompletionStage<Result> callback() {
replacedertNotNull("callbackLogic", callbackLogic);
replacedertNotNull("config", config);
final PlayWebContext playWebContext = new PlayWebContext(ctx(), playSessionStore);
return CompletableFuture.supplyAsync(() -> callbackLogic.perform(playWebContext, config, config.getHttpActionAdapter(), this.defaultUrl, this.saveInSession, this.multiProfile, this.renewSession, this.defaultClient), ec.current());
}
17
View Complete Implementation : LogoutController.java
Copyright Apache License 2.0
Author : pac4j
Copyright Apache License 2.0
Author : pac4j
public CompletionStage<Result> logout() {
replacedertNotNull("logoutLogic", logoutLogic);
replacedertNotNull("config", config);
final PlayWebContext playWebContext = new PlayWebContext(ctx(), playSessionStore);
return CompletableFuture.supplyAsync(() -> logoutLogic.perform(playWebContext, config, config.getHttpActionAdapter(), this.defaultUrl, this.logoutUrlPattern, this.localLogout, this.destroySession, this.centralLogout), ec.current());
}
17
View Complete Implementation : HomeController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
/**
* Display the paginated list of computers.
*
* @param page Current page number (starts from 0)
* @param sortBy Column to be sorted
* @param order Sort order (either asc or desc)
* @param filter Filter applied on computer names
*/
public CompletionStage<Result> list(Http.Request request, int page, String sortBy, String order, String filter) {
// Run a db operation in another thread (using DatabaseExecutionContext)
return computerRepository.page(page, 10, sortBy, order, filter).thenApplyAsync(list -> {
// This is the HTTP rendering thread context
return ok(views.html.list.render(list, sortBy, order, filter, request, messagesApi.preferred(request)));
}, httpExecutionContext.current());
}
17
View Complete Implementation : HomeController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
/**
* Handle computer deletion
*/
public CompletionStage<Result> delete(Long id) {
// Run delete db operation, then redirect
return computerRepository.delete(id).thenApplyAsync(v -> {
// This is the HTTP rendering thread context
return GO_HOME.flashing("success", "Computer has been deleted");
}, httpExecutionContext.current());
}
17
View Complete Implementation : PostAction.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
private CompletionStage<Result> doCall(Http.Request request) {
return delegate.call(request).handleAsync((result, e) -> {
if (e != null) {
if (e instanceof CompletionException) {
Throwable completionException = e.getCause();
if (completionException instanceof FailsafeException) {
logger.error("Circuit breaker is open!", completionException);
return Results.status(SERVICE_UNAVAILABLE, "Service has timed out");
} else {
logger.error("Direct exception " + e.getMessage(), e);
return internalServerError();
}
} else {
logger.error("Unknown exception " + e.getMessage(), e);
return internalServerError();
}
} else {
return result;
}
}, ec.current());
}
17
View Complete Implementation : PostController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
public CompletionStage<Result> create(Http.Request request) {
JsonNode json = request.body().asJson();
final PostResource resource = Json.fromJson(json, PostResource.clreplaced);
return handler.create(request, resource).thenApplyAsync(savedResource -> {
return created(Json.toJson(savedResource));
}, ec.current());
}
17
View Complete Implementation : PostController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
public CompletionStage<Result> update(Http.Request request, String id) {
JsonNode json = request.body().asJson();
PostResource resource = Json.fromJson(json, PostResource.clreplaced);
return handler.update(request, id, resource).thenApplyAsync(optionalResource -> {
return optionalResource.map(r -> ok(Json.toJson(r))).orElseGet(Results::notFound);
}, ec.current());
}
16
View Complete Implementation : HomeController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
/**
* Display the 'new computer form'.
*/
public CompletionStage<Result> create(Http.Request request) {
Form<Computer> computerForm = formFactory.form(Computer.clreplaced);
// Run companies db operation and then render the form
return companyRepository.options().thenApplyAsync((Map<String, String> companies) -> {
// This is the HTTP rendering thread context
return ok(views.html.createForm.render(computerForm, companies, request, messagesApi.preferred(request)));
}, httpExecutionContext.current());
}
16
View Complete Implementation : PostController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
public CompletionStage<Result> list(Http.Request request) {
return handler.find(request).thenApplyAsync(posts -> {
final List<PostResource> postList = posts.collect(Collectors.toList());
return ok(Json.toJson(postList));
}, ec.current());
}
15
View Complete Implementation : Pac4jHandler.java
Copyright Apache License 2.0
Author : pac4j
Copyright Apache License 2.0
Author : pac4j
@Override
public CompletionStage<Result> onAuthFailure(final Http.Context context, final Optional<String> content) {
return CompletableFuture.supplyAsync(() -> {
final PlayWebContext playWebContext = new PlayWebContext(context, playSessionStore);
final HttpActionAdapter<Result, PlayWebContext> httpActionAdapter = config.getHttpActionAdapter();
return httpActionAdapter.adapt(403, playWebContext);
}, httpExecutionContext.current());
}
15
View Complete Implementation : PersonController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
public CompletionStage<Result> addPerson(final Http.Request request) {
Person person = formFactory.form(Person.clreplaced).bindFromRequest(request).get();
return personRepository.add(person).thenApplyAsync(p -> redirect(routes.PersonController.index()), ec.current());
}
14
View Complete Implementation : StockSentiment.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
private CompletionStage<List<String>> fetchTweets(String symbol) {
final CompletionStage<WSResponse> futureResponse = wsClient.url(tweetUrl).addQueryParameter("q", "$" + symbol).get();
final CompletionStage<WSResponse> filter = futureResponse.thenApplyAsync(response -> {
if (response.getStatus() == Http.Status.OK) {
return response;
} else {
return null;
}
}, ec.current());
return filter.thenApplyAsync(response -> {
final List<String> statuses = stream(response.asJson().findPath("statuses").spliterator(), false).map(s -> s.findValue("text").asText()).collect(Collectors.toList());
return statuses;
});
}
13
View Complete Implementation : Pac4jHandler.java
Copyright Apache License 2.0
Author : pac4j
Copyright Apache License 2.0
Author : pac4j
@Override
public CompletionStage<Optional<? extends Subject>> getSubject(final Http.Context context) {
return CompletableFuture.supplyAsync(() -> {
final Optional<CommonProfile> profile = getProfile(context);
if (profile.isPresent()) {
logger.debug("profile found: {} -> building a subject", profile);
return Optional.of(new Pac4jSubject(profile.get()));
} else {
logger.debug("no profile found -> returning empty");
return Optional.empty();
}
}, httpExecutionContext.current());
}
13
View Complete Implementation : HomeController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
/**
* Display the 'edit form' of a existing Computer.
*
* @param id Id of the computer to edit
*/
public CompletionStage<Result> edit(Http.Request request, Long id) {
// Run a db operation in another thread (using DatabaseExecutionContext)
CompletionStage<Map<String, String>> companiesFuture = companyRepository.options();
// Run the lookup also in another thread, then combine the results:
return computerRepository.lookup(id).thenCombineAsync(companiesFuture, (computerOptional, companies) -> {
// This is the HTTP rendering thread context
Computer c = computerOptional.get();
Form<Computer> computerForm = formFactory.form(Computer.clreplaced).fill(c);
return ok(views.html.editForm.render(id, computerForm, companies, request, messagesApi.preferred(request)));
}, httpExecutionContext.current());
}
11
View Complete Implementation : HomeController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
/**
* Handle the 'new computer form' submission
*/
public CompletionStage<Result> save(Http.Request request) {
Form<Computer> computerForm = formFactory.form(Computer.clreplaced).bindFromRequest(request);
if (computerForm.hasErrors()) {
// Run companies db operation and then render the form
return companyRepository.options().thenApplyAsync(companies -> {
// This is the HTTP rendering thread context
return badRequest(views.html.createForm.render(computerForm, companies, request, messagesApi.preferred(request)));
}, httpExecutionContext.current());
}
Computer computer = computerForm.get();
// Run insert db operation, then redirect
return computerRepository.insert(computer).thenApplyAsync(data -> {
// This is the HTTP rendering thread context
return GO_HOME.flashing("success", "Computer " + computer.name + " has been created");
}, httpExecutionContext.current());
}
11
View Complete Implementation : HomeController.java
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
Copyright Creative Commons Zero v1.0 Universal
Author : playframework
/**
* Handle the 'edit form' submission
*
* @param id Id of the computer to edit
*/
public CompletionStage<Result> update(Http.Request request, Long id) throws PersistenceException {
Form<Computer> computerForm = formFactory.form(Computer.clreplaced).bindFromRequest(request);
if (computerForm.hasErrors()) {
// Run companies db operation and then render the failure case
return companyRepository.options().thenApplyAsync(companies -> {
// This is the HTTP rendering thread context
return badRequest(views.html.editForm.render(id, computerForm, companies, request, messagesApi.preferred(request)));
}, httpExecutionContext.current());
} else {
Computer newComputerData = computerForm.get();
// Run update operation and then flash and then redirect
return computerRepository.update(id, newComputerData).thenApplyAsync(data -> {
// This is the HTTP rendering thread context
return GO_HOME.flashing("success", "Computer " + newComputerData.name + " has been updated");
}, httpExecutionContext.current());
}
}
2
View Complete Implementation : Pac4jHandler.java
Copyright Apache License 2.0
Author : pac4j
Copyright Apache License 2.0
Author : pac4j
@Override
public CompletionStage<Optional<Result>> beforeAuthCheck(final Http.Context context) {
return CompletableFuture.supplyAsync(() -> {
final Optional<CommonProfile> profile = getProfile(context);
if (profile.isPresent()) {
logger.debug("profile found -> returning empty");
return Optional.empty();
} else {
final PlayWebContext playWebContext = new PlayWebContext(context, playSessionStore);
final HttpActionAdapter<Result, PlayWebContext> httpActionAdapter = config.getHttpActionAdapter();
final List<Client> currentClients = getClientFinder().find(config.getClients(), playWebContext, clients);
logger.debug("currentClients: {}", currentClients);
HttpAction action;
try {
if (startDirectAuthentication(currentClients)) {
logger.debug("Starting direct authentication");
DirectClient client = (DirectClient) currentClients.get(0);
Credentials credentials = client.getCredentials(playWebContext);
if (credentials != null) {
CommonProfile userProfile = credentials.getUserProfile();
if (userProfile != null) {
setProfile(context, userProfile);
return Optional.empty();
}
}
logger.debug("unauthorized");
action = unauthorized(playWebContext, currentClients);
} else if (startAuthentication(playWebContext, currentClients)) {
logger.debug("Starting authentication");
saveRequestedUrl(playWebContext, currentClients);
action = redirectToIdenreplacedyProvider(playWebContext, currentClients);
} else {
logger.debug("unauthorized");
action = unauthorized(playWebContext, currentClients);
}
} catch (final HttpAction e) {
action = e;
}
return Optional.of(httpActionAdapter.adapt(action.getCode(), playWebContext));
}
}, httpExecutionContext.current());
}