/** * Set the log category for warn logging. The name will be passed to the underlying logger * implementation through Commons Logging, getting interpreted as a log category according * to the logger's configuration. If {@code null} is passed, warn logging is turned off. * <p>By default there is no warn logging although sub-classes like * {@link org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver} * can change that default. Specify this setting to activate warn logging into a specific * category. Alternatively, override the {@link #logException} method for custom logging. * @see org.apache.commons.logging.LogFactory#getLog(String) * @see java.util.logging.Logger#getLogger(String) */ public void setWarnLogCategory(String loggerName) { this.warnLogger = !StringUtils.isEmpty(loggerName) ? LogFactory.getLog(loggerName) : null; }
private static String getMethodMapping(Method method) { Assert.notNull(method, "'method' must not be null"); RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class); if (requestMapping == null) { throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString()); } String[] paths = requestMapping.path(); if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) { return "/"; } if (paths.length > 1 && logger.isTraceEnabled()) { logger.trace("Using first of multiple paths on " + method.toGenericString()); } return paths[0]; }
private static URI initUri(HttpServerExchange exchange) throws URISyntaxException { Assert.notNull(exchange, "HttpServerExchange is required."); String requestURL = exchange.getRequestURL(); String query = exchange.getQueryString(); String requestUriAndQuery = StringUtils.isEmpty(query) ? requestURL : requestURL + "?" + query; return new URI(requestUriAndQuery); }
private static String getClassMapping(Class<?> controllerType) { Assert.notNull(controllerType, "'controllerType' must not be null"); RequestMapping mapping = AnnotatedElementUtils.findMergedAnnotation(controllerType, RequestMapping.class); if (mapping == null) { return "/"; } String[] paths = mapping.path(); if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) { return "/"; } if (paths.length > 1 && logger.isTraceEnabled()) { logger.trace("Using first of multiple paths on " + controllerType.getName()); } return paths[0]; }
private boolean verifyAuthCode(String authCode, String telephone){ if(StringUtils.isEmpty(authCode)){ return false; } String realAuthCode = redisService.get(REDIS_KEY_PREFIX_AUTH_CODE + telephone); return authCode.equals(realAuthCode); }
@GetMapping public List<App> findApps(@RequestParam(value = "appIds", required = false) String appIds) { if (StringUtils.isEmpty(appIds)) { return appService.findAll(); } else { return appService.findByAppIds(Sets.newHashSet(appIds.split(","))); } }
/** * Return the set of allowed {@link HttpMethod HTTP methods}, * as specified by the {@code Allow} header. * <p>Returns an empty set when the allowed methods are unspecified. */ public Set<HttpMethod> getAllow() { String value = getFirst(ALLOW); if (!StringUtils.isEmpty(value)) { String[] tokens = StringUtils.tokenizeToStringArray(value, ","); List<HttpMethod> result = new ArrayList<>(tokens.length); for (String token : tokens) { HttpMethod resolved = HttpMethod.resolve(token); if (resolved != null) { result.add(resolved); } } return EnumSet.copyOf(result); } else { return EnumSet.noneOf(HttpMethod.class); } }
/** * Whether the given targetUrl has a host that is a "foreign" system in which * case {@link javax.servlet.http.HttpServletResponse#encodeRedirectURL} will not be applied. * This method returns {@code true} if the {@link #setHosts(String[])} * property is configured and the target URL has a host that does not match. * @param targetUrl the target redirect URL * @return {@code true} the target URL has a remote host, {@code false} if it * the URL does not have a host or the "host" property is not configured. */ protected boolean isRemoteHost(String targetUrl) { if (ObjectUtils.isEmpty(this.hosts)) { return false; } String targetHost = UriComponentsBuilder.fromUriString(targetUrl).build().getHost(); if (StringUtils.isEmpty(targetHost)) { return false; } for (String host : this.hosts) { if (targetHost.equals(host)) { return false; } } return true; }
@Nullable protected final String getCallbackParam(ServerHttpRequest request) { String query = request.getURI().getQuery(); MultiValueMap<String, String> params = UriComponentsBuilder.newInstance().query(query).build().getQueryParams(); String value = params.getFirst("c"); if (StringUtils.isEmpty(value)) { return null; } String result = UriUtils.decode(value, StandardCharsets.UTF_8); return (CALLBACK_PARAM_PATTERN.matcher(result).matches() ? result : null); }
@Override public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) { if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) { return; } PathVariable ann = parameter.getParameterAnnotation(PathVariable.class); String name = (ann != null && !StringUtils.isEmpty(ann.value()) ? ann.value() : parameter.getParameterName()); String formatted = formatUriValue(conversionService, new TypeDescriptor(parameter.nestedIfOptional()), value); uriVariables.put(name, formatted); }
/** * Evaluate the condition and if not null, return it. * If it is null, return the other value. * @param state the expression state * @throws EvaluationException if the condition does not evaluate correctly * to a boolean or there is a problem executing the chosen alternative */ @Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue value = this.children[0].getValueInternal(state); // If this check is changed, the generateCode method will need changing too if (!StringUtils.isEmpty(value.getValue())) { return value; } else { TypedValue result = this.children[1].getValueInternal(state); computeExitTypeDescriptor(); return result; } }
public void handleMessage(TextMessage message, WebSocketSession wsSession) throws Exception { String payload = message.getPayload(); if (StringUtils.isEmpty(payload)) { return; } String[] messages; try { messages = getSockJsServiceConfig().getMessageCodec().decode(payload); } catch (Throwable ex) { logger.error("Broken data received. Terminating WebSocket connection abruptly", ex); tryCloseWithSockJsTransportError(ex, CloseStatus.BAD_DATA); return; } if (messages != null) { delegateMessages(messages); } }
@Override public List<SmsFlashPromotion> list(String keyword, Integer pageSize, Integer pageNum) { PageHelper.startPage(pageNum, pageSize); SmsFlashPromotionExample example = new SmsFlashPromotionExample(); if (!StringUtils.isEmpty(keyword)) { example.createCriteria().andTitleLike("%" + keyword + "%"); } return flashPromotionMapper.selectByExample(example); } }
@Override public List<PmsSkuStock> getList(Long pid, String keyword) { PmsSkuStockExample example = new PmsSkuStockExample(); PmsSkuStockExample.Criteria criteria = example.createCriteria().andProductIdEqualTo(pid); if (!StringUtils.isEmpty(keyword)) { criteria.andSkuCodeLike("%" + keyword + "%"); } return skuStockMapper.selectByExample(example); }
@Override public List<CmsSubject> list(String keyword, Integer pageNum, Integer pageSize) { PageHelper.startPage(pageNum, pageSize); CmsSubjectExample example = new CmsSubjectExample(); CmsSubjectExample.Criteria criteria = example.createCriteria(); if (!StringUtils.isEmpty(keyword)) { criteria.andTitleLike("%" + keyword + "%"); } return subjectMapper.selectByExample(example); } }
@Override public List<PmsBrand> listBrand(String keyword, int pageNum, int pageSize) { PageHelper.startPage(pageNum, pageSize); PmsBrandExample pmsBrandExample = new PmsBrandExample(); pmsBrandExample.setOrderByClause("sort desc"); PmsBrandExample.Criteria criteria = pmsBrandExample.createCriteria(); if (!StringUtils.isEmpty(keyword)) { criteria.andNameLike("%" + keyword + "%"); } return brandMapper.selectByExample(pmsBrandExample); }
private UriComponentsBuilder initUriComponentsBuilder(String uriTemplate) { UriComponentsBuilder result; if (StringUtils.isEmpty(uriTemplate)) { result = baseUri != null ? baseUri.cloneBuilder() : UriComponentsBuilder.newInstance(); } else if (baseUri != null) { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uriTemplate); UriComponents uri = builder.build(); result = uri.getHost() == null ? baseUri.cloneBuilder().uriComponents(uri) : builder; } else { result = UriComponentsBuilder.fromUriString(uriTemplate); } if (encodingMode.equals(EncodingMode.TEMPLATE_AND_VALUES)) { result.encode(); } parsePathIfNecessary(result); return result; }
@Override public List<PmsProduct> list(String keyword) { PmsProductExample productExample = new PmsProductExample(); PmsProductExample.Criteria criteria = productExample.createCriteria(); criteria.andDeleteStatusEqualTo(0); if(!StringUtils.isEmpty(keyword)){ criteria.andNameLike("%" + keyword + "%"); productExample.or().andDeleteStatusEqualTo(0).andProductSnLike("%" + keyword + "%"); } return productMapper.selectByExample(productExample); }
protected String getServiceBaseUrl() { String baseUrl = instance.getServiceBaseUrl(); if (!StringUtils.isEmpty(baseUrl)) { return baseUrl; } return UriComponentsBuilder.newInstance() .scheme(getScheme(server.getSsl())) .host(getServiceHost()) .port(getLocalServerPort()) .toUriString(); }
@Test // SPR-11970 public void fromUriStringNoPathWithReservedCharInQuery() { UriComponents result = UriComponentsBuilder.fromUriString("http://example.com?foo=bar@baz").build(); assertTrue(StringUtils.isEmpty(result.getUserInfo())); assertEquals("example.com", result.getHost()); assertTrue(result.getQueryParams().containsKey("foo")); assertEquals("bar@baz", result.getQueryParams().getFirst("foo")); }