This commit is contained in:
Phillip Webb 2013-11-15 23:37:38 -08:00
parent 127da15c3c
commit 883fd9162f
22 changed files with 72 additions and 88 deletions

View File

@ -239,7 +239,7 @@ public class CrshAutoConfiguration {
try { try {
token = this.authenticationManager.authenticate(token); token = this.authenticationManager.authenticate(token);
} }
catch (AuthenticationException ae) { catch (AuthenticationException ex) {
return false; return false;
} }
@ -250,7 +250,7 @@ public class CrshAutoConfiguration {
this.accessDecisionManager.decide(token, this, this.accessDecisionManager.decide(token, this,
SecurityConfig.createList(this.roles)); SecurityConfig.createList(this.roles));
} }
catch (AccessDeniedException e) { catch (AccessDeniedException ex) {
return false; return false;
} }
} }
@ -440,7 +440,7 @@ public class CrshAutoConfiguration {
try { try {
return this.resource.lastModified(); return this.resource.lastModified();
} }
catch (IOException e) { catch (IOException ex) {
} }
return -1; return -1;
} }

View File

@ -50,18 +50,18 @@ public class SimpleHealthIndicator implements HealthIndicator<Map<String, Object
map.put("database", this.dataSource.getConnection().getMetaData() map.put("database", this.dataSource.getConnection().getMetaData()
.getDatabaseProductName()); .getDatabaseProductName());
} }
catch (SQLException e) { catch (SQLException ex) {
map.put("status", "error"); map.put("status", "error");
map.put("error", e.getClass().getName() + ": " + e.getMessage()); map.put("error", ex.getClass().getName() + ": " + ex.getMessage());
} }
if (StringUtils.hasText(this.query)) { if (StringUtils.hasText(this.query)) {
try { try {
map.put("hello", map.put("hello",
this.jdbcTemplate.queryForObject(this.query, String.class)); this.jdbcTemplate.queryForObject(this.query, String.class));
} }
catch (Exception e) { catch (Exception ex) {
map.put("status", "error"); map.put("status", "error");
map.put("error", e.getClass().getName() + ": " + e.getMessage()); map.put("error", ex.getClass().getName() + ": " + ex.getMessage());
} }
} }
} }

View File

