Java Code Examples for io.micrometer.core.instrument.util.StringUtils#isNotEmpty()

The following examples show how to use io.micrometer.core.instrument.util.StringUtils#isNotEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeignBasicAuthRequestInterceptor.java    From mogu_blog_v2 with Apache License 2.0 7 votes vote down vote up
@Override
public void apply(RequestTemplate requestTemplate) {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    // 获取token,放入到feign的请求头
    String token = request.getParameter("token");

    if(StringUtils.isNotEmpty(token)){
        // 如果带有?说明还带有其它参数,我们只截取到token即可
        if(token.indexOf("?") != -1) {
            String [] params = token.split("\\?url=");
            token = params[0];
        }
        requestTemplate.header("pictureToken", token);
    }
}
 
Example 2
Source File: ApplicationController.java    From Moss with Apache License 2.0 6 votes vote down vote up
/**
 * 得到应用的flux 实例
 * @return
 */
private Flux<MossApplication> applicationFlux(String appName){
    Flux<Instance> instanceFlux=null;
    /**
     * 当应用名不为空进行过滤分页
     */
    if(StringUtils.isNotEmpty(appName)){
        //因为注册到Eureka上的服务为大写
        instanceFlux=registry.getInstances(appName);
    }else {
        instanceFlux=registry.getInstances();
    }
    String registerSource = this.getRegisterSource();
    if(StringUtils.isNotEmpty(registerSource)){
        instanceFlux=instanceFlux.filter(instance->registerSource.equalsIgnoreCase(instance.getRegistration().getSource()));
    }
    return instanceFlux.filter(Instance::isRegistered)
            .groupBy(instance -> instance.getRegistration().getName())
            .flatMap(grouped -> toApplication(grouped.key(), grouped));
}
 
Example 3
Source File: CustomAuthenticationSuccessHandler.java    From oauth2-client with MIT License 5 votes vote down vote up
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
                                    HttpServletResponse response, Authentication authentication)
    throws IOException, ServletException {

    String redirectUrl = "";
    SavedRequest savedRequest = requestCache.getRequest(request, response);
    if (savedRequest != null && StringUtils.isNotEmpty(savedRequest.getRedirectUrl())) {
        redirectUrl = savedRequest.getRedirectUrl();
    }


    // 根据需要设置 cookie,js携带token直接访问api接口等
    if (authentication instanceof OAuth2AuthenticationToken) {
        OAuth2AuthorizedClient client = authorizedClientService
            .loadAuthorizedClient(
                ((OAuth2AuthenticationToken) authentication).getAuthorizedClientRegistrationId(),
                authentication.getName());
        String token = client.getAccessToken().getTokenValue();
        Cookie tokenCookie = new Cookie("access_token", token);
        tokenCookie.setHttpOnly(true);
        tokenCookie.setDomain(cookieDomain);
        tokenCookie.setPath("/");
        response.addCookie(tokenCookie);
    }

    //设置回调成功的页面,
    if (StringUtils.isNotEmpty(redirectUrl)) {
        super.onAuthenticationSuccess(request, response, authentication);
    } else {
        response.sendRedirect("/");
    }

}
 
Example 4
Source File: UploadController.java    From spring-admin-vue with Apache License 2.0 5 votes vote down vote up
/**
 * 删除图片
 *
 * @param url
 * @return java.io.File
 * @throws IOException
 * @author Wang Chen Chen<[email protected]>
 * @date 2019/12/13 23:03
 */
@ApiOperation(value = "图片删除", notes = "根据url 删除图片")
@DeleteMapping("/delete")
public JsonResult deleteImages(String url) throws IOException {
    if (StringUtils.isNotEmpty(url)) {
        String fileKey = url.substring((url.lastIndexOf("/") + 1), url.length());
        log.info("deleteImages url: {}  fileKey: {}", url, fileKey);
        qiniuUtils.delete(fileKey);
    }
    return JsonResult.success();
}
 
Example 5
Source File: ElasticMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new instance with given parameters.
 *
 * @param config configuration to use
 * @param clock clock to use
 * @param threadFactory thread factory to use
 * @param httpClient http client to use
 * @since 1.2.1
 */
protected ElasticMeterRegistry(ElasticConfig config, Clock clock, ThreadFactory threadFactory, HttpSender httpClient) {
    super(config, clock);
    config().namingConvention(new ElasticNamingConvention());
    this.config = config;
    indexDateFormatter = DateTimeFormatter.ofPattern(config.indexDateFormat());
    this.httpClient = httpClient;
    if (StringUtils.isNotEmpty(config.pipeline())) {
        indexLine = "{ \"index\" : {\"pipeline\":\"" + config.pipeline() + "\"} }\n";
    } else {
        indexLine = "{ \"index\" : {} }\n";
    }

    start(threadFactory);
}