Java Code Examples for org.springframework.util.Assert#hasLength()
The following examples show how to use
org.springframework.util.Assert#hasLength() .
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: ZkDiscoveryService.java From iotplatform with Apache License 2.0 | 6 votes |
@PostConstruct public void init() { log.info("Initializing..."); Assert.hasLength(zkUrl, MiscUtils.missingProperty("zk.url")); Assert.notNull(zkRetryInterval, MiscUtils.missingProperty("zk.retry_interval_ms")); Assert.notNull(zkConnectionTimeout, MiscUtils.missingProperty("zk.connection_timeout_ms")); Assert.notNull(zkSessionTimeout, MiscUtils.missingProperty("zk.session_timeout_ms")); log.info("Initializing discovery service using ZK connect string: {}", zkUrl); zkNodesDir = zkDir + "/nodes"; try { client = CuratorFrameworkFactory.newClient(zkUrl, zkSessionTimeout, zkConnectionTimeout, new RetryForever(zkRetryInterval)); client.start(); client.blockUntilConnected(); cache = new PathChildrenCache(client, zkNodesDir, true); cache.getListenable().addListener(this); cache.start(); } catch (Exception e) { log.error("Failed to connect to ZK: {}", e.getMessage(), e); CloseableUtils.closeQuietly(client); throw new RuntimeException(e); } }
Example 2
Source File: MultipartBodyBuilder.java From spring-analysis-note with MIT License | 6 votes |
/** * Add an asynchronous part with {@link Publisher}-based content. * @param name the name of the part to add * @param publisher a Publisher of content for the part * @param elementClass the type of elements contained in the publisher * @return builder that allows for further customization of part headers */ @SuppressWarnings("unchecked") public <T, P extends Publisher<T>> PartBuilder asyncPart(String name, P publisher, Class<T> elementClass) { Assert.hasLength(name, "'name' must not be empty"); Assert.notNull(publisher, "'publisher' must not be null"); Assert.notNull(elementClass, "'elementClass' must not be null"); if (Part.class.isAssignableFrom(elementClass)) { publisher = (P) Mono.from(publisher).flatMapMany(p -> ((Part) p).content()); elementClass = (Class<T>) DataBuffer.class; } HttpHeaders headers = new HttpHeaders(); PublisherPartBuilder<T, P> builder = new PublisherPartBuilder<>(headers, publisher, elementClass); this.parts.add(name, builder); return builder; }
Example 3
Source File: WechatUserInfoService.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
public WechatUserInfo findByOpenId(String openId) { Assert.hasLength(openId,"openId 为空"); WechatUserInfo wechatUserInfo = new WechatUserInfo(); wechatUserInfo.setOpenid(openId); List<WechatUserInfo> list = this.findList(wechatUserInfo); return list.size() > 0 ? list.get(0):null; }
Example 4
Source File: WechatServiceAPI.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
/** * h5 需要js 的签名参数 * @param url * @return */ public Map<String,Object> getJsConfig(String url){ Assert.hasLength(url,"url 为null"); String noncestr = WxUtils.createNoncestr(); long timestamp = WxUtils.createTimestamp(); String jsapiTicket = getJsApiTicket(); String signature = WxUtils.jsSignature(noncestr, timestamp, jsapiTicket, url); Map<String,Object> config = Maps.newHashMap(); config.put("noncestr", noncestr); config.put("timestamp", timestamp); config.put("signature", signature); config.put("appId", appId); return config; }
Example 5
Source File: AbstractDispatcherServletInitializer.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Register a {@link DispatcherServlet} against the given servlet context. * <p>This method will create a {@code DispatcherServlet} with the name returned by * {@link #getServletName()}, initializing it with the application context returned * from {@link #createServletApplicationContext()}, and mapping it to the patterns * returned from {@link #getServletMappings()}. * <p>Further customization can be achieved by overriding {@link * #customizeRegistration(ServletRegistration.Dynamic)} or * {@link #createDispatcherServlet(WebApplicationContext)}. * @param servletContext the context to register the servlet against */ protected void registerDispatcherServlet(ServletContext servletContext) { String servletName = getServletName(); Assert.hasLength(servletName, "getServletName() must not return empty or null"); WebApplicationContext servletAppContext = createServletApplicationContext(); Assert.notNull(servletAppContext, "createServletApplicationContext() did not return an application " + "context for servlet [" + servletName + "]"); FrameworkServlet dispatcherServlet = createDispatcherServlet(servletAppContext); dispatcherServlet.setContextInitializers(getServletApplicationContextInitializers()); ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, dispatcherServlet); Assert.notNull(registration, "Failed to register servlet with name '" + servletName + "'." + "Check if there is another servlet registered under the same name."); registration.setLoadOnStartup(1); registration.addMapping(getServletMappings()); registration.setAsyncSupported(isAsyncSupported()); Filter[] filters = getServletFilters(); if (!ObjectUtils.isEmpty(filters)) { for (Filter filter : filters) { registerServletFilter(servletContext, filter); } } customizeRegistration(registration); }
Example 6
Source File: AbstractTrie.java From zuul-trie-matcher-spring-cloud-starter with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public T put(String key, T value) { Assert.hasLength(key, "Key must be not null or not empty string."); return put(getRoot(), key, value); }
Example 7
Source File: GenTypeMapping.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
/** * 通过DB 类型获得 java类型 * * @param dbType * @return */ public static String getDbJavaMapping(String dbType) { Assert.hasLength(dbType, "dbType 为空"); String mapping = dbJavaTypeMapping.get(dbType.toLowerCase()); Assert.notNull(mapping, dbType + "无对应mybatis 映射,请补全"); return mapping; }
Example 8
Source File: WechatLoginController.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
@RequestMapping("/auth2Login.do") public void auth2Login(@RequestParam String code,@RequestParam String state,HttpServletResponse response,HttpSession session) throws IOException { String redirectUrl = valueOperations.get(state); Assert.hasLength(redirectUrl,"redirectUrl地址为空"); AuthAccessToken accessToken = wechatUserInfoServiceAPI.getUserInfoByCode(code); FrontUser frontUser = new FrontUser(); WechatUserInfo wechatUserInfo = new WechatUserInfo(); if ("snsapi_base".equals(accessToken.getScope())) {//不需要用户信息 frontUser.setUserId(accessToken.getOpenid()); wechatUserInfo.setOpenid(accessToken.getOpenid()); } else if ("snsapi_userinfo".equals(accessToken.getScope())) { UserInfo userinfo = wechatUserInfoServiceAPI.userinfo(accessToken); frontUser.setUserId(userinfo.getOpenid()); frontUser.setName(userinfo.getNickname()); wechatUserInfo.setOpenid(userinfo.getOpenid()); wechatUserInfo.setNickname(userinfo.getNickname()); wechatUserInfo.setSex(userinfo.getSex()); wechatUserInfo.setProvince(userinfo.getProvince()); wechatUserInfo.setCity(userinfo.getCity()); wechatUserInfo.setCountry(userinfo.getCountry()); wechatUserInfo.setHeadImgUrl(userinfo.getHeadimgurl()); wechatUserInfo.setUnionid(userinfo.getUnionid()); } WechatUserInfo dbWechatUserInfo = wechatUserInfoService.findByOpenId(wechatUserInfo.getOpenid()); if (null == dbWechatUserInfo) { wechatUserInfoService.save(wechatUserInfo); } else { wechatUserInfo.setId(dbWechatUserInfo.getId()); wechatUserInfoService.updateSelective(wechatUserInfo); } FrontSubject.putUserSession(session, frontUser); response.sendRedirect(redirectUrl); }
Example 9
Source File: HierarchicalUriComponents.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Encode the given source into an encoded String using the rules specified * by the given component and with the given options. * @param source the source string * @param encoding the encoding of the source string * @param type the URI component for the source * @return the encoded URI * @throws IllegalArgumentException when the given uri parameter is not a valid URI */ static String encodeUriComponent(String source, String encoding, Type type) throws UnsupportedEncodingException { if (source == null) { return null; } Assert.hasLength(encoding, "Encoding must not be empty"); byte[] bytes = encodeBytes(source.getBytes(encoding), type); return new String(bytes, "US-ASCII"); }
Example 10
Source File: MockPart.java From java-technology-stack with MIT License | 5 votes |
/** * Constructor for a part with a filename and byte[] content. * @see #getHeaders() */ public MockPart(String name, @Nullable String filename, @Nullable byte[] content) { Assert.hasLength(name, "'name' must not be empty"); this.name = name; this.filename = filename; this.content = (content != null ? content : new byte[0]); this.headers.setContentDispositionFormData(name, filename); }
Example 11
Source File: SysRoleService.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
public int removeUsersByRoleId(String roleId,List<String> userIds) { Assert.hasLength(roleId, "roleId 为空"); Assert.notEmpty(userIds,"移除用户为空"); userIds.forEach((userId) -> { this.d.deleteUserRoleByRoleIdAndUserId(roleId, userId); }); return userIds.size(); }
Example 12
Source File: WechatServiceAPI.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
public Map<String,Object> mpay(String body,String out_trade_no,Integer total_fee,String openid,String attach) { Assert.hasLength(openid,"openid 为空"); UnifiedOrder unifiedOrderParams = this.buildUnifiedOrderParams(body, out_trade_no, total_fee, attach, "JSAPI"); unifiedOrderParams.setAppid(mappId); //小程序支付openid 必传 unifiedOrderParams.setOpenid(openid); UnifiedOrderResult unifiedOrder = this.unifiedOrder(unifiedOrderParams); return this.getMPayParams(unifiedOrder.getPrepay_id()); }
Example 13
Source File: HttpCookie.java From java-technology-stack with MIT License | 4 votes |
public HttpCookie(String name, @Nullable String value) { Assert.hasLength(name, "'name' is required and must not be empty."); this.name = name; this.value = (value != null ? value : ""); }
Example 14
Source File: MockHttpServletRequestBuilder.java From java-technology-stack with MIT License | 4 votes |
private static void addToMap(Map<String, Object> map, String name, Object value) { Assert.hasLength(name, "'name' must not be empty"); Assert.notNull(value, "'value' must not be null"); map.put(name, value); }
Example 15
Source File: BasicAuthAsyncInterceptor.java From haven-platform with Apache License 2.0 | 4 votes |
public BasicAuthAsyncInterceptor(String username, String password) { Assert.hasLength(username, "Username must not be empty"); this.username = username; this.password = (password != null ? password : ""); }
Example 16
Source File: JsonHttpUtilTest.java From Dolphin with Apache License 2.0 | 4 votes |
@Test public void testPostOneWithRequestBody() throws Exception { String url = buildUrl("postOneWithRequestBody"); User user = JsonHttpUtil.postOne(url, USER, User.class); Assert.hasLength(user.getName()); }
Example 17
Source File: HttpSessionChallengeRepository.java From webauthn4j-spring-security with Apache License 2.0 | 4 votes |
/** * Sets the {@link HttpSession} attribute name that the {@link Challenge} is stored in * * @param sessionAttributeName the new attribute name to use */ public void setSessionAttributeName(String sessionAttributeName) { Assert.hasLength(sessionAttributeName, "sessionAttributename cannot be null or empty"); this.sessionAttributeName = sessionAttributeName; }
Example 18
Source File: SysUserService.java From seezoon-framework-all with Apache License 2.0 | 4 votes |
public String encryptPwd(String password,String salt) { Assert.hasLength(password,"密码为空"); Assert.hasLength(salt,"盐为空"); return ShiroUtils.sha256(password, salt); }
Example 19
Source File: CassandraZuulRouteStore.java From zuul-route-cassandra-spring-cloud-starter with Apache License 2.0 | 3 votes |
/** * Creates new instance of {@link CassandraZuulRouteStore}. * * @param cassandraOperations the cassandra template * @param keyspace the optional keyspace * @param table the table name * @throws IllegalArgumentException if {@code keyspace} is {@code null} * or {@code table} is {@code null} or empty */ public CassandraZuulRouteStore(CassandraOperations cassandraOperations, String keyspace, String table) { Assert.notNull(cassandraOperations, "Parameter 'cassandraOperations' can not be null."); Assert.hasLength(table, "Parameter 'table' can not be empty."); this.cassandraOperations = cassandraOperations; this.keyspace = keyspace; this.table = table; }
Example 20
Source File: AnnotatedElementUtils.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Get the fully qualified class names of all meta-annotation * types <em>present</em> on the annotation (of the specified * {@code annotationName}) on the supplied {@link AnnotatedElement}. * <p>This method follows <em>get semantics</em> as described in the * {@linkplain AnnotatedElementUtils class-level javadoc}. * @param element the annotated element * @param annotationName the fully qualified class name of the annotation * type on which to find meta-annotations * @return the names of all meta-annotations present on the annotation, * or {@code null} if not found * @see #getMetaAnnotationTypes(AnnotatedElement, Class) * @see #hasMetaAnnotationTypes */ public static Set<String> getMetaAnnotationTypes(AnnotatedElement element, String annotationName) { Assert.notNull(element, "AnnotatedElement must not be null"); Assert.hasLength(annotationName, "'annotationName' must not be null or empty"); return getMetaAnnotationTypes(element, AnnotationUtils.getAnnotation(element, annotationName)); }