本文整理汇总了Java中play.libs.ws.WS.url方法的典型用法代码示例。如果您正苦于以下问题:Java WS.url方法的具体用法?Java WS.url怎么用?Java WS.url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.libs.ws.WS
的用法示例。
在下文中一共展示了WS.url方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: custom
import play.libs.ws.WS; //导入方法依赖的package包/类
private Promise<Result> custom(
String moduleId,
String path,
Function<WSRequest, Promise<WSResponse>> prepareAndFireRequest) {
long userId = getUserIdForRequest();
if (!UserModuleActivationPersistency.doesActivationExist(userId,
moduleId)) {
return Promise
.pure(badRequestJson(AssistanceAPIErrors.moduleActivationNotActive));
}
ActiveAssistanceModule module = UserModuleActivationPersistency.activatedModuleEndpointsForUser(new String[]{moduleId})[0];
WSRequest request = WS.url(module.restUrl("/custom/" + path));
request.setHeader("ASSISTANCE-USER-ID", Long.toString(userId));
Promise<WSResponse> responsePromise = prepareAndFireRequest.apply(request);
return responsePromise.map((response) -> (Result) Results.status(response.getStatus(),
response.getBody()));
}
示例2: findAll
import play.libs.ws.WS; //导入方法依赖的package包/类
public static List<Todo> findAll(String accessToken) {
WSRequestHolder req = WS.url(OAUTH_RESOURCE_SERVER_URL + "/rest/todos");
req.setHeader("Authorization", "Bearer " + accessToken);
Promise<List<Todo>> jsonPromise = req.get().map(new Function<WSResponse, List<Todo>>() {
public List<Todo> apply(WSResponse response) {
JsonNode json = response.asJson();
ArrayNode results = (ArrayNode) json;
List<Todo> todos = new ArrayList<Todo>();
Iterator<JsonNode> it = results.iterator();
while (it.hasNext()) {
JsonNode node = it.next();
Todo todo = new Todo();
todo.setDescription(node.get("description").asText());
todos.add(todo);
}
return todos;
}
});
return jsonPromise.get(5000);
}
示例3: findByUsername
import play.libs.ws.WS; //导入方法依赖的package包/类
public static List<Todo> findByUsername(String accessToken, String username) {
WSRequestHolder req = WS.url(OAUTH_RESOURCE_SERVER_URL + "/rest/todos/" + username);
req.setHeader("Authorization", "Bearer " + accessToken);
Promise<List<Todo>> jsonPromise = req.get().map(new Function<WSResponse, List<Todo>>() {
public List<Todo> apply(WSResponse response) {
JsonNode json = response.asJson();
ArrayNode results = (ArrayNode) json;
List<Todo> todos = new ArrayList<Todo>();
Iterator<JsonNode> it = results.iterator();
while (it.hasNext()) {
JsonNode node = it.next();
Todo todo = new Todo();
todo.setId(node.get("id").asLong());
todo.setDescription(node.get("description").asText());
todo.setUsername(node.get("username").asText());
todos.add(todo);
}
return todos;
}
});
return jsonPromise.get(5000);
}
示例4: index
import play.libs.ws.WS; //导入方法依赖的package包/类
public static Promise<Result> index() {
if (session().get("access_token") == null) {
return Promise.pure(redirect(routes.Application.index().absoluteURL(request())));
}
String accessToken = session().get("access_token");
WSRequestHolder req = WS.url(OAUTH_URL + "/userinfo");
req.setHeader("Authorization", "Bearer " + accessToken);
// Get the JSON Response
Promise<Result> resultPromise = req.get().map(new Function<WSResponse, Result>() {
public Result apply(WSResponse response) {
if (200 == response.getStatus()) {
// get the user info
String username = response.asJson().get("username").textValue();
session().put("username", username);
return redirect(routes.Application.index().absoluteURL(request()));
}
// go back to authentication
return redirect(OAuthUtils.oAuthAuthorizeUrl());
}
});
return resultPromise;
}
示例5: delete
import play.libs.ws.WS; //导入方法依赖的package包/类
public static String delete(String accessToken, String username, Long id) {
WSRequestHolder req = WS.url(OAUTH_RESOURCE_SERVER_URL + "/rest/todos/" + id + "/delete");
req.setHeader("Authorization", "Bearer " + accessToken);
Promise<String> jsonPromise = req.post("").map(new Function<WSResponse, String>() {
public String apply(WSResponse response) {
JsonNode json = response.asJson();
return json.asText();
}
});
return jsonPromise.get(5000);
}
示例6: getUser
import play.libs.ws.WS; //导入方法依赖的package包/类
private WSResponse getUser(String userAccessToken) {
WSRequestHolder requestHolder = WS.url("http://localhost:3333/user/get");
if (userAccessToken != null) {
requestHolder.setHeader("Authorization", "Bearer " + userAccessToken);
}
return requestHolder.get().get(TIMEOUT);
}