/** * convert by name. * * @param name name * @return {@link HttpMethodEnum } */ public static HttpMethodEnum acquireByName(final String name) { return Arrays.stream(HttpMethodEnum.values()) .filter(e -> e.support && e.name.equals(name)).findFirst() .orElseThrow(() -> new SoulException(" this http method can not support!")); }
List<EnumVO> httpMethodEnums = Arrays.stream(HttpMethodEnum.values()) .map(httpMethodEnum -> new EnumVO(null, httpMethodEnum.getName(), httpMethodEnum.getSupport())) .collect(Collectors.toList());
private Mono<Void> doHttpInvoke() { if (requestDTO.getHttpMethod().equals(HttpMethodEnum.GET.getName())) { String uri = buildRealURL(); if (StringUtils.isNoneBlank(requestDTO.getExtInfo())) { uri = uri + "?" + GSONUtils.getInstance().toGetParam(requestDTO.getExtInfo()); } return WEB_CLIENT.get().uri(uri) .headers(httpHeaders -> { httpHeaders.addAll(exchange.getRequest().getHeaders()); httpHeaders.remove(HttpHeaders.HOST); }) .exchange() .doOnError(e -> LogUtils.error(LOGGER, e::getMessage)) .timeout(Duration.ofMillis(timeout)) .flatMap(this::doNext); } else if (requestDTO.getHttpMethod().equals(HttpMethodEnum.POST.getName())) { return WEB_CLIENT.post().uri(buildRealURL()) .headers(httpHeaders -> { httpHeaders.addAll(exchange.getRequest().getHeaders()); httpHeaders.remove(HttpHeaders.HOST); }) .contentType(buildMediaType()) .body(BodyInserters.fromDataBuffers(exchange.getRequest().getBody())) .exchange() .doOnError(e -> LogUtils.error(LOGGER, e::getMessage)) .timeout(Duration.ofMillis(timeout)) .flatMap(this::doNext); } return Mono.empty(); }
private Boolean verify(final RequestDTO requestDTO, final ServerWebExchange exchange) { if (Objects.isNull(requestDTO) || StringUtils.isBlank(requestDTO.getModule()) || StringUtils.isBlank(requestDTO.getMethod())) { return false; } final RpcTypeEnum rpcTypeEnum = RpcTypeEnum.acquireByName(requestDTO.getRpcType()); if (Objects.isNull(rpcTypeEnum)) { return false; } //if rpcType is dubbo if (Objects.equals(rpcTypeEnum.getName(), RpcTypeEnum.DUBBO.getName())) { final String dubboParams = requestDTO.getDubboParams(); if (StringUtils.isBlank(dubboParams)) { return false; } final Map<String, Object> paramMap = GSONUtils.getInstance().toObjectMap(dubboParams); if (paramMap.containsKey(DubboParamConstants.INTERFACE_NAME) && paramMap.containsKey(DubboParamConstants.METHOD)) { exchange.getAttributes().put(Constants.DUBBO_PARAMS, paramMap); return true; } else { return false; } } else { return !StringUtils.isBlank(requestDTO.getHttpMethod()) && !Objects.isNull(HttpMethodEnum.acquireByName(requestDTO.getHttpMethod())); } }