List of usage examples for org.springframework.util Assert hasLength
public static void hasLength(@Nullable String text, Supplier<String> messageSupplier)
From source file:org.springframework.boot.devtools.remote.client.ClassPathChangeUploader.java
public ClassPathChangeUploader(String url, ClientHttpRequestFactory requestFactory) { Assert.hasLength(url, "URL must not be empty"); Assert.notNull(requestFactory, "RequestFactory must not be null"); try {/*from w ww .j a v a2 s . c o m*/ this.uri = new URL(url).toURI(); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Malformed URL '" + url + "'"); } catch (MalformedURLException ex) { throw new IllegalArgumentException("Malformed URL '" + url + "'"); } this.requestFactory = requestFactory; }
From source file:org.springframework.boot.devtools.remote.client.DelayedLiveReloadTrigger.java
DelayedLiveReloadTrigger(OptionalLiveReloadServer liveReloadServer, ClientHttpRequestFactory requestFactory, String url) {// w w w.j a v a 2s . c o m Assert.notNull(liveReloadServer, "LiveReloadServer must not be null"); Assert.notNull(requestFactory, "RequestFactory must not be null"); Assert.hasLength(url, "URL must not be empty"); this.liveReloadServer = liveReloadServer; this.requestFactory = requestFactory; try { this.uri = new URI(url); } catch (URISyntaxException ex) { throw new IllegalArgumentException(ex); } }
From source file:org.springframework.boot.devtools.tunnel.client.HttpTunnelConnection.java
/** * Create a new {@link HttpTunnelConnection} instance. * @param url the URL to connect to/* w w w. ja va 2 s. c o m*/ * @param requestFactory the HTTP request factory * @param executor the executor used to handle connections */ protected HttpTunnelConnection(String url, ClientHttpRequestFactory requestFactory, Executor executor) { Assert.hasLength(url, "URL must not be empty"); Assert.notNull(requestFactory, "RequestFactory must not be null"); try { this.uri = new URL(url).toURI(); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Malformed URL '" + url + "'"); } catch (MalformedURLException ex) { throw new IllegalArgumentException("Malformed URL '" + url + "'"); } this.requestFactory = requestFactory; this.executor = (executor == null ? Executors.newCachedThreadPool(new TunnelThreadFactory()) : executor); }
From source file:org.springframework.boot.web.servlet.DynamicRegistrationBean.java
/** * Set the name of this registration. If not specified the bean name will be used. * @param name the name of the registration *//*from ww w . j a v a 2 s . c om*/ public void setName(String name) { Assert.hasLength(name, "Name must not be empty"); this.name = name; }
From source file:org.springframework.context.support.AbstractApplicationContext.java
/** * Set a friendly name for this context. * Typically done during initialization of concrete context implementations. * <p>Default is the object id of the context instance. *///from ww w.ja v a2 s .co m public void setDisplayName(String displayName) { Assert.hasLength(displayName, "Display name must not be empty"); this.displayName = displayName; }
From source file:org.springframework.ldap.test.AbstractEc2InstanceLaunchingFactoryBean.java
@Override protected final Object createInstance() throws Exception { Assert.hasLength(imageName, "ImageName must be set"); Assert.hasLength(awsKey, "AwsKey must be set"); Assert.hasLength(awsSecretKey, "AwsSecretKey must be set"); Assert.hasLength(keypairName, "KeyName must be set"); Assert.hasLength(groupName, "GroupName must be set"); log.info("Launching EC2 instance for image: " + imageName); Jec2 jec2 = new Jec2(awsKey, awsSecretKey); LaunchConfiguration launchConfiguration = new LaunchConfiguration(imageName); launchConfiguration.setKeyName(keypairName); launchConfiguration.setSecurityGroup(Collections.singletonList(groupName)); ReservationDescription reservationDescription = jec2.runInstances(launchConfiguration); instance = reservationDescription.getInstances().get(0); while (!instance.isRunning() && !instance.isTerminated()) { log.info("Instance still starting up; sleeping " + INSTANCE_START_SLEEP_TIME + "ms"); Thread.sleep(INSTANCE_START_SLEEP_TIME); reservationDescription = jec2.describeInstances(Collections.singletonList(instance.getInstanceId())) .get(0);/*from ww w . j ava2 s.c o m*/ instance = reservationDescription.getInstances().get(0); } if (instance.isRunning()) { log.info("EC2 instance is now running"); if (preparationSleepTime > 0) { log.info( "Sleeping " + preparationSleepTime + "ms allowing instance services to start up properly."); Thread.sleep(preparationSleepTime); log.info("Instance prepared - proceeding"); } return doCreateInstance(instance.getDnsName()); } else { throw new IllegalStateException("Failed to start a new instance"); } }
From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java
@SuppressWarnings("deprecation") // on JDK 9 private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IOException, SAXException { if (logger.isDebugEnabled()) { logger.debug("Setting validation schema to " + StringUtils.arrayToCommaDelimitedString(this.schemaResources)); }//w w w .j a v a 2 s . c o m Assert.notEmpty(resources, "No resources given"); Assert.hasLength(schemaLanguage, "No schema language provided"); Source[] schemaSources = new Source[resources.length]; XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); for (int i = 0; i < resources.length; i++) { Assert.notNull(resources[i], "Resource is null"); Assert.isTrue(resources[i].exists(), "Resource " + resources[i] + " does not exist"); InputSource inputSource = SaxResourceUtils.createInputSource(resources[i]); schemaSources[i] = new SAXSource(xmlReader, inputSource); } SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage); if (this.schemaResourceResolver != null) { schemaFactory.setResourceResolver(this.schemaResourceResolver); } return schemaFactory.newSchema(schemaSources); }
From source file:org.springframework.security.authentication.jaas.AbstractJaasAuthenticationProvider.java
/** * Validates the required properties are set. In addition, if * {@link #setCallbackHandlers(JaasAuthenticationCallbackHandler[])} has not been * called with valid handlers, initializes to use {@link JaasNameCallbackHandler} and * {@link JaasPasswordCallbackHandler}./*from w ww. ja va2s.c o m*/ */ public void afterPropertiesSet() throws Exception { Assert.hasLength(this.loginContextName, "loginContextName cannot be null or empty"); Assert.notEmpty(this.authorityGranters, "authorityGranters cannot be null or empty"); if (ObjectUtils.isEmpty(this.callbackHandlers)) { setCallbackHandlers(new JaasAuthenticationCallbackHandler[] { new JaasNameCallbackHandler(), new JaasPasswordCallbackHandler() }); } Assert.notNull(this.loginExceptionResolver, "loginExceptionResolver cannot be null"); }
From source file:org.springframework.security.authentication.jaas.JaasAuthenticationProvider.java
@Override public void afterPropertiesSet() throws Exception { // the superclass is not called because it does additional checks that are // non-passive Assert.hasLength(getLoginContextName(), () -> "loginContextName must be set on " + getClass()); Assert.notNull(this.loginConfig, () -> "loginConfig must be set on " + getClass()); configureJaas(this.loginConfig); Assert.notNull(Configuration.getConfiguration(), "As per https://java.sun.com/j2se/1.5.0/docs/api/javax/security/auth/login/Configuration.html " + "\"If a Configuration object was set via the Configuration.setConfiguration method, then that object is " + "returned. Otherwise, a default Configuration object is returned\". Your JRE returned null to " + "Configuration.getConfiguration()."); }
From source file:org.springframework.security.captcha.CaptchaEntryPoint.java
/** * @throws Exception any ex. */ public void afterPropertiesSet() throws Exception { Assert.hasLength(captchaFormUrl, "captchaFormUrl must be specified"); Assert.hasLength(originalRequestMethodParameterName, "originalRequestMethodParameterName must be specified"); Assert.hasLength(originalRequestParametersNameValueSeparator, "originalRequestParametersNameValueSeparator must be specified"); Assert.hasLength(originalRequestParametersParameterName, "originalRequestParametersParameterName must be specified"); Assert.hasLength(originalRequestParametersSeparator, "originalRequestParametersSeparator must be specified"); Assert.hasLength(originalRequestUrlParameterName, "originalRequestUrlParameterName must be specified"); Assert.hasLength(urlEncodingCharset, "urlEncodingCharset must be specified"); Assert.notNull(portMapper, "portMapper must be specified"); Assert.notNull(portResolver, "portResolver must be specified"); URLEncoder.encode(" fzaef & ", urlEncodingCharset); }