Example usage for org.springframework.util StringUtils isEmpty

List of usage examples for org.springframework.util StringUtils isEmpty

Introduction

In this page you can find the example usage for org.springframework.util StringUtils isEmpty.

Prototype

public static boolean isEmpty(@Nullable Object str) 

Source Link

Document

Check whether the given object (possibly a String ) is empty.

Usage

From source file:com.vcredit.lrh.microservice.gateway.api.redis.SecurityHandlerRedis.java

public void process(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException {
    HttpServletResponse httpServletResponse = (HttpServletResponse) response;
    HttpServletRequest servletRequest = (HttpServletRequest) request;
    String token = "";
    String clientVersion = "";
    String deviceType = "";
    //header??/*www .  ja  v  a2s.c  o  m*/
    String base64Str = servletRequest.getHeader("clientHeader");
    if (!StringUtils.isEmpty(base64Str)) {
        String headerJsonStr = Base64Utils.getFromBase64(base64Str);
        JSONObject headerJson = JSONObject.parseObject(headerJsonStr);
        token = headerJson.getString("accessToken");
        try {
            clientVersion = headerJson.getString("apiClientVersion");
            deviceType = headerJson.getString("deviceType");
            //add by xuhui 20170406
            if (!StringUtils.isEmpty(clientVersion)) {
                if ("iOS".equals(deviceType) && iosAppVertion.compareTo(clientVersion) > 0) {
                    JSONObject jSONObject = new JSONObject();
                    PrintWriter pw = httpServletResponse.getWriter();
                    jSONObject.put("type", LrhConstants.ErrorCodeTypeEnum.FORCEUPDATE.getCode());
                    jSONObject.put("success", true);
                    jSONObject.put("code", 201);
                    Map<String, Object> map = new HashMap();
                    //?
                    map.put("updateUrl", "");
                    map.put("updateInfo", "");
                    map.put("updateTargetVersion", iosAppVertion);
                    map.put("forceUpdate", true);
                    map.put("appType", "iOS");
                    jSONObject.put("data", map);
                    pw.write(jSONObject.toJSONString());
                    pw.flush();
                }
                if ("android".equals(deviceType) && andriodAppVersion.compareTo(clientVersion) > 0) {
                    JSONObject jSONObject = new JSONObject();
                    PrintWriter pw = httpServletResponse.getWriter();
                    jSONObject.put("type", LrhConstants.ErrorCodeTypeEnum.FORCEUPDATE.getCode());
                    jSONObject.put("success", true);
                    jSONObject.put("code", 201);
                    Map<String, Object> map = new HashMap();
                    //?
                    map.put("updateUrl",
                            "http://10.154.40.42:7777/lrh_apk_android_20_v0.0.1/vcredit_lrh_debug_v0.0.2_2017_0421_1041_Vcredit_TecentQQ.apk");
                    map.put("updateInfo", "");
                    map.put("updateTargetVersion", andriodAppVersion);
                    map.put("forceUpdate", true);
                    map.put("appType", "android");
                    jSONObject.put("data", map);
                    pw.write(jSONObject.toJSONString());
                    pw.flush();
                }
            }
        } catch (Exception e) {
        }
    }

    //        String token = request.getParameter("accessToken") == null ? accessTokenFromHeader : request.getParameter("accessToken");
    if (StringUtils.isEmpty(token)) {
        token = servletRequest.getSession().getId().toUpperCase();
    }
    String openId = request.getParameter("open_id");
    httpServletResponse.setHeader("Content-Type", "application/json");
    try {
        if (servletRequest.getServletPath().equals(securityProperties.getLoginSecurityUrl())) {
            chain.doFilter(request, response);
        } else if (servletRequest.getServletPath().equals("/favicon.ico")) {
            chain.doFilter(request, response);
            //                PrintWriter pw = httpServletResponse.getWriter();
            //                pw.write("favicon.ico");
            //                pw.flush();
        } else if (openId == null && null == token) {
            unauthorizedRequest(httpServletResponse);
        } else if (needAuthentication(servletRequest.getServletPath())) {
            //                JSONObject currentUser = securityService.getUserByAccessToken(token);
            JSONObject currentUser = redisTemplate.get(RedisCacheKeys.ACCOUNT_CACHE_TOKEN + token,
                    JSONObject.class);
            if (null == currentUser) {
                unauthorizedRequest(httpServletResponse);
            } else {
                chain.doFilter(request, response);
            }
        } else {
            chain.doFilter(request, response);
        }
    } catch (ServletException ex) {
        logger.error(ex.getMessage(), ex);
        serverErrorRequest(httpServletResponse);
    }
}

From source file:org.carewebframework.shell.layout.UIElementLayout.java

public UILayout getLayout() throws Exception {
    if (layout == null) {
        layout = new UILayout();
        String xml = LayoutUtil.getLayoutContent(new LayoutIdentifier(layoutName, shared));

        if (StringUtils.isEmpty(xml)) {
            raise("Unknown layout: " + layoutName);
        }//from w  ww .  j av  a2 s.  co  m

        layout.loadFromText(xml);
    }

    return layout;
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.ws.controller.TaxonomyController.java

/**
 * Endpoint: search for InformationAssetViews in lucene index using a
 * category query and other parameters//  w w w  . java2 s . co m
 * 
 * @param searchRequest
 * @return paginated list of found information asset views
 * @throws Exception
 */
@RequestMapping(value = "/search", method = RequestMethod.POST, consumes = APPLICATION_JSON, produces = APPLICATION_JSON)
@ResponseBody
PaginatedList<InformationAssetView> searchIAView(@RequestBody SearchIAViewRequest searchRequest)
        throws Exception {

    logger.info("/search > {}", searchRequest.toString());

    if (StringUtils.isEmpty(searchRequest.getCategoryQuery())) {
        throw new TaxonomyException(TaxonomyErrorType.INVALID_CATEGORY_QUERY,
                "categoryQuery should be provided and not empty");
    }
    if (searchRequest.getLimit() == null) {
        searchRequest.setLimit(10);
    }
    if (searchRequest.getOffset() == null) {
        searchRequest.setOffset(0);
    }

    PaginatedList<InformationAssetView> listOfIAViews = iaViewService.performSearch(
            searchRequest.getCategoryQuery(), searchRequest.getScore(), searchRequest.getLimit(),
            searchRequest.getOffset());

    logger.info("/search < {} IAViews returned, {} IAViews found", listOfIAViews.size(),
            listOfIAViews.getNumberOfResults());
    if (!CollectionUtils.isEmpty(listOfIAViews.getResults())) {
        logger.info("/search < first element: {}", listOfIAViews.getResults().get(0).toString());
    }

    return listOfIAViews;
}

From source file:cn.guoyukun.spring.jpa.plugin.web.controller.BaseTreeableController.java

/**
 * ???sys:user/*from  w w  w.ja va2  s .c  o  m*/
 * ??? sys:user:create
 */
public void setResourceIdentity(String resourceIdentity) {
    if (!StringUtils.isEmpty(resourceIdentity)) {
        permissionList = PermissionList.newPermissionList(resourceIdentity);
    }
}

From source file:org.ensembl.gti.seqstore.GeneHashTest.java

@Test
public void testLocationToString() {

    String locG = SeqStoreHashUtils.locationToString(gene);
    String locTr = SeqStoreHashUtils.locationToString(gene.getTranscripts().get(0));
    String locE = SeqStoreHashUtils.locationToString(gene.getTranscripts().get(0).getExons().get(0));

    assertFalse("locG is empty or null", StringUtils.isEmpty(locG));
    assertFalse("locTr is empty or null", StringUtils.isEmpty(locTr));
    assertFalse("locE is empty or null", StringUtils.isEmpty(locE));

    String locG2 = SeqStoreHashUtils.locationToString(gene2);
    String locTr2 = SeqStoreHashUtils.locationToString(gene2.getTranscripts().get(0));
    String locE2 = SeqStoreHashUtils.locationToString(gene2.getTranscripts().get(0).getExons().get(0));

    assertEquals("Gene models not equal", locG, locG2);
    assertEquals("Transcript models not equal", locTr, locTr2);
    assertEquals("Exon models not equal", locE, locE2);

}

From source file:com.graphaware.importer.domain.Neo4jPropertyContainer.java

private synchronized void initializeForClass(Class<?> clazz) {
    if (CACHE.containsKey(clazz.getCanonicalName())) {
        return;/*from w  w w.  j  av a2  s  .co  m*/
    }

    Set<Pair<Field, String>> fieldsAndNames = new HashSet<>();

    for (Field field : ReflectionUtils.getAllFields(clazz)) {
        Neo4jProperty annotation = field.getAnnotation(Neo4jProperty.class);
        if (annotation == null) {
            continue;
        }

        String fieldName = StringUtils.isEmpty(annotation.name()) ? field.getName() : annotation.name();
        fieldsAndNames.add(new Pair<>(field, fieldName));
        field.setAccessible(true);
    }

    CACHE.put(clazz.getCanonicalName(), fieldsAndNames);
}

From source file:asia.gkc.vneedu.authorization.interceptor.AuthorizationInterceptor.java

/**
 * This implementation always returns {@code true}.
 *
 * @param request/*from  w  ww.j  a va 2s .  c  o m*/
 * @param response
 * @param handler
 */
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    // ?
    if (!(handler instanceof HandlerMethod)) {
        return true;
    }

    HandlerMethod handlerMethod = (HandlerMethod) handler;
    Method method = handlerMethod.getMethod();

    // ???
    if (method.getAnnotation(RequireLogin.class) == null) {
        return true;
    }

    // ??
    String authorization = request.getHeader(Constants.AUTHORIZATION);

    // ?
    if (authorization == null) {
        return exitWithHeaderError(response);
    }

    String[] auths = authorization.split(" ");
    if (!auths[0].equals("token") || (auths.length > 1 && StringUtils.isEmpty(auths[1]))) {
        return exitWithHeaderError(response);
    }

    // ?Token
    try {
        logger.debug(auths[1]);
        String uuid = IdentityUtil.verifyToken(auths[1]);
        logger.debug(uuid);

        request.setAttribute(Constants.USER_ID_IN_REQUEST, uuid);
    } catch (ExpiredJwtException e) {
        return exitWithExpiredAuth(response);
    } catch (Exception e) {
        return exitWithTokenError(response);
    }

    return true;
}

From source file:de.codecentric.boot.admin.zuul.ApplicationRouteLocator.java

protected List<Route> locateRoutes() {
    Collection<Application> applications = registry.getApplications();

    List<Route> locateRoutes = new ArrayList<>(applications.size() * (endpoints.length + 1));

    for (Application application : applications) {
        addRoute(locateRoutes, application.getId(), "health", application.getHealthUrl());

        if (!StringUtils.isEmpty(application.getManagementUrl())) {
            for (String endpoint : endpoints) {
                addRoute(locateRoutes, application.getId(), endpoint,
                        application.getManagementUrl() + "/" + endpoint);
            }//from  w  ww.  j  a va2s  . c  o m
        }
    }

    return locateRoutes;
}

From source file:com.luna.common.repository.support.SimpleBaseRepositoryFactoryBean.java

protected Object getTargetRepository(RepositoryMetadata metadata) {
    Class<?> repositoryInterface = metadata.getRepositoryInterface();

    if (isBaseRepository(repositoryInterface)) {

        JpaEntityInformation<M, ID> entityInformation = getEntityInformation(
                (Class<M>) metadata.getDomainType());
        SimpleBaseRepository repository = new SimpleBaseRepository<M, ID>(entityInformation, entityManager);

        SearchableQuery searchableQuery = AnnotationUtils.findAnnotation(repositoryInterface,
                SearchableQuery.class);
        if (searchableQuery != null) {
            String countAllQL = searchableQuery.countAllQuery();
            if (!StringUtils.isEmpty(countAllQL)) {
                repository.setCountAllQL(countAllQL);
            }/*w  w  w  . j av a  2s. c o m*/
            String findAllQL = searchableQuery.findAllQuery();
            if (!StringUtils.isEmpty(findAllQL)) {
                repository.setFindAllQL(findAllQL);
            }
            Class<? extends SearchCallback> callbackClass = searchableQuery.callbackClass();
            if (callbackClass != null && callbackClass != SearchCallback.class) {
                repository.setSearchCallback(BeanUtils.instantiate(callbackClass));
            }

            repository.setJoins(searchableQuery.joins());

        }

        return repository;
    }
    return super.getTargetRepository(metadata);
}

From source file:de.codecentric.boot.admin.config.SpringBootAdminClientEnabledCondition.java

private boolean isUrlEmpty(Environment env) {
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(env, "spring.boot.admin.");
    return StringUtils.isEmpty(resolver.getProperty("url", ""));
}