本文整理汇总了Java中play.libs.ws.WSRequest类的典型用法代码示例。如果您正苦于以下问题:Java WSRequest类的具体用法?Java WSRequest怎么用?Java WSRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WSRequest类属于play.libs.ws包,在下文中一共展示了WSRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pingAsync
import play.libs.ws.WSRequest; //导入依赖的package包/类
public CompletionStage<Status> pingAsync() {
WSRequest request = wsClient.url(storageAdapterWebserviceUrl + "/status");
request.setRequestTimeout(Duration.ofSeconds(10));
CompletionStage<WSResponse> responsePromise = request.get();
return responsePromise.handle((result, error) -> {
if (error != null) {
return new Status(false, error.getMessage());
} else {
if (result.getStatus() == 200) {
return new Status(true, "Alive and well");
} else {
return new Status(false, result.getStatusText());
}
}
});
}
示例2: listFacilities
import play.libs.ws.WSRequest; //导入依赖的package包/类
@Restrict({@Group("STUDENT")})
public CompletionStage<Result> listFacilities(Optional<String> organisation) throws MalformedURLException {
if (!organisation.isPresent()) {
return wrapAsPromise(badRequest());
}
URL url = parseExternalUrl(organisation.get());
WSRequest request = wsClient.url(url.toString());
Function<WSResponse, Result> onSuccess = response -> {
JsonNode root = response.asJson();
if (response.getStatus() != 200) {
return internalServerError(root.get("message").asText("Connection refused"));
}
return ok(root);
};
return request.get().thenApplyAsync(onSuccess);
}
示例3: listOrganisations
import play.libs.ws.WSRequest; //导入依赖的package包/类
@Restrict({@Group("STUDENT")})
public CompletionStage<Result> listOrganisations() throws MalformedURLException {
URL url = parseUrl();
WSRequest request = wsClient.url(url.toString());
String localRef = ConfigFactory.load().getString("sitnet.integration.iop.organisationRef");
Function<WSResponse, Result> onSuccess = response -> {
JsonNode root = response.asJson();
if (response.getStatus() != 200) {
return internalServerError(root.get("message").asText("Connection refused"));
}
if (root instanceof ArrayNode) {
ArrayNode node = (ArrayNode) root;
for (JsonNode n : node) {
((ObjectNode) n).put("homeOrg", n.get("_id").asText().equals(localRef));
}
}
return ok(root);
};
return request.get().thenApplyAsync(onSuccess);
}
示例4: downloadCourses
import play.libs.ws.WSRequest; //导入依赖的package包/类
private CompletionStage<List<Course>> downloadCourses(URL url) {
WSRequest request = wsClient.url(url.toString().split("\\?")[0]);
if (url.getQuery() != null) {
request = request.setQueryString(url.getQuery());
}
RemoteFunction<WSResponse, List<Course>> onSuccess = response -> {
int status = response.getStatus();
if (status == STATUS_OK) {
return parseCourses(response.asJson());
}
Logger.info("Non-OK response received for URL: {}. Status: {}", url, status);
throw new RemoteException(String.format("sitnet_remote_failure %d %s", status, response.getStatusText()));
};
return request.get().thenApplyAsync(onSuccess).exceptionally(t -> {
Logger.error("Connection error occurred", t);
return Collections.emptyList();
});
}
示例5: send
import play.libs.ws.WSRequest; //导入依赖的package包/类
private void send(ExamEnrolment enrolment) throws IOException {
String ref = enrolment.getReservation().getExternalRef();
Logger.debug("Sending back assessment for reservation " + ref);
URL url = parseUrl(ref);
WSRequest request = wsClient.url(url.toString());
ExternalExam ee = enrolment.getExternalExam();
Function<WSResponse, Void> onSuccess = response -> {
if (response.getStatus() != 201) {
Logger.error("Failed in sending assessment for reservation " + ref);
} else {
ee.setSent(DateTime.now());
ee.update();
Logger.info("Assessment for reservation " + ref + " processed successfully");
}
return null;
};
String json = Ebean.json().toJson(ee, PathProperties.parse("(*, creator(id))"));
ObjectMapper om = new ObjectMapper();
JsonNode node = om.readTree(json);
request.post(node).thenApplyAsync(onSuccess);
}
示例6: custom
import play.libs.ws.WSRequest; //导入依赖的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()));
}
示例7: prepareRequest
import play.libs.ws.WSRequest; //导入依赖的package包/类
private WSRequest prepareRequest(String id) {
String url = this.storageUrl;
if (id != null) {
url = url + "/" + id;
}
WSRequest wsRequest = this.wsClient
.url(url)
.addHeader("Content-Type", "application/json");
return wsRequest;
}
示例8: requestSlots
import play.libs.ws.WSRequest; //导入依赖的package包/类
@Restrict(@Group("STUDENT"))
public CompletionStage<Result> requestSlots(Long examId, String roomRef, Optional<String> org, Optional<String> date)
throws MalformedURLException {
if (org.isPresent() && date.isPresent()) {
// First check that exam exists
User user = getLoggedUser();
Exam exam = getEnrolledExam(examId, user);
if (exam == null) {
return wrapAsPromise(forbidden("sitnet_error_enrolment_not_found"));
}
// Also sanity check the provided search date
try {
parseSearchDate(date.get(), exam, null);
} catch (NotFoundException e) {
return wrapAsPromise(notFound());
}
// Ready to shoot
String start = ISODateTimeFormat.dateTime().print(new DateTime(exam.getExamActiveStartDate()));
String end = ISODateTimeFormat.dateTime().print(new DateTime(exam.getExamActiveEndDate()));
Integer duration = exam.getDuration();
URL url = parseUrl(org.get(), roomRef, date.get(), start, end, duration);
WSRequest request = wsClient.url(url.toString().split("\\?")[0]).setQueryString(url.getQuery());
Function<WSResponse, Result> onSuccess = response -> {
JsonNode root = response.asJson();
if (response.getStatus() != 200) {
return internalServerError(root.get("message").asText("Connection refused"));
}
Set<TimeSlot> slots = postProcessSlots(root, date.get(), exam, user);
return ok(Json.toJson(slots));
};
return request.get().thenApplyAsync(onSuccess);
} else {
return wrapAsPromise(badRequest());
}
}
示例9: getPermittedCourses
import play.libs.ws.WSRequest; //导入依赖的package包/类
@Override
public CompletionStage<Collection<String>> getPermittedCourses(User user) throws MalformedURLException {
URL url = parseUrl(user);
WSRequest request = wsClient.url(url.toString().split("\\?")[0]);
if (url.getQuery() != null) {
request = request.setQueryString(url.getQuery());
}
RemoteFunction<WSResponse, Collection<String>> onSuccess = response -> {
JsonNode root = response.asJson();
if (root.has("exception")) {
throw new RemoteException(root.get("exception").asText());
} else if (root.has("data")) {
Set<String> results = new HashSet<>();
for (JsonNode course : root.get("data")) {
if (course.has("course_code")) {
results.add(course.get("course_code").asText());
} else {
Logger.warn("Unexpected content {}", course.asText());
}
}
return results;
} else {
Logger.warn("Unexpected content {}", root.asText());
throw new RemoteException("sitnet_request_timed_out");
}
};
return request.get().thenApplyAsync(onSuccess);
}
示例10: send
import play.libs.ws.WSRequest; //导入依赖的package包/类
private void send(Reservation reservation) throws MalformedURLException {
URL url = parseUrl(reservation.getExternalRef());
WSRequest request = wsClient.url(url.toString());
Function<WSResponse, Void> onSuccess = response -> {
if (response.getStatus() != 200) {
Logger.error("No success in sending assessment #{} to XM", reservation.getExternalRef());
} else {
reservation.setNoShow(true);
reservation.update();
Logger.info("Successfully sent assessment #{} to XM", reservation.getExternalRef());
}
return null;
};
request.post(Json.newObject()).thenApplyAsync(onSuccess);
}
示例11: prepareRequestToModule
import play.libs.ws.WSRequest; //导入依赖的package包/类
private WSRequest prepareRequestToModule(ActiveAssistanceModule module) {
WSRequest request = ws.url(getURLForRequest(module));
request.setRequestTimeout(1L);
// TODO: Set request parameters?
// TODO: Auth against module?
// TODO: SSL? Probably not because inside cluster which is not reachable from outside
return request;
}
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:12,代码来源:CurrentModuleInformationAggregator.java
示例12: fetchLuisApi
import play.libs.ws.WSRequest; //导入依赖的package包/类
/**
* Connects to LuisServiceProvider API using HTTPS request.
* LuisServiceProvider API processes the query.
*
* @param query A string showing question asked by user.
* @return intent and entities as JSON object
*/
private CompletionStage<JsonNode> fetchLuisApi(String query) {
String luisurl = ConfigUtilities.getString("luis.url");
String key = ConfigUtilities.getString("luis.subscription-key");
WSRequest request = ws.url(luisurl);
WSRequest complexRequest = request.setQueryParameter("subscription-key", key).setQueryParameter("q", query);
return complexRequest.get().thenApply(WSResponse::asJson);
}
示例13: fetchTicketByApi
import play.libs.ws.WSRequest; //导入依赖的package包/类
/**
* To request for JIRA ticket info page via REST API. A non-blocking call.
*
* @param ticketId ticket ID in string.
* @return info page encoded in JSON.
*/
public CompletionStage<JsonNode> fetchTicketByApi(String ticketId) {
WSRequest request = ws.url(ConfigUtilities.getString("jira.baseUrl")
+ ConfigUtilities.getString("jira.issueEndpoint")
+ ticketId);
WSRequest complexRequest = request.setAuth(jiraAuth.username, jiraAuth.password, WSAuthScheme.BASIC);
return complexRequest.get().thenApply(WSResponse::asJson);
}
示例14: fetchAssigneeInfoByApi
import play.libs.ws.WSRequest; //导入依赖的package包/类
/** Fetches Assignee Info from JIRA API.
*
* @param jiraUsername jira username in string.
* @return info page encoded in JSON.
*/
public CompletionStage<JsonNode> fetchAssigneeInfoByApi(String jiraUsername) {
WSRequest request = ws.url("https://jira.agiledigital.com.au/rest/api/2/search")
.setQueryParameter("jql", "assignee=" + jiraUsername);
WSRequest complexRequest = request.setAuth(jiraAuth.username, jiraAuth.password, WSAuthScheme.BASIC);
return complexRequest.get().thenApply(WSResponse::asJson);
}
示例15: wrap
import play.libs.ws.WSRequest; //导入依赖的package包/类
@Override
protected HttpRequest wrap(Object request) {
if (request instanceof WSRequest) {
return new WSRequestAdapter((WSRequest)request);
} else {
throw new IllegalArgumentException("OAuthCalculator expects requests of type play.libs.WS.WSRequest");
}
}