@ -54,7 +54,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/** /**
* Tests for {@link CrshAutoConfiguration}. * Tests for {@link CrshAutoConfiguration}.
@ -235,7 +234,7 @@ public class CrshAutoConfigurationTests {
} }
@Test @Test
public void testSimpleAuthenticationProvider() { public void testSimpleAuthenticationProvider() throws Exception {
MockEnvironment env = new MockEnvironment(); MockEnvironment env = new MockEnvironment();
env.setProperty("shell.auth", "simple"); env.setProperty("shell.auth", "simple");
env.setProperty("shell.auth.simple.username", "user"); env.setProperty("shell.auth.simple.username", "user");
@ -261,24 +260,13 @@ public class CrshAutoConfigurationTests {
} }
} }
assertNotNull(authenticationPlugin); assertNotNull(authenticationPlugin);
try { assertTrue(authenticationPlugin.authenticate("user", "password"));
assertTrue(authenticationPlugin.authenticate("user", "password")); assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(),
} "password"));
catch (Exception e) {
fail();
}
try {
assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(),
"password"));
}
catch (Exception e) {
fail();
}
} }
@Test @Test
public void testSpringAuthenticationProvider() { public void testSpringAuthenticationProvider() throws Exception {
MockEnvironment env = new MockEnvironment(); MockEnvironment env = new MockEnvironment();
env.setProperty("shell.auth", "spring"); env.setProperty("shell.auth", "spring");
this.context = new AnnotationConfigWebApplicationContext(); this.context = new AnnotationConfigWebApplicationContext();
@ -300,22 +288,11 @@ public class CrshAutoConfigurationTests {
break; break;
} }
} }
assertNotNull(authenticationPlugin); assertTrue(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME,
try { SecurityConfiguration.PASSWORD));
assertTrue(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME,
SecurityConfiguration.PASSWORD));
}
catch (Exception e) {
fail();
}
try { assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(),
assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(), SecurityConfiguration.PASSWORD));
SecurityConfiguration.PASSWORD));
}
catch (Exception e) {
fail();
}
} }
@Configuration @Configuration

View File

@ -197,7 +197,8 @@ public class WebMvcAutoConfiguration {
logger.info("Adding welcome page: " logger.info("Adding welcome page: "
+ this.resourceLoader.getResource(resource).getURL()); + this.resourceLoader.getResource(resource).getURL());
} }
catch (IOException e) { catch (IOException ex) {
// Ignore
} }
registry.addViewController("/").setViewName("/index.html"); registry.addViewController("/").setViewName("/index.html");
return; return;

View File

@ -16,12 +16,15 @@
package org.springframework.boot.autoconfigure.amqp; package org.springframework.boot.autoconfigure.amqp;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.amqp.core.AmqpAdmin; import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.TestUtils; import org.springframework.boot.TestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -29,7 +32,6 @@ import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
/** /**
* Tests for {@link RabbitAutoConfiguration}. * Tests for {@link RabbitAutoConfiguration}.
@ -40,6 +42,9 @@ public class RabbitAutoconfigurationTests {
private AnnotationConfigApplicationContext context; private AnnotationConfigApplicationContext context;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testDefaultRabbitTemplate() { public void testDefaultRabbitTemplate() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
@ -123,12 +128,11 @@ public class RabbitAutoconfigurationTests {
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class);
TestUtils.addEnviroment(this.context, "spring.rabbitmq.dynamic:false"); TestUtils.addEnviroment(this.context, "spring.rabbitmq.dynamic:false");
this.context.refresh(); this.context.refresh();
try { // There should NOT be an AmqpAdmin bean when dynamic is switch to false
this.context.getBean(AmqpAdmin.class); this.thrown.expect(NoSuchBeanDefinitionException.class);
fail("There should NOT be an AmqpAdmin bean when dynamic is switch to false"); this.thrown.expectMessage("No qualifying bean of type "
} + "[org.springframework.amqp.core.AmqpAdmin] is defined");
catch (Exception e) { this.context.getBean(AmqpAdmin.class);
}
} }
@Configuration @Configuration

View File

@ -87,7 +87,7 @@ public class UnsecureManagementSampleActuatorApplicationTests {
public void testMetrics() throws Exception { public void testMetrics() throws Exception {
try { try {
testHomeIsSecure(); // makes sure some requests have been made testHomeIsSecure(); // makes sure some requests have been made
} catch (AssertionError e) { } catch (AssertionError ex) {
// ignore; // ignore;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")

View File

@ -39,8 +39,8 @@ public class SampleMongoApplicationTests {
public void testDefaultSettings() throws Exception { public void testDefaultSettings() throws Exception {
try { try {
SampleMongoApplication.main(new String[0]); SampleMongoApplication.main(new String[0]);
} catch (IllegalStateException e) { } catch (IllegalStateException ex) {
if (serverNotRunning(e)) { if (serverNotRunning(ex)) {
return; return;
} }
} }

View File

@ -94,8 +94,8 @@ public class SnakeTimer {
try { try {
tick(); tick();
} }
catch (Throwable e) { catch (Throwable ex) {
log.error("Caught to prevent timer from shutting down", e); log.error("Caught to prevent timer from shutting down", ex);
} }
} }
}, TICK_DELAY, TICK_DELAY); }, TICK_DELAY, TICK_DELAY);

View File

@ -60,8 +60,8 @@ public class WebApplicationInitializersConfiguration extends AbstractConfigurati
initializer.onStartup(sce.getServletContext()); initializer.onStartup(sce.getServletContext());
} }
} }
catch (Exception e) { catch (Exception ex) {
throw new RuntimeException(e); throw new RuntimeException(ex);
} }
} }

View File

@ -173,14 +173,16 @@ public class LaunchedURLClassLoader extends URLClassLoader {
} }
} }
catch (IOException e) { catch (IOException ex) {
// Ignore
} }
} }
return null; return null;
} }
}, AccessController.getContext()); }, AccessController.getContext());
} }
catch (java.security.PrivilegedActionException pae) { catch (java.security.PrivilegedActionException ex) {
// Ignore
} }
} }
} }

View File

@ -308,7 +308,7 @@ public class PropertiesLauncher extends Launcher {
this.logger.info("Main class from home directory manifest: " + mainClass); this.logger.info("Main class from home directory manifest: " + mainClass);
return mainClass; return mainClass;
} }
catch (IllegalStateException e) { catch (IllegalStateException ex) {
// Otherwise try the parent archive // Otherwise try the parent archive
String mainClass = createArchive().getMainClass(); String mainClass = createArchive().getMainClass();
this.logger.info("Main class from archive manifest: " + mainClass); this.logger.info("Main class from archive manifest: " + mainClass);

View File

@ -65,7 +65,7 @@ public abstract class Archive {
try { try {
return getUrl().toString(); return getUrl().toString();
} }
catch (Exception e) { catch (Exception ex) {
return "archive"; return "archive";
} }
} }

View File

@ -44,7 +44,7 @@ import org.springframework.boot.loader.tools.MainClassFinder;
* @author Phillip Webb * @author Phillip Webb
*/ */
@Mojo(name = "run", requiresProject = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.TEST) @Mojo(name = "run", requiresProject = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.TEST)
@Execute(phase=LifecyclePhase.TEST_COMPILE) @Execute(phase = LifecyclePhase.TEST_COMPILE)
public class RunMojo extends AbstractMojo { public class RunMojo extends AbstractMojo {
/** /**
@ -179,7 +179,7 @@ public class RunMojo extends AbstractMojo {
hasNonDaemonThreads = true; hasNonDaemonThreads = true;
thread.join(); thread.join();
} }
catch (InterruptedException e) { catch (InterruptedException ex) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
@ -249,8 +249,8 @@ public class RunMojo extends AbstractMojo {
+ "main method with appropriate signature.", ex); + "main method with appropriate signature.", ex);
thread.getThreadGroup().uncaughtException(thread, wrappedEx); thread.getThreadGroup().uncaughtException(thread, wrappedEx);
} }
catch (Exception e) { catch (Exception ex) {
thread.getThreadGroup().uncaughtException(thread, e); thread.getThreadGroup().uncaughtException(thread, ex);
} }
} }
} }

View File

@ -116,7 +116,7 @@ public abstract class AnsiOutput {
} }
return !(OPERATING_SYSTEM_NAME.indexOf("win") >= 0); return !(OPERATING_SYSTEM_NAME.indexOf("win") >= 0);
} }
catch (Throwable e) { catch (Throwable ex) {
return false; return false;
} }
} }

View File

@ -59,7 +59,7 @@ public class PropertySourcesPropertyValues implements PropertyValues {
try { try {
value = resolver.getProperty(propertyName); value = resolver.getProperty(propertyName);
} }
catch (RuntimeException e) { catch (RuntimeException ex) {
// Probably could not resolve placeholders, ignore it here // Probably could not resolve placeholders, ignore it here
} }
this.propertyValues.put(propertyName, new PropertyValue( this.propertyValues.put(propertyName, new PropertyValue(

View File

@ -121,9 +121,9 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext
try { try {
super.refresh(); super.refresh();
} }
catch (RuntimeException e) { catch (RuntimeException ex) {
stopAndReleaseEmbeddedServletContainer(); stopAndReleaseEmbeddedServletContainer();
throw e; throw ex;
} }
} }
@ -340,11 +340,11 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex); WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
throw ex; throw ex;
} }
catch (Error err) { catch (Error ex) {
logger.error("Context initialization failed", err); logger.error("Context initialization failed", ex);
servletContext.setAttribute( servletContext.setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err); WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
throw err; throw ex;
} }
} }

View File

@ -74,8 +74,8 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
Connector connector = this.tomcat.getConnector(); Connector connector = this.tomcat.getConnector();
connector.getProtocolHandler().stop(); connector.getProtocolHandler().stop();
} }
catch (Exception e) { catch (Exception ex) {
this.logger.error("Cannot pause connector: ", e); this.logger.error("Cannot pause connector: ", ex);
} }
// Unlike Jetty, all Tomcat threads are daemon threads. We create a // Unlike Jetty, all Tomcat threads are daemon threads. We create a
// blocking non-daemon to stop immediate shutdown // blocking non-daemon to stop immediate shutdown
@ -105,8 +105,8 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
try { try {
connector.getProtocolHandler().start(); connector.getProtocolHandler().start();
} }
catch (Exception e) { catch (Exception ex) {
this.logger.error("Cannot start connector: ", e); this.logger.error("Cannot start connector: ", ex);
} }
} }
} }

View File

@ -454,9 +454,9 @@ public class TomcatEmbeddedServletContainerFactory extends
} }
} }
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException ex) {
} }
catch (LinkageError e) { catch (LinkageError ex) {
} }
return nativePage; return nativePage;
} }

View File

@ -85,7 +85,7 @@ public class TomcatEmbeddedWebappClassLoader extends WebappClassLoader {
try { try {
return Class.forName(name, false, this.parent); return Class.forName(name, false, this.parent);
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException ex) {
return null; return null;
} }
} }
@ -94,7 +94,7 @@ public class TomcatEmbeddedWebappClassLoader extends WebappClassLoader {
try { try {
return findClass(name); return findClass(name);
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException ex) {
return null; return null;
} }
} }
@ -105,9 +105,9 @@ public class TomcatEmbeddedWebappClassLoader extends WebappClassLoader {
this.securityManager.checkPackageAccess(name.substring(0, this.securityManager.checkPackageAccess(name.substring(0,
name.lastIndexOf('.'))); name.lastIndexOf('.')));
} }
catch (SecurityException se) { catch (SecurityException ex) {
throw new ClassNotFoundException("Security Violation, attempt to use " throw new ClassNotFoundException("Security Violation, attempt to use "
+ "Restricted Class: " + name, se); + "Restricted Class: " + name, ex);
} }
} }
} }

View File

@ -160,8 +160,8 @@ public class VcapApplicationContextInitializer implements
properties.putAll(map); properties.putAll(map);
} }
} }
catch (Exception e) { catch (Exception ex) {
logger.error("Could not parse VCAP_APPLICATION", e); logger.error("Could not parse VCAP_APPLICATION", ex);
} }
return properties; return properties;
} }
@ -187,8 +187,8 @@ public class VcapApplicationContextInitializer implements
} }
} }
} }
catch (Exception e) { catch (Exception ex) {
logger.error("Could not parse VCAP_APPLICATION", e); logger.error("Could not parse VCAP_APPLICATION", ex);
} }
return properties; return properties;
} }

View File

@ -71,7 +71,7 @@ public class SimpleFormatter extends Formatter {
try { try {
value = System.getenv(key); value = System.getenv(key);
} }
catch (Exception e) { catch (Exception ex) {
// ignore // ignore
} }
if (value == null) { if (value == null) {

View File

@ -77,7 +77,7 @@ public class OutputCapture implements TestRule {
this.captureOut.flush(); this.captureOut.flush();
this.captureErr.flush(); this.captureErr.flush();
} }
catch (IOException e) { catch (IOException ex) {
// ignore // ignore
} }
} }
@ -144,7 +144,7 @@ public class OutputCapture implements TestRule {
Class.forName("org.springframework.boot.ansi.AnsiOutput"); Class.forName("org.springframework.boot.ansi.AnsiOutput");
return new AnsiPresentOutputControl(); return new AnsiPresentOutputControl();
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException ex) {
return new AnsiOutputControl(); return new AnsiOutputControl();
} }
} }