[spring-extensions] branch master updated: Null-related corrections, tweaks, and cleanup.
Scott Cantor
cantor.2 at osu.edu
Wed Oct 24 15:43:58 EDT 2018
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository spring-extensions.
View the commit online:
http://git.shibboleth.net/view/?p=spring-extensions.git;a=commit;h=cc82d05b20573285710ff2a3cc188b26a7c9d214
The following commit(s) were added to refs/heads/master by this push:
new cc82d05 Null-related corrections, tweaks, and cleanup.
cc82d05 is described below
commit cc82d05b20573285710ff2a3cc188b26a7c9d214
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Oct 24 15:43:49 2018 -0400
Null-related corrections, tweaks, and cleanup.
Includes an apparent Spring 5 fix to HTTPResource test.
---
...ceholderFileSystemXmlWebApplicationContext.java | 3 +--
.../FileSystemXmlWebApplicationContext.java | 4 +---
.../ext/spring/factory/DOMDocumentFactoryBean.java | 28 ++++++++++++----------
.../ext/spring/resource/ConditionalResource.java | 9 ++++---
.../spring/resource/FileBackedHTTPResource.java | 5 ++--
.../ext/spring/resource/HTTPResource.java | 4 ++--
.../ext/spring/resource/ResourceHelper.java | 26 ++++++++++----------
.../resource/RunnableFileSystemResource.java | 5 ++--
.../ApplicationContextServiceableComponent.java | 3 +--
.../spring/service/ReloadableSpringService.java | 10 ++++----
.../ext/spring/velocity/SpringResourceLoader.java | 8 +++----
.../ext/spring/velocity/VelocityConfig.java | 4 +---
.../ext/spring/velocity/VelocityConfigurer.java | 4 +---
.../ext/spring/velocity/VelocityView.java | 14 +++++------
.../ext/spring/resource/HTTPResourceTest.java | 7 ++++--
15 files changed, 67 insertions(+), 67 deletions(-)
diff --git a/src/main/java/net/shibboleth/ext/spring/context/DeferPlaceholderFileSystemXmlWebApplicationContext.java b/src/main/java/net/shibboleth/ext/spring/context/DeferPlaceholderFileSystemXmlWebApplicationContext.java
index f4dd82d..326d101 100644
--- a/src/main/java/net/shibboleth/ext/spring/context/DeferPlaceholderFileSystemXmlWebApplicationContext.java
+++ b/src/main/java/net/shibboleth/ext/spring/context/DeferPlaceholderFileSystemXmlWebApplicationContext.java
@@ -17,7 +17,6 @@
package net.shibboleth.ext.spring.context;
-import javax.annotation.Nonnull;
/**
* An extension of {@link FileSystemXmlWebApplicationContext} that defers property placeholder resolution of config
@@ -27,7 +26,7 @@ import javax.annotation.Nonnull;
public class DeferPlaceholderFileSystemXmlWebApplicationContext extends FileSystemXmlWebApplicationContext {
/** Whether property sources have been initialized. */
- @Nonnull private boolean propertySourcesInitialized;
+ private boolean propertySourcesInitialized;
/** Constructor. */
public DeferPlaceholderFileSystemXmlWebApplicationContext() {
diff --git a/src/main/java/net/shibboleth/ext/spring/context/FileSystemXmlWebApplicationContext.java b/src/main/java/net/shibboleth/ext/spring/context/FileSystemXmlWebApplicationContext.java
index fb6de2a..1ee4104 100644
--- a/src/main/java/net/shibboleth/ext/spring/context/FileSystemXmlWebApplicationContext.java
+++ b/src/main/java/net/shibboleth/ext/spring/context/FileSystemXmlWebApplicationContext.java
@@ -17,8 +17,6 @@
package net.shibboleth.ext.spring.context;
-import javax.annotation.Nonnull;
-
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
@@ -66,7 +64,7 @@ public class FileSystemXmlWebApplicationContext extends XmlWebApplicationContext
* Supports wildcard classpath locations prefixed with {@link ResourcePatternResolver#CLASSPATH_ALL_URL_PREFIX}.
* </p>
*/
- @Override public Resource getResource(@Nonnull final String location) {
+ @Override public Resource getResource(final String location) {
Constraint.isNotNull(location, "Location must not be null");
if (location.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX)) {
return new ClassPathResource(location.substring(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX.length()),
diff --git a/src/main/java/net/shibboleth/ext/spring/factory/DOMDocumentFactoryBean.java b/src/main/java/net/shibboleth/ext/spring/factory/DOMDocumentFactoryBean.java
index 55fece8..f8e94ee 100644
--- a/src/main/java/net/shibboleth/ext/spring/factory/DOMDocumentFactoryBean.java
+++ b/src/main/java/net/shibboleth/ext/spring/factory/DOMDocumentFactoryBean.java
@@ -62,21 +62,23 @@ public class DOMDocumentFactoryBean implements FactoryBean<Document> {
/** {@inheritDoc} */
@Override @Nonnull public synchronized Document getObject() throws Exception {
- if (document == null) {
- if (resource == null){
- throw new BeanCreationException("Document resource must be provided in order to use this factory.");
- }
-
- if (parserPool == null){
- throw new BeanCreationException("ParserPool must be provided in order to use this factory.");
- }
-
- try (InputStream is = resource.getInputStream()) {
- document = parserPool.parse(is);
- }
+
+ if (document != null) {
+ return document;
+ }
+
+ if (resource == null){
+ throw new BeanCreationException("Document resource must be provided in order to use this factory.");
}
- return document;
+ if (parserPool == null){
+ throw new BeanCreationException("ParserPool must be provided in order to use this factory.");
+ }
+
+ try (InputStream is = resource.getInputStream()) {
+ document = parserPool.parse(is);
+ return document;
+ }
}
/** {@inheritDoc} */
diff --git a/src/main/java/net/shibboleth/ext/spring/resource/ConditionalResource.java b/src/main/java/net/shibboleth/ext/spring/resource/ConditionalResource.java
index 371b037..0420af2 100644
--- a/src/main/java/net/shibboleth/ext/spring/resource/ConditionalResource.java
+++ b/src/main/java/net/shibboleth/ext/spring/resource/ConditionalResource.java
@@ -77,7 +77,7 @@ public class ConditionalResource extends AbstractIdentifiedInitializableComponen
}
/** {@inheritDoc} */
- public InputStream getInputStream() throws IOException {
+ @Nonnull public InputStream getInputStream() throws IOException {
try {
return wrappedResource.getInputStream();
} catch (final IOException e) {
@@ -216,9 +216,12 @@ public class ConditionalResource extends AbstractIdentifiedInitializableComponen
* @return a string for insertion at the beginning of any log messages
*/
@Nonnull @NotEmpty protected String getLogPrefix() {
- if (logPrefix == null) {
- logPrefix = "ConditionalResource " + getId() + ":";
+
+ if (logPrefix != null) {
+ return logPrefix;
}
+
+ logPrefix = "ConditionalResource " + getId() + ":";
return logPrefix;
}
diff --git a/src/main/java/net/shibboleth/ext/spring/resource/FileBackedHTTPResource.java b/src/main/java/net/shibboleth/ext/spring/resource/FileBackedHTTPResource.java
index f3ae592..fa0e2dd 100644
--- a/src/main/java/net/shibboleth/ext/spring/resource/FileBackedHTTPResource.java
+++ b/src/main/java/net/shibboleth/ext/spring/resource/FileBackedHTTPResource.java
@@ -163,7 +163,7 @@ public class FileBackedHTTPResource extends HTTPResource {
}
/** {@inheritDoc} */
- @Override public InputStream getInputStream() throws IOException {
+ @Override @Nonnull public InputStream getInputStream() throws IOException {
try {
final InputStream stream = super.getInputStream();
return saveAndClone(stream);
@@ -239,4 +239,5 @@ public class FileBackedHTTPResource extends HTTPResource {
.append(backingResource.getDescription()).append(']');
return builder.toString();
}
-}
+
+}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java b/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java
index 420ea5d..14d5ff6 100644
--- a/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java
+++ b/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java
@@ -123,7 +123,7 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
*
* @return a new instance of {@link HttpCacheContext}
*/
- protected HttpCacheContext buildHttpClientContext() {
+ @Nonnull protected HttpCacheContext buildHttpClientContext() {
return HttpCacheContext.create();
}
@@ -159,7 +159,7 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
}
/** {@inheritDoc} */
- @Override public InputStream getInputStream() throws IOException {
+ @Override @Nonnull public InputStream getInputStream() throws IOException {
final HttpGet httpGet = new HttpGet(resourceURL.toExternalForm());
final HttpCacheContext context = buildHttpClientContext();
diff --git a/src/main/java/net/shibboleth/ext/spring/resource/ResourceHelper.java b/src/main/java/net/shibboleth/ext/spring/resource/ResourceHelper.java
index bb27fa2..d9c8a0a 100644
--- a/src/main/java/net/shibboleth/ext/spring/resource/ResourceHelper.java
+++ b/src/main/java/net/shibboleth/ext/spring/resource/ResourceHelper.java
@@ -63,65 +63,65 @@ public final class ResourceHelper implements net.shibboleth.utilities.java.suppo
}
/** {@inheritDoc} */
- @Override public InputStream getInputStream() throws IOException {
+ @Nonnull public InputStream getInputStream() throws IOException {
return springResource.getInputStream();
}
/** {@inheritDoc} */
- @Override public boolean exists() {
+ public boolean exists() {
return springResource.exists();
}
/** {@inheritDoc} */
- @Override public boolean isReadable() {
+ public boolean isReadable() {
return springResource.isReadable();
}
/** {@inheritDoc} */
- @Override public boolean isOpen() {
+ public boolean isOpen() {
return springResource.isOpen();
}
/** {@inheritDoc} */
- @Override public URL getURL() throws IOException {
+ public URL getURL() throws IOException {
return springResource.getURL();
}
/** {@inheritDoc} */
- @Override public URI getURI() throws IOException {
+ public URI getURI() throws IOException {
return springResource.getURI();
}
/** {@inheritDoc} */
- @Override public File getFile() throws IOException {
+ public File getFile() throws IOException {
return springResource.getFile();
}
/** {@inheritDoc} */
- @Override public long contentLength() throws IOException {
+ public long contentLength() throws IOException {
return springResource.contentLength();
}
/** {@inheritDoc} */
- @Override public long lastModified() throws IOException {
+ public long lastModified() throws IOException {
return springResource.lastModified();
}
/** {@inheritDoc} */
- @Override public net.shibboleth.utilities.java.support.resource.Resource
+ public net.shibboleth.utilities.java.support.resource.Resource
createRelativeResource(final String relativePath) throws IOException {
return of(springResource.createRelative(relativePath));
}
/** {@inheritDoc} */
- @Override public String getFilename() {
+ public String getFilename() {
return springResource.getFilename();
}
/** {@inheritDoc} */
- @Override public String getDescription() {
+ public String getDescription() {
return springResource.getDescription();
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/ext/spring/resource/RunnableFileSystemResource.java b/src/main/java/net/shibboleth/ext/spring/resource/RunnableFileSystemResource.java
index cd57c53..066c60b 100644
--- a/src/main/java/net/shibboleth/ext/spring/resource/RunnableFileSystemResource.java
+++ b/src/main/java/net/shibboleth/ext/spring/resource/RunnableFileSystemResource.java
@@ -103,7 +103,7 @@ public class RunnableFileSystemResource extends FileSystemResource
}
/** {@inheritDoc} */
- @Override public InputStream getInputStream() throws IOException {
+ @Override @Nonnull public InputStream getInputStream() throws IOException {
callRunnable();
return super.getInputStream();
}
@@ -127,4 +127,5 @@ public class RunnableFileSystemResource extends FileSystemResource
throw new IOException(ex);
}
}
-}
+
+}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/ext/spring/service/ApplicationContextServiceableComponent.java b/src/main/java/net/shibboleth/ext/spring/service/ApplicationContextServiceableComponent.java
index a0b57a5..68d7f72 100644
--- a/src/main/java/net/shibboleth/ext/spring/service/ApplicationContextServiceableComponent.java
+++ b/src/main/java/net/shibboleth/ext/spring/service/ApplicationContextServiceableComponent.java
@@ -40,8 +40,7 @@ public class ApplicationContextServiceableComponent extends AbstractServiceableC
@Override
@Nonnull public ApplicationContext getComponent() {
final ApplicationContext context = getApplicationContext();
- Constraint.isNotNull(context, "ApplicationContext not yet set");
- return context;
+ return Constraint.isNotNull(context, "ApplicationContext not yet set");
}
}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/ext/spring/service/ReloadableSpringService.java b/src/main/java/net/shibboleth/ext/spring/service/ReloadableSpringService.java
index b53f1fe..a6ccf39 100644
--- a/src/main/java/net/shibboleth/ext/spring/service/ReloadableSpringService.java
+++ b/src/main/java/net/shibboleth/ext/spring/service/ReloadableSpringService.java
@@ -30,7 +30,6 @@ import javax.annotation.concurrent.ThreadSafe;
import net.shibboleth.ext.spring.util.ApplicationContextBuilder;
import net.shibboleth.utilities.java.support.annotation.ParameterName;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
-import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
@@ -77,7 +76,7 @@ public class ReloadableSpringService<T> extends AbstractReloadableService<T> imp
@Nonnull private final Logger log = LoggerFactory.getLogger(ReloadableSpringService.class);
/** List of configuration resources for this service. */
- @Nullable @NonnullElements private List<Resource> serviceConfigurations;
+ @Nonnull @NonnullElements private List<Resource> serviceConfigurations;
/** List of bean factory post processors for this service's content. */
@Nonnull @NonnullElements private List<BeanFactoryPostProcessor> factoryPostProcessors;
@@ -138,6 +137,7 @@ public class ReloadableSpringService<T> extends AbstractReloadableService<T> imp
factoryPostProcessors = Collections.emptyList();
postProcessors = Collections.emptyList();
beanProfiles = Collections.emptyList();
+ serviceConfigurations = Collections.emptyList();
}
/**
@@ -455,18 +455,18 @@ public class ReloadableSpringService<T> extends AbstractReloadableService<T> imp
}
/** {@inheritDoc} */
- @Override public void setApplicationContext(final ApplicationContext applicationContext) {
+ public void setApplicationContext(final ApplicationContext applicationContext) {
setParentContext(applicationContext);
}
/** {@inheritDoc} */
- @Override public void setBeanName(@Nonnull @NotEmpty final String name) {
+ public void setBeanName(final String name) {
beanName = name;
}
/** {@inheritDoc} */
@Override protected void doInitialize() throws ComponentInitializationException {
- if (getId() == null) {
+ if (getId() == null && beanName != null) {
setId(beanName);
}
super.doInitialize();
diff --git a/src/main/java/net/shibboleth/ext/spring/velocity/SpringResourceLoader.java b/src/main/java/net/shibboleth/ext/spring/velocity/SpringResourceLoader.java
index a8334cb..d1847d2 100644
--- a/src/main/java/net/shibboleth/ext/spring/velocity/SpringResourceLoader.java
+++ b/src/main/java/net/shibboleth/ext/spring/velocity/SpringResourceLoader.java
@@ -82,7 +82,7 @@ public class SpringResourceLoader extends ResourceLoader {
/** {@inheritDoc} */
@Override
- public void init(@Nullable final ExtendedProperties configuration) {
+ public void init(final ExtendedProperties configuration) {
resourceLoader =
(org.springframework.core.io.ResourceLoader) rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER);
final String resourceLoaderPath = (String) rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER_PATH);
@@ -109,7 +109,7 @@ public class SpringResourceLoader extends ResourceLoader {
/** {@inheritDoc} */
@Override
- @Nonnull public InputStream getResourceStream(@Nonnull @NotEmpty final String source)
+ public InputStream getResourceStream(final String source)
throws ResourceNotFoundException {
log.debug("Looking for Velocity resource with name '{}'", source);
for (final String resourceLoaderPath : resourceLoaderPaths) {
@@ -127,13 +127,13 @@ public class SpringResourceLoader extends ResourceLoader {
/** {@inheritDoc} */
@Override
- public boolean isSourceModified(@Nonnull final Resource resource) {
+ public boolean isSourceModified(final Resource resource) {
return false;
}
/** {@inheritDoc} */
@Override
- public long getLastModified(@Nonnull final Resource resource) {
+ public long getLastModified(final Resource resource) {
return 0;
}
diff --git a/src/main/java/net/shibboleth/ext/spring/velocity/VelocityConfig.java b/src/main/java/net/shibboleth/ext/spring/velocity/VelocityConfig.java
index e01284f..a04ec77 100644
--- a/src/main/java/net/shibboleth/ext/spring/velocity/VelocityConfig.java
+++ b/src/main/java/net/shibboleth/ext/spring/velocity/VelocityConfig.java
@@ -17,8 +17,6 @@
package net.shibboleth.ext.spring.velocity;
-import javax.annotation.Nonnull;
-
import org.apache.velocity.app.VelocityEngine;
/**
@@ -39,5 +37,5 @@ public interface VelocityConfig {
*
* @return the VelocityEngine
*/
- @Nonnull VelocityEngine getVelocityEngine();
+ VelocityEngine getVelocityEngine();
}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/ext/spring/velocity/VelocityConfigurer.java b/src/main/java/net/shibboleth/ext/spring/velocity/VelocityConfigurer.java
index 0cd9bba..a0a6b02 100644
--- a/src/main/java/net/shibboleth/ext/spring/velocity/VelocityConfigurer.java
+++ b/src/main/java/net/shibboleth/ext/spring/velocity/VelocityConfigurer.java
@@ -85,8 +85,7 @@ public class VelocityConfigurer extends VelocityEngineFactory
@Nullable private VelocityEngine velocityEngine;
/** {@inheritDoc} */
- @Override
- public void setServletContext(@Nonnull final ServletContext context) {
+ public void setServletContext(final ServletContext context) {
servletContext = context;
}
@@ -110,7 +109,6 @@ public class VelocityConfigurer extends VelocityEngineFactory
}
/** {@inheritDoc} */
- @Override
public VelocityEngine getVelocityEngine() {
return velocityEngine;
}
diff --git a/src/main/java/net/shibboleth/ext/spring/velocity/VelocityView.java b/src/main/java/net/shibboleth/ext/spring/velocity/VelocityView.java
index 18cb68c..ddb522e 100644
--- a/src/main/java/net/shibboleth/ext/spring/velocity/VelocityView.java
+++ b/src/main/java/net/shibboleth/ext/spring/velocity/VelocityView.java
@@ -40,8 +40,6 @@ import org.springframework.core.NestedIOException;
import org.springframework.web.servlet.view.AbstractTemplateView;
import org.springframework.web.util.NestedServletException;
-import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
-
/**
* View using the Velocity template engine.
*
@@ -220,8 +218,8 @@ public class VelocityView extends AbstractTemplateView {
* This method can be overridden if custom behavior is needed.</p>
*/
@Override
- protected void renderMergedTemplateModel(@Nullable final Map<String,Object> model,
- @Nonnull final HttpServletRequest request, @Nonnull final HttpServletResponse response) throws Exception {
+ protected void renderMergedTemplateModel(final Map<String,Object> model,
+ final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final Context velocityContext = createVelocityContext(model, request, response);
@@ -265,7 +263,7 @@ public class VelocityView extends AbstractTemplateView {
*
* @throws Exception if there's a fatal error while creating the context
*/
- protected Context createVelocityContext(@Nullable final Map<String, Object> model) throws Exception {
+ protected Context createVelocityContext(final Map<String, Object> model) throws Exception {
return new VelocityContext(model);
}
@@ -286,7 +284,7 @@ public class VelocityView extends AbstractTemplateView {
*
* @throws Exception if thrown by Velocity
*/
- protected void doRender(@Nonnull final Context context, @Nonnull final HttpServletResponse response)
+ protected void doRender(final Context context, final HttpServletResponse response)
throws Exception {
/*
* TODO: uncomment once we have a commons logging solution
@@ -332,7 +330,7 @@ public class VelocityView extends AbstractTemplateView {
*
* @throws Exception if thrown by Velocity
*/
- protected Template getTemplate(@Nonnull @NotEmpty final String name) throws Exception {
+ protected Template getTemplate(final String name) throws Exception {
return getEncoding() != null ?
getVelocityEngine().getTemplate(name, getEncoding()) :
getVelocityEngine().getTemplate(name);
@@ -347,7 +345,7 @@ public class VelocityView extends AbstractTemplateView {
*
* @throws Exception if thrown by Velocity
*/
- protected void mergeTemplate(@Nonnull final Template t, @Nonnull final Context context,
+ protected void mergeTemplate(final Template t, final Context context,
@Nonnull final HttpServletResponse response) throws Exception {
try {
diff --git a/src/test/java/net/shibboleth/ext/spring/resource/HTTPResourceTest.java b/src/test/java/net/shibboleth/ext/spring/resource/HTTPResourceTest.java
index ffe56e4..fb561c0 100644
--- a/src/test/java/net/shibboleth/ext/spring/resource/HTTPResourceTest.java
+++ b/src/test/java/net/shibboleth/ext/spring/resource/HTTPResourceTest.java
@@ -150,8 +150,11 @@ public class HTTPResourceTest {
private GenericApplicationContext getContext(final String fileName, final File theDir) {
final GenericApplicationContext parentContext = new GenericApplicationContext();
parentContext.refresh(); // THIS IS REQUIRED
- parentContext.getBeanFactory().registerSingleton("theDir", theDir);
-
+ if (theDir != null) {
+ // Spring 5 blows up on a null registration.
+ parentContext.getBeanFactory().registerSingleton("theDir", theDir);
+ }
+
final GenericApplicationContext context = new GenericApplicationContext(parentContext);
final XmlBeanDefinitionReader beanDefinitionReader = new SchemaTypeAwareXMLBeanDefinitionReader(context);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list