当前位置: 首页>>代码示例>>Java>>正文


Java WS.url方法代码示例

本文整理汇总了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()));
}
 
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:22,代码来源:CustomAssistanceProxy.java

示例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);
}
 
开发者ID:tcompiegne,项目名称:oauth2-client-samples,代码行数:24,代码来源:TodoService.java

示例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);
}
 
开发者ID:tcompiegne,项目名称:oauth2-client-samples,代码行数:26,代码来源:TodoService.java

示例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;
}
 
开发者ID:tcompiegne,项目名称:oauth2-client-samples,代码行数:27,代码来源:UserInfo.java

示例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);

}
 
开发者ID:tcompiegne,项目名称:oauth2-client-samples,代码行数:15,代码来源:TodoService.java

示例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);
}
 
开发者ID:tfeng,项目名称:play-oauth2,代码行数:8,代码来源:IntegrationTest.java


注:本文中的play.libs.ws.WS.url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。