Java Code Examples for org.springframework.util.Assert#hasLength()

The following examples show how to use org.springframework.util.Assert#hasLength() . These examples are extracted from open source projects. 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
 * 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
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);, builder);
	return builder;

Example 2
Source Project: iotplatform   File:    License: Apache License 2.0 6 votes vote down vote up
public void init() {"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"));"Initializing discovery service using ZK connect string: {}", zkUrl);

  zkNodesDir = zkDir + "/nodes";
  try {
    client = CuratorFrameworkFactory.newClient(zkUrl, zkSessionTimeout, zkConnectionTimeout,
        new RetryForever(zkRetryInterval));
    cache = new PathChildrenCache(client, zkNodesDir, true);
  } catch (Exception e) {
    log.error("Failed to connect to ZK: {}", e.getMessage(), e);
    throw new RuntimeException(e);
Example 3
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");
	//小程序支付openid 必传
	UnifiedOrderResult unifiedOrder = this.unifiedOrder(unifiedOrderParams);
	return this.getMPayParams(unifiedOrder.getPrepay_id());
Example 4
public int removeUsersByRoleId(String roleId,List<String> userIds) {
	Assert.hasLength(roleId, "roleId 为空");
	userIds.forEach((userId) -> {
		this.d.deleteUserRoleByRoleIdAndUserId(roleId, userId);
	return userIds.size();
Example 5
Source Project: java-technology-stack   File:    License: MIT License 5 votes vote down vote up
 * 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"); = name;
	this.filename = filename;
	this.content = (content != null ? content : new byte[0]);
	this.headers.setContentDispositionFormData(name, filename);
Example 6
 * 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 7
public WechatUserInfo findByOpenId(String openId) {
	Assert.hasLength(openId,"openId 为空");
	WechatUserInfo wechatUserInfo = new WechatUserInfo();
	List<WechatUserInfo> list = this.findList(wechatUserInfo);
	return list.size() > 0 ? list.get(0):null;
Example 8
public void auth2Login(@RequestParam String code,@RequestParam String state,HttpServletResponse response,HttpSession session) throws IOException {
	String redirectUrl = valueOperations.get(state);
	AuthAccessToken accessToken = wechatUserInfoServiceAPI.getUserInfoByCode(code);
	FrontUser frontUser = new FrontUser();
	WechatUserInfo wechatUserInfo = new WechatUserInfo();
	if ("snsapi_base".equals(accessToken.getScope())) {//不需要用户信息
	} else if ("snsapi_userinfo".equals(accessToken.getScope())) {
		UserInfo userinfo = wechatUserInfoServiceAPI.userinfo(accessToken);
	WechatUserInfo dbWechatUserInfo = wechatUserInfoService.findByOpenId(wechatUserInfo.getOpenid());
	if (null == dbWechatUserInfo) {;
	} else {
	FrontSubject.putUserSession(session, frontUser);
Example 9
 * 通过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 10
 * {@inheritDoc}
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 11
 * 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();
			"createServletApplicationContext() did not return an application " +
			"context for servlet [" + servletName + "]");

	FrameworkServlet dispatcherServlet = createDispatcherServlet(servletAppContext);

	ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, dispatcherServlet);
			"Failed to register servlet with name '" + servletName + "'." +
			"Check if there is another servlet registered under the same name.");


	Filter[] filters = getServletFilters();
	if (!ObjectUtils.isEmpty(filters)) {
		for (Filter filter : filters) {
			registerServletFilter(servletContext, filter);

Example 12
 * 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 13
Source Project: java-technology-stack   File:    License: MIT License 4 votes vote down vote up
public HttpCookie(String name, @Nullable String value) {
	Assert.hasLength(name, "'name' is required and must not be empty."); = name;
	this.value = (value != null ? value : "");
Example 14
Source Project: Dolphin   File:    License: Apache License 2.0 4 votes vote down vote up
public void testPostOneWithRequestBody() throws Exception {
    String url = buildUrl("postOneWithRequestBody");
    User user = JsonHttpUtil.postOne(url, USER, User.class);
Example 15
public BasicAuthAsyncInterceptor(String username, String password) {
    Assert.hasLength(username, "Username must not be empty");
    this.username = username;
    this.password = (password != null ? password : "");
Example 16
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 17
 * 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) {
            "sessionAttributename cannot be null or empty");
    this.sessionAttributeName = sessionAttributeName;
Example 18
public String encryptPwd(String password,String salt) {
	return ShiroUtils.sha256(password, salt);
Example 19
 * 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
 * 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));