當前位置: 首頁>>代碼示例>>Java>>正文


Java DeferredResult.setErrorResult方法代碼示例

本文整理匯總了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;
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:31,代碼來源:PluginApiController.java

示例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;
}
 
開發者ID:rsdomingues,項目名稱:wiredtigervsvmap,代碼行數:23,代碼來源:DeferredResultAdapter.java

示例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;
}
 
開發者ID:zalando-nakadi,項目名稱:paradox-nakadi-consumer,代碼行數:25,代碼來源:ControllerConfiguration.java

示例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;
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:31,代碼來源:PluginApiController.java

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

}
 
開發者ID:btrofimov,項目名稱:spark-enterprise-example,代碼行數:15,代碼來源:BulletinController.java

示例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;
}
 
開發者ID:KonkerLabs,項目名稱:konker-platform,代碼行數:66,代碼來源:DeviceEventRestEndpoint.java

示例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;
}
 
開發者ID:zalando-nakadi,項目名稱:paradox-nakadi-consumer,代碼行數:6,代碼來源:ControllerConfiguration.java


注:本文中的org.springframework.web.context.request.async.DeferredResult.setErrorResult方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。