List of usage examples for org.springframework.util Assert state
public static void state(boolean expression, Supplier<String> messageSupplier)
From source file:org.opencredo.couchdb.core.CouchDbDocumentTemplate.java
public void writeDocument(String id, Object document, MessageHeaders headers, Counter counter) throws CouchDbOperationException { Assert.state(defaultDocumentUrl != null, "defaultDatabaseUrl must be set to use this method"); HttpEntity<?> httpEntity = createHttpEntity(document); try {//from w ww . ja v a2 s . com if (headers != null) { HashMap<String, Object> copiedHeaders = new HashMap<String, Object>(headers); if (StringUtils.hasLength(id)) { copiedHeaders.put(MessageHeaders.ID, id); } restOperations.put(defaultDocumentUrl, httpEntity, copiedHeaders); } else { restOperations.put(defaultDocumentUrl, httpEntity, id); } } catch (RestClientException e) { throw new CouchDbOperationException(document, counter, "Unable to communicate with CouchDB", e); } }
From source file:sample.GemFireClientServerReadyBeanPostProcessor.java
private void validateCacheClientNotified() throws InterruptedException { boolean didNotTimeout = LATCH.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); Assert.state(didNotTimeout, String.format("GemFire Cache Server failed to start on host [%s] and port [%d]", this.host, this.port)); }
From source file:org.opennms.ng.services.capsdconfig.CapsdConfigFactory.java
/** * Return the singleton instance of this factory. * * @return The current factory instance. * @throws IllegalStateException/*from w w w .j a va 2 s . co m*/ * Thrown if the factory has not yet been initialized. */ public static synchronized CapsdConfig getInstance() { Assert.state(isLoaded(), "The factory has not been initialized"); return s_singleton; }
From source file:org.cloudfoundry.tools.timeout.HotSwappingTimeoutProtectionStrategy.java
public HttpServletResponseMonitorFactory handleRequest(final TimeoutProtectionHttpRequest request) { final long startTime = System.currentTimeMillis(); return new HttpServletResponseMonitorFactory() { public HttpServletResponseMonitor getMonitor() { if ((HotSwappingTimeoutProtectionStrategy.this.threshold != 0) && (System.currentTimeMillis() - startTime < HotSwappingTimeoutProtectionStrategy.this.threshold)) { return null; }/*from w w w . j a v a 2 s . c o m*/ RequestCoordinator requestCoordinator = HotSwappingTimeoutProtectionStrategy.this.requestCoordinators .get(request); HttpServletResponse pollResponse; synchronized (requestCoordinator) { pollResponse = requestCoordinator.consumePollResponse(); } if (pollResponse == null) { try { requestCoordinator.awaitPollResponse(HotSwappingTimeoutProtectionStrategy.this.failTimeout); } catch (InterruptedException e) { throw new IllegalStateException("Timeout waiting for poll", e); } pollResponse = requestCoordinator.consumePollResponse(); Assert.state(pollResponse != null, "Unable to consume poll response"); } return new DuplicatingHttpServletResponseMonitorFactory(pollResponse).getMonitor(); } }; }
From source file:com.ggk.hrms.authentication.CustomTokenServices.java
@Override public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException, InvalidTokenException { Map<String, Object> checkTokenResponse = checkToken(accessToken); if (checkTokenResponse.containsKey("error")) { logger.debug("check_token returned error: " + checkTokenResponse.get("error")); throw new InvalidTokenException(accessToken); }/*from w ww . j ava2s . c o m*/ transformNonStandardValuesToStandardValues(checkTokenResponse); Assert.state(checkTokenResponse.containsKey("client_id"), "Client id must be present in response from auth server"); return tokenConverter.extractAuthentication(checkTokenResponse); }
From source file:com.apporiented.spring.override.GenericBeanDefinitionParser.java
/** * Parse the supplied {@link org.w3c.dom.Element} and populate the supplied * {@link org.springframework.beans.factory.support.BeanDefinitionBuilder} as required. * <p>This implementation maps any attributes present on the * supplied element to {@link org.springframework.beans.PropertyValue} * instances, and// w w w .j a va 2s . c o m * {@link org.springframework.beans.factory.support.BeanDefinitionBuilder#addPropertyValue(String, Object) adds them} * to the * {@link org.springframework.beans.factory.config.BeanDefinition builder}. * <p>The {@link #extractPropertyName(String)} method is used to * reconcile the name of an attribute with the name of a JavaBean * property. * @param element the XML element being parsed * @param parserContext the object encapsulating the current state of the parsing process * @param builder used to define the <code>BeanDefinition</code> * @see #extractPropertyName(String) */ protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); String name = attribute.getLocalName(); if (isEligibleAttribute(name, parserContext)) { String propertyName = extractPropertyName(name); Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); Object value; if (references.contains(propertyName)) { value = new RuntimeBeanReference(attribute.getValue()); } else { value = attribute.getValue(); } builder.addPropertyValue(propertyName, value); } } postProcess(builder, parserContext, element); }
From source file:org.spring.data.gemfire.app.dao.provider.JdbcUserDao.java
protected DataSource getDataSource() { Assert.state(userDataSource != null, "A reference to the User DataSource was not properly configured!"); return userDataSource; }
From source file:es.fcs.batch.integration.chunk.GenericChunkProcessorChunkHandler.java
/** * @param chunkRequest the current request * @param stepContribution the step contribution to update * @throws Exception if there is a fatal exception */// w w w . ja va 2 s.c o m private Throwable process(MyChunkRequest<S> chunkRequest, StepContribution stepContribution) throws Exception { ChunkProcessor<S> chunkProcessor = chunkRequest.getChunkProcessor(); logger.debug("ChunkProcessor=" + chunkProcessor.getClass()); Assert.state(chunkProcessor instanceof ChunkProcessor<?>, chunkProcessor.getClass() + "must be a ChunkProcessor"); Chunk<S> chunk = new Chunk<S>(chunkRequest.getItems()); Throwable failure = null; try { chunkProcessor.process(stepContribution, chunk); } catch (SkipLimitExceededException e) { failure = e; } catch (NonSkippableReadException e) { failure = e; } catch (SkipListenerFailedException e) { failure = e; } catch (RetryException e) { failure = e; } catch (JobInterruptedException e) { failure = e; } catch (Exception e) { if (chunkProcessor instanceof FaultTolerantChunkProcessor<?, ?>) { // try again... throw e; } else { failure = e; } } return failure; }
From source file:com.dianwoba.redcliff.blink.config.MybatisConfig.java
@PostConstruct public void checkConfigFileExists() { if (this.properties.isCheckConfigLocation() && StringUtils.hasText(this.properties.getConfigLocation())) { Resource resource = this.resourceLoader.getResource(this.properties.getConfigLocation()); Assert.state(resource.exists(), "Cannot find config location: " + resource + " (please add config file or check your Mybatis " + "configuration)"); }/*from ww w . java 2s. c om*/ }
From source file:org.jasig.jpa.OpenEntityManagerAspect.java
/** * Obtain the transactional EntityManager for this accessor's EntityManagerFactory, if any. * @return the transactional EntityManager, or <code>null</code> if none * @throws IllegalStateException if this accessor is not configured with an EntityManagerFactory * @see EntityManagerFactoryUtils#getTransactionalEntityManager(javax.persistence.EntityManagerFactory) * @see EntityManagerFactoryUtils#getTransactionalEntityManager(javax.persistence.EntityManagerFactory, java.util.Map) *//* w ww. j a va 2s.com*/ protected EntityManager getTransactionalEntityManager(EntityManagerFactory emf) throws IllegalStateException { Assert.state(emf != null, "No EntityManagerFactory specified"); return EntityManagerFactoryUtils.getTransactionalEntityManager(emf); }