本文整理汇总了Java中org.springframework.web.context.request.async.DeferredResult.setErrorResult方法的典型用法代码示例。如果您正苦于以下问题:Java DeferredResult.setErrorResult方法的具体用法?Java DeferredResult.setErrorResult怎么用?Java DeferredResult.setErrorResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.request.async.DeferredResult
的用法示例。
在下文中一共展示了DeferredResult.setErrorResult方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processRequest
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/{pluginToken}/**")
@ResponseStatus(value = HttpStatus.OK)
public DeferredResult<ResponseEntity> processRequest(
@PathVariable("pluginToken") String pluginToken,
RequestEntity<byte[]> requestEntity,
HttpServletRequest request)
throws IoTPException {
log.debug("[{}] Going to process requst uri: {}", pluginToken, requestEntity.getUrl());
DeferredResult<ResponseEntity> result = new DeferredResult<ResponseEntity>();
PluginMetaData pluginMd = pluginService.findPluginByApiToken(pluginToken);
if (pluginMd == null) {
result.setErrorResult(new PluginNotFoundException("Plugin with token: " + pluginToken + " not found!"));
} else {
TenantId tenantId = getCurrentUser().getTenantId();
CustomerId customerId = getCurrentUser().getCustomerId();
if (validatePluginAccess(pluginMd, tenantId, customerId)) {
if(ModelConstants.NULL_UUID.equals(tenantId.getId())){
tenantId = null;
}
PluginApiCallSecurityContext securityCtx = new PluginApiCallSecurityContext(pluginMd.getTenantId(), pluginMd.getId(), tenantId, customerId);
actorService.process(new BasicPluginRestMsg(securityCtx, new RestRequest(requestEntity, request), result));
} else {
result.setResult(new ResponseEntity<>(HttpStatus.FORBIDDEN));
}
}
return result;
}
示例2: requestAsync
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
public static <T> DeferredResult<T> requestAsync(final TaskExecutor executor,
final Callable<T> action) {
final DeferredResult<T> result = new DeferredResult<>();
final Runnable beforeCallable = () -> {
try {
T t = action.call();
if (result.isSetOrExpired()) {
log.error("async request expired");
return;
}
result.setResult(t);
} catch (final Exception ex) {
result.setErrorResult(ex);
}
};
executor.execute(beforeCallable);
return result;
}
示例3: deferredReplayResult
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
private DeferredResult<ResponseEntity<?>> deferredReplayResult(final EventTypePartition eventTypePartition,
final String consumerName, final boolean verbose, final Single<String> singleContent) {
final DeferredResult<ResponseEntity<?>> deferredResult = new DeferredResult<>(DEFERRED_TIMEOUT);
final Set<EventTypeConsumer> consumers = registry.getEventTypeConsumers().stream()
.filter(filterConsumer(eventTypePartition.getName(),
consumerName)).collect(Collectors.toSet());
if (consumers.isEmpty()) {
deferredResult.setErrorResult(ResponseEntity.notFound().build());
} else {
singleContent.subscribe(content -> {
consumers.forEach(eventTypeConsumer -> {
final EventHandler<?> handler = requireNonNull(
registry.getEventTypeConsumerHandler(eventTypeConsumer), "handler not found");
replayHandler.handle(consumerName, handler, eventTypePartition, content);
});
deferredResult.setResult(ok(verbose ? content : ""));
},
throwable -> deferredResult.setErrorResult(badRequest().body(throwable.toString())));
}
return deferredResult;
}
示例4: processRequest
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/{pluginToken}/**")
@ResponseStatus(value = HttpStatus.OK)
public DeferredResult<ResponseEntity> processRequest(
@PathVariable("pluginToken") String pluginToken,
RequestEntity<byte[]> requestEntity,
HttpServletRequest request)
throws ThingsboardException {
log.debug("[{}] Going to process requst uri: {}", pluginToken, requestEntity.getUrl());
DeferredResult<ResponseEntity> result = new DeferredResult<ResponseEntity>();
PluginMetaData pluginMd = pluginService.findPluginByApiToken(pluginToken);
if (pluginMd == null) {
result.setErrorResult(new PluginNotFoundException("Plugin with token: " + pluginToken + " not found!"));
} else {
TenantId tenantId = getCurrentUser().getTenantId();
CustomerId customerId = getCurrentUser().getCustomerId();
if (validatePluginAccess(pluginMd, tenantId, customerId)) {
if(tenantId != null && ModelConstants.NULL_UUID.equals(tenantId.getId())){
tenantId = null;
}
PluginApiCallSecurityContext securityCtx = new PluginApiCallSecurityContext(pluginMd.getTenantId(), pluginMd.getId(), tenantId, customerId);
actorService.process(new BasicPluginRestMsg(securityCtx, new RestRequest(requestEntity, request), result));
} else {
result.setResult(new ResponseEntity<>(HttpStatus.FORBIDDEN));
}
}
return result;
}
示例5: onCompleted
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
private void onCompleted(
final String cmdId,
final CmdCompleted cmdCompleted,
final DeferredResult<Bulletin> deferredResult) {
if(cmdCompleted.getSucceeded()) {
deferredResult.setResult(repo.findOne(cmdId));
} else {
deferredResult.setErrorResult(new RuntimeException(cmdCompleted.getErrorMessage()));
}
}
示例6: subEvent
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@RequestMapping(
value = { "sub/{apiKey}", "sub/{apiKey}/{channel}" },
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@JsonView(EventJsonView.class)
public DeferredResult<List<EventVO>> subEvent(HttpServletRequest servletRequest,
@PathVariable("apiKey") String apiKey,
@PathVariable(name="channel", required=false) String channel,
@AuthenticationPrincipal Device principal,
@RequestParam(name = "offset", required = false) Optional<Long> offset,
@RequestParam(name = "waitTime", required = false) Optional<Long> waitTime,
Locale locale,
HttpServletResponse httpResponse) {
DeferredResult<List<EventVO>> deferredResult = new DeferredResult<>(waitTime.orElse(new Long("0")), Collections.emptyList());
Device device = deviceRegisterService.findByApiKey(apiKey);
if (!principal.getApiKey().equals(apiKey)) {
deferredResult.setErrorResult(applicationContext.getMessage(Messages.INVALID_RESOURCE.getCode(), null, locale));
httpResponse.setStatus(HttpStatus.BAD_REQUEST.value());
return deferredResult;
}
if (waitTime.isPresent() && waitTime.get().compareTo(new Long("30000")) > 0) {
deferredResult.setErrorResult(applicationContext.getMessage(Messages.INVALID_WAITTIME.getCode(), null, locale));
httpResponse.setStatus(HttpStatus.BAD_REQUEST.value());
return deferredResult;
}
if(Optional.ofNullable(channel).isPresent() &&
(channel.length() > 32 || Pattern.compile("[^A-Za-z0-9_-]").matcher(channel).find())){
deferredResult.setErrorResult(applicationContext.getMessage(Messages.INVALID_CHANNEL_PATTERN.getCode(), null, locale));
httpResponse.setStatus(HttpStatus.BAD_REQUEST.value());
return deferredResult;
}
if (!Optional.of(device).isPresent()) {
deferredResult.setErrorResult(applicationContext.getMessage(Messages.DEVICE_NOT_FOUND.getCode(), null, locale));
httpResponse.setStatus(HttpStatus.BAD_REQUEST.value());
return deferredResult;
}
Instant startTimestamp = offset.isPresent() ? Instant.ofEpochMilli(offset.get()) : null;
boolean asc = offset.isPresent();
Integer limit = offset.isPresent() ? 50 : 1;
ServiceResponse<List<Event>> response = deviceEventService.findOutgoingBy(device.getTenant(), device.getApplication(), device.getGuid(),
channel, startTimestamp, null, asc, limit);
if (!response.getResult().isEmpty() || !waitTime.isPresent() || (waitTime.isPresent() && waitTime.get().equals(new Long("0")))) {
deferredResult.setResult(EventVO.from(response.getResult()));
} else {
CompletableFuture.supplyAsync(() -> {
String subChannel = Optional.ofNullable(channel).isPresent() ? apiKey+"."+channel : apiKey;
return jedisTaskService.subscribeToChannel(subChannel, startTimestamp, asc, limit);
}, executor)
.whenCompleteAsync((result, throwable) -> deferredResult.setResult(EventVO.from(result)), executor);
}
return deferredResult;
}
示例7: getBadDeferredResult
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
private DeferredResult<ResponseEntity<?>> getBadDeferredResult() {
final DeferredResult<ResponseEntity<?>> deferredResult = new DeferredResult<>();
deferredResult.setErrorResult(badRequest().body("Consumer not found."));
return deferredResult;
}