Example usage for org.springframework.util Assert hasText

List of usage examples for org.springframework.util Assert hasText

Introduction

In this page you can find the example usage for org.springframework.util Assert hasText.

Prototype

public static void hasText(@Nullable String text, Supplier<String> messageSupplier) 

Source Link

Document

Assert that the given String contains valid text content; that is, it must not be null and must contain at least one non-whitespace character.

Usage

From source file:org.surfnet.oaaas.auth.AuthorizationServerResourceFilter.java

public AuthorizationServerResourceFilter(String resourceServerKey, String resourceServerSecret,
        String authorizationServerUrl, boolean cacheEnabled) {
    this.resourceServerKey = resourceServerKey;
    this.resourceServerSecret = resourceServerSecret;
    this.authorizationServerUrl = authorizationServerUrl;
    this.cacheEnabled = cacheEnabled;

    Assert.hasText(this.resourceServerKey, "Must provide a resource server key");
    Assert.hasText(this.resourceServerSecret, "Must provide a resource server secret");
    Assert.hasText(this.authorizationServerUrl, "Must provide a authorization server url");

    if (this.cacheEnabled) {
        this.cache = this.buildCache();
        Assert.notNull(this.cache);
    }//from www.  j  ava 2 s  .c  o m

    this.authorizationValue = new String(
            Base64.encodeBase64(resourceServerKey.concat(":").concat(resourceServerSecret).getBytes()));

    this.client = createClient();
    this.objectMapper = createObjectMapper();
}

From source file:org.codehaus.groovy.grails.scaffolding.AbstractGrailsTemplateGenerator.java

public void generateViews(GrailsDomainClass domainClass, String destDir) throws IOException {
    Assert.hasText(destDir, "Argument [destdir] not specified");

    File viewsDir = new File(destDir, "grails-app/views/" + domainClass.getPropertyName());
    if (!viewsDir.exists()) {
        viewsDir.mkdirs();// w w w  .  ja v  a  2 s.com
    }

    for (String name : getTemplateNames()) {
        if (log.isInfoEnabled()) {
            log.info("Generating [" + name + "] view for domain class [" + domainClass.getFullName() + "]");
        }
        generateView(domainClass, name, viewsDir.getAbsolutePath());
    }
}

From source file:org.zalando.failsafeactuator.service.CircuitBreakerRegistry.java

/**
 * Returns the {@link CircuitBreaker} for the given name or <code>null</code> if no breaker with that name was registered before.
 *
 * @param name of the CircuitBreaker to get
 * @return the found CircuitBreaker or <code>null</code>
 *///from  w  ww  .ja  va 2s . co  m
CircuitBreaker get(final String name) {
    Assert.hasText(name, "Name for circuitbreaker needs to be set");
    return concurrentBreakerMap.get(name);
}

From source file:com.tealium.publisher.ftp.FtpSessionFactory.java

private T createClient() throws SocketException, IOException {
    final T client = (T) this.createClientInstance();
    Assert.notNull(client, "client must not be null");
    Assert.hasText(this.username, "username is required");

    this.postProcessClientBeforeConnect(client);

    // Connect/*from  www  .ja va2  s.c o  m*/
    try {
        String[] resutls = client.connect(this.host, this.port);
        logger.debug("Connected to server [" + host + ":" + port + "]");

        // Login
        client.login(username, password);

    } catch (IllegalStateException | FTPIllegalReplyException | FTPException e) {
        logger.error("createClient: -" + FtpSession.getError(e), e);
        throw new IOException(FtpSession.getError(e).toString());
    }

    this.postProcessClientAfterConnect(client);

    this.updateClientMode(client);
    client.setType(fileType);
    client.setCharset(controlEncoding);
    if (connParam.get(FTPUtil.ALIVE_AUTO_PING) != null) {
        client.setAutoNoopTimeout(Long.parseLong(connParam.get(FTPUtil.ALIVE_AUTO_PING)));
    }
    client.setCompressionEnabled(isCompressSupported(connParam.get(FTPUtil.FTP_HOST), client));
    return client;
}

From source file:org.zalando.stups.oauth2.spring.server.TokenInfoResourceServerTokenServices.java

public TokenInfoResourceServerTokenServices(final String tokenInfoEndpointUrl, final String clientId,
        final AuthenticationExtractor authenticationExtractor, final RestTemplate restTemplate) {

    Assert.hasText(tokenInfoEndpointUrl, "TokenInfoEndpointUrl should never be null or empty");
    try {/*from   ww  w .  j av  a2 s.  c  om*/
        new URL(tokenInfoEndpointUrl);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("TokenInfoEndpointUrl is not an URL", e);
    }

    Assert.hasText(clientId, "ClientId should never be null or empty");
    Assert.notNull(authenticationExtractor, "AuthenticationExtractor should never be null");
    Assert.notNull(restTemplate, "RestTemplate should not be null");

    this.tokenInfoEndpointUrl = tokenInfoEndpointUrl;
    this.authenticationExtractor = authenticationExtractor;
    this.restTemplate = restTemplate;

    this.clientId = clientId;
}

From source file:io.curly.artifact.service.DefaultArtifactService.java

@Override
@Loggable//from w w w.jav a  2 s .c o  m
@CacheEvict(value = { "artifacts", "singleArtifact" }, key = "#id")
public void delete(String id, User user) {
    Assert.notNull(user, "User must be not null");
    Assert.hasText(id, "Id must be not empty");
    log.debug("Looking for entity with id {}", id);
    Artifact artifact = findOne(id);
    if (artifact != null && (artifact.getOwner().equals(user.getId()))) {
        repository.delete(artifact);
    } else {
        log.error("Cannot process #delete({},{})", id, user.getId());
    }
}

From source file:com.rosy.bill.utils.jmx.JmxClientTemplate.java

/**
 * ???MBean(MBeanClass).//from   w  w w.  j av a2s.c  o m
 * 
 * attributeName?.
 */
public Object getAttribute(final String mbeanName, final String attributeName) {
    Assert.hasText(mbeanName, "mbeanName?");
    Assert.hasText(attributeName, "attributeName?");
    assertConnected();

    try {
        ObjectName objectName = buildObjectName(mbeanName);
        return connection.getAttribute(objectName, attributeName);
    } catch (JMException e) {
        throw new IllegalArgumentException("??", e);
    } catch (IOException e) {
        throw new IllegalStateException("", e);
    }
}

From source file:io.galeb.core.entity.Account.java

@JsonProperty(value = "password", required = true)
public Account setPassword(String password) {
    Assert.hasText(password,
            "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank");
    updateHash();//from   w w w.ja  v a2 s .  co  m
    this.password = ENCODER.encode(password);
    return this;
}

From source file:org.esco.portlet.changeetab.service.impl.CachingEtablissementService.java

@Override
public Etablissement retrieveEtablissementsByCode(final String code) {
    Assert.hasText(code, "No Etablissement code supplied !");

    Etablissement etab = null;// www  . ja v a2  s  .co m

    final String cacheKey = this.genCacheKey(code);
    ValueWrapper cachedValue = null;

    // Aquire read lock to avoid cache unconsistency
    this.cacheRl.lock();
    try {
        cachedValue = this.etablissementCache.get(cacheKey);
    } finally {
        this.cacheRl.unlock();
    }
    if (cachedValue == null) {
        CachingEtablissementService.LOG.warn("No etablissement found in cache for code: [{}] !", code);
    } else {
        etab = (Etablissement) cachedValue.get();
    }

    return etab;
}

From source file:com.bsi.summer.core.util.ReflectionUtils.java

/**
 * ?, ?DeclaredField,   ?filedName//www  .j av a2s.  c om
 * 
 * ?Object?, null.
 */
public static String getAccessibleFieldName(final Object obj, final String fieldName) {
    Assert.notNull(obj, "object?");
    Assert.hasText(fieldName, "fieldName");
    for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass
            .getSuperclass()) {
        Field fields[] = superClass.getDeclaredFields();
        for (Field field : fields) {
            if (field.getName().toUpperCase().equals(fieldName.toUpperCase())) {
                return field.getName();
            }
        }
    }
    return null;
}