本文整理汇总了Java中play.libs.ws.WSRequest类的典型用法代码示例。如果您正苦于以下问题:Java WSRequest类的具体用法?Java WSRequest怎么用?Java WSRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WSRequest类属于play.libs.ws包,在下文中一共展示了WSRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
}
});
}
开发者ID:Azure,项目名称:device-telemetry-java,代码行数:18,代码来源:KeyValueClient.java
示例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);
}
开发者ID:CSCfi,项目名称:exam,代码行数:17,代码来源:FacilityController.java
示例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);
}
开发者ID:CSCfi,项目名称:exam,代码行数:22,代码来源:OrganisationController.java
示例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();
});
}
开发者ID:CSCfi,项目名称:exam,代码行数:19,代码来源:ExternalCourseHandlerImpl.java
示例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);
}
开发者ID:CSCfi,项目名称:exam,代码行数:22,代码来源:AssessmentSenderActor.java
示例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()));
}
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:22,代码来源:CustomAssistanceProxy.java
示例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;
}
开发者ID:Azure,项目名称:device-telemetry-java,代码行数:14,代码来源:Rules.java
示例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());
}
}
开发者ID:CSCfi,项目名称:exam,代码行数:37,代码来源:ExternalCalendarController.java
示例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);
}
开发者ID:CSCfi,项目名称:exam,代码行数:29,代码来源:ExternalCourseHandlerImpl.java
示例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);
}
开发者ID:CSCfi,项目名称:exam,代码行数:16,代码来源:NoShowHandlerImpl.java
示例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);
}
开发者ID:agiledigital,项目名称:poet-slack-bot,代码行数:18,代码来源:LuisServiceProvider.java
示例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);
}
开发者ID:agiledigital,项目名称:poet-slack-bot,代码行数:15,代码来源:JiraReaderService.java
示例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);
}
开发者ID:agiledigital,项目名称:poet-slack-bot,代码行数:13,代码来源:JiraReaderService.java
示例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");
}
}
开发者ID:vangav,项目名称:vos_backend,代码行数:9,代码来源:OAuth.java
示例16: sign
import play.libs.ws.WSRequest; //导入依赖的package包/类
@Override
public void sign(WSRequest request) {
try {
sign(wrap(request));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:vangav,项目名称:vos_backend,代码行数:9,代码来源:OAuth.java
示例17: sign
import play.libs.ws.WSRequest; //导入依赖的package包/类
private WSRequest sign() {
if (this.oauthToken != null && this.oauthSecret != null) {
WSOAuthConsumer consumer = new WSOAuthConsumer(oauthInfo, oauthToken, oauthSecret);
try {
consumer.sign(this, this.type);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return this;
}
开发者ID:eBay,项目名称:restcommander,代码行数:12,代码来源:WSAsync.java
示例18: wrap
import play.libs.ws.WSRequest; //导入依赖的package包/类
@Override
protected HttpRequest wrap(Object request) {
if (!(request instanceof WSRequest)) {
throw new IllegalArgumentException("WSOAuthConsumer expects requests of type play.libs.WS.WSRequest");
}
return new WSRequestAdapter((WSRequest)request);
}
开发者ID:eBay,项目名称:restcommander,代码行数:8,代码来源:WSAsync.java
示例19: updateFacility
import play.libs.ws.WSRequest; //导入依赖的package包/类
@Override
public CompletionStage<Result> updateFacility(ExamRoom room) throws MalformedURLException {
URL url = parseUrl(room.getExternalRef());
WSRequest request = wsClient.url(url.toString());
return request.put(Json.toJson(room)).thenApplyAsync(response -> ok(room));
}
开发者ID:CSCfi,项目名称:exam,代码行数:7,代码来源:FacilityController.java
示例20: requestRemoval
import play.libs.ws.WSRequest; //导入依赖的package包/类
private CompletionStage<Result> requestRemoval(String ref, User user) throws IOException {
final ExamEnrolment enrolment = Ebean.find(ExamEnrolment.class)
.fetch("reservation")
.fetch("reservation.machine")
.fetch("reservation.machine.room")
.where()
.eq("user.id", user.getId())
.eq("reservation.externalRef", ref)
.findUnique();
if (enrolment == null) {
return CompletableFuture.supplyAsync(() -> Results.notFound(String.format("No reservation with ref %s for current user.", ref)));
}
// Removal not permitted if reservation is in the past or ongoing
final Reservation reservation = enrolment.getReservation();
DateTime now = AppUtil.adjustDST(DateTime.now(), reservation.getExternalReservation());
if (reservation.toInterval().isBefore(now) || reservation.toInterval().contains(now)) {
return CompletableFuture.supplyAsync(() -> Results.forbidden("sitnet_reservation_in_effect"));
}
// good to go
ExternalReservation external = reservation.getExternalReservation();
URL url = parseUrl(external.getOrgRef(), external.getRoomRef(), ref);
WSRequest request = wsClient.url(url.toString());
Function<WSResponse, Result> onSuccess = response -> {
if (response.getStatus() != 200) {
JsonNode root = response.asJson();
return Results.internalServerError(root.get("message").asText("Connection refused"));
}
enrolment.setReservation(null);
enrolment.setReservationCanceled(true);
Ebean.save(enrolment);
reservation.delete();
// send email asynchronously
boolean isStudentUser = user.equals(enrolment.getUser());
system.scheduler().scheduleOnce(Duration.create(1, TimeUnit.SECONDS), () -> {
emailComposer.composeReservationCancellationNotification(enrolment.getUser(), reservation, "", isStudentUser, enrolment);
Logger.info("Reservation cancellation confirmation email sent");
}, system.dispatcher());
return Results.ok();
};
return request.delete().thenApplyAsync(onSuccess);
}
开发者ID:CSCfi,项目名称:exam,代码行数:44,代码来源:ExternalReservationHandlerImpl.java
注:本文中的play.libs.ws.WSRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论