diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0679d88 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = tab +indent_size = 4 +end_of_line = lf +insert_final_newline = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.settings.xml b/.settings.xml index 6c35512..6f542c9 100644 --- a/.settings.xml +++ b/.settings.xml @@ -1,66 +1,68 @@ - - - repo.spring.io - ${env.CI_DEPLOY_USERNAME} - ${env.CI_DEPLOY_PASSWORD} - - - - - - spring - true - - - spring-snapshots - Spring Snapshots - http://repo.spring.io/libs-snapshot-local - - true - - - - spring-milestones - Spring Milestones - http://repo.spring.io/libs-milestone-local - - false - - - - spring-releases - Spring Releases - http://repo.spring.io/release - - false - - - - - - spring-snapshots - Spring Snapshots - http://repo.spring.io/libs-snapshot-local - - true - - - - spring-milestones - Spring Milestones - http://repo.spring.io/libs-milestone-local - - false - - - - - + + + repo.spring.io + ${env.CI_DEPLOY_USERNAME} + ${env.CI_DEPLOY_PASSWORD} + + + + + + spring + + true + + + + spring-snapshots + Spring Snapshots + http://repo.spring.io/libs-snapshot-local + + true + + + + spring-milestones + Spring Milestones + http://repo.spring.io/libs-milestone-local + + false + + + + spring-releases + Spring Releases + http://repo.spring.io/release + + false + + + + + + spring-snapshots + Spring Snapshots + http://repo.spring.io/libs-snapshot-local + + true + + + + spring-milestones + Spring Milestones + http://repo.spring.io/libs-milestone-local + + false + + + + + diff --git a/.springformat b/.springformat new file mode 100644 index 0000000..e69de29 diff --git a/Guardfile b/Guardfile index b3f6788..b556156 100644 --- a/Guardfile +++ b/Guardfile @@ -5,8 +5,8 @@ require './src/main/ruby/readme.rb' options = {:mkdirs => true, :safe => :unsafe, :attributes => ['linkcss', 'allow-uri-read']} guard 'shell' do - watch(/^src\/[A-Z-a-z][^#]*\.adoc$/) {|m| - SpringCloud::Build.render_file('src/main/asciidoc/README.adoc', :to_file => './README.adoc') - Asciidoctor.render_file('src/main/asciidoc/spring-cloud-bus.adoc', options.merge(:to_dir => 'target/generated-docs')) - } + watch(/^src\/[A-Z-a-z][^#]*\.adoc$/) {|m| + SpringCloud::Build.render_file('src/main/asciidoc/README.adoc', :to_file => './README.adoc') + Asciidoctor.render_file('src/main/asciidoc/spring-cloud-bus.adoc', options.merge(:to_dir => 'target/generated-docs')) + } end diff --git a/docs/pom.xml b/docs/pom.xml index 74ccefa..6abadce 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 org.springframework.cloud spring-cloud-bus-docs @@ -16,14 +18,14 @@ ${basedir}/.. 1.1.x,1.2.x,1.3.x - + - - maven-deploy-plugin - - true - + + maven-deploy-plugin + + true + @@ -31,31 +33,31 @@ docs - - - org.apache.maven.plugins - maven-dependency-plugin - - - org.asciidoctor - asciidoctor-maven-plugin - false - - - com.agilejava.docbkx - docbkx-maven-plugin - - - org.apache.maven.plugins - maven-antrun-plugin - false - - - org.codehaus.mojo - build-helper-maven-plugin - false - - + + + org.apache.maven.plugins + maven-dependency-plugin + + + org.asciidoctor + asciidoctor-maven-plugin + false + + + com.agilejava.docbkx + docbkx-maven-plugin + + + org.apache.maven.plugins + maven-antrun-plugin + false + + + org.codehaus.mojo + build-helper-maven-plugin + false + + diff --git a/pom.xml b/pom.xml index 59a9d6f..30e8fd0 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 @@ -30,6 +31,9 @@ 2.1.1.BUILD-SNAPSHOT Fishtown.BUILD-SNAPSHOT bus + true + true + @@ -43,9 +47,26 @@ 1.8 + + org.apache.maven.plugins + maven-checkstyle-plugin + + + io.spring.javaformat + spring-javaformat-maven-plugin + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + + spring @@ -142,8 +163,11 @@ https://github.com/spring-cloud/spring-cloud-bus - scm:git:git://github.com/spring-cloud/spring-cloud-bus.git - scm:git:ssh://git@github.com/spring-cloud/spring-cloud-bus.git + scm:git:git://github.com/spring-cloud/spring-cloud-bus.git + + + scm:git:ssh://git@github.com/spring-cloud/spring-cloud-bus.git + HEAD diff --git a/spring-cloud-bus-dependencies/pom.xml b/spring-cloud-bus-dependencies/pom.xml index 4d2ddbf..4bf2fc2 100644 --- a/spring-cloud-bus-dependencies/pom.xml +++ b/spring-cloud-bus-dependencies/pom.xml @@ -1,12 +1,13 @@ - 4.0.0 spring-cloud-dependencies-parent org.springframework.cloud 2.1.3.BUILD-SNAPSHOT - + spring-cloud-bus-dependencies 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-bus-tests/pom.xml b/spring-cloud-bus-tests/pom.xml index b6e46eb..ee23368 100644 --- a/spring-cloud-bus-tests/pom.xml +++ b/spring-cloud-bus-tests/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 spring-cloud-bus-tests diff --git a/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusJmxEndpointTests.java b/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusJmxEndpointTests.java index b70b4eb..00ddcd3 100644 --- a/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusJmxEndpointTests.java +++ b/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusJmxEndpointTests.java @@ -2,6 +2,7 @@ package org.springframework.cloud.bus; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -13,7 +14,8 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@SpringBootTest(properties = { "spring.jmx.enabled=true", "endpoints.default.jmx.enabled=true" }) +@SpringBootTest(properties = { "spring.jmx.enabled=true", + "endpoints.default.jmx.enabled=true" }) public class BusJmxEndpointTests { @Autowired(required = false) @@ -30,5 +32,8 @@ public class BusJmxEndpointTests { @SpringBootConfiguration @EnableAutoConfiguration - protected static class TestConfig {} + protected static class TestConfig { + + } + } diff --git a/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/jackson/BusJacksonIntegrationTests.java b/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/jackson/BusJacksonIntegrationTests.java index 8663183..05da2e9 100644 --- a/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/jackson/BusJacksonIntegrationTests.java +++ b/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/jackson/BusJacksonIntegrationTests.java @@ -33,73 +33,81 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen @SpringBootTest(webEnvironment = RANDOM_PORT) public class BusJacksonIntegrationTests { - @LocalServerPort - private int port; + @LocalServerPort + private int port; - @Autowired - private TestRestTemplate rest; + @Autowired + private TestRestTemplate rest; - @Autowired - private BusJacksonMessageConverter converter; + @Autowired + private BusJacksonMessageConverter converter; - @Test - public void testCustomEventSerializes() { - assertThat(converter.isMapperCreated()).isFalse(); + @Test + public void testCustomEventSerializes() { + assertThat(this.converter.isMapperCreated()).isFalse(); - rest.put("http://localhost:"+port+"/names"+"/foo", null); - rest.put("http://localhost:"+port+"/names"+"/bar", null); + this.rest.put("http://localhost:" + this.port + "/names" + "/foo", null); + this.rest.put("http://localhost:" + this.port + "/names" + "/bar", null); - ResponseEntity response = rest.getForEntity("http://localhost:" + port + "/names", List.class); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.getBody()).contains("foo", "bar"); - } + ResponseEntity response = this.rest + .getForEntity("http://localhost:" + this.port + "/names", List.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).contains("foo", "bar"); + } - public static class NameEvent extends RemoteApplicationEvent { + public static class NameEvent extends RemoteApplicationEvent { - private String name; + private String name; - protected NameEvent() {} + protected NameEvent() { + } - public NameEvent(Object source, String originService, String name) { - super(source, originService); - this.name = name; - } + public NameEvent(Object source, String originService, String name) { + super(source, originService); + this.name = name; + } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } + public String getName() { + return this.name; + } - } + public void setName(String name) { + this.name = name; + } - @RestController - @EnableAutoConfiguration - @SpringBootConfiguration - @RemoteApplicationEventScan - protected static class Config { - final private Set names = ConcurrentHashMap.newKeySet(); - @Autowired - private ServiceMatcher busServiceMatcher; - @Autowired - private ApplicationEventPublisher publisher; + } - @GetMapping("/names") - public Collection names() { - return this.names; - } + @RestController + @EnableAutoConfiguration + @SpringBootConfiguration + @RemoteApplicationEventScan + protected static class Config { - @PutMapping("/names/{name}") - public void sayName(@PathVariable String name) { - this.names.add(name); - publisher.publishEvent(new NameEvent(this, busServiceMatcher.getServiceId(), name)); - } + final private Set names = ConcurrentHashMap.newKeySet(); - @EventListener - public void handleNameSaid(NameEvent event) { - this.names.add(event.getName()); - } + @Autowired + private ServiceMatcher busServiceMatcher; + + @Autowired + private ApplicationEventPublisher publisher; + + @GetMapping("/names") + public Collection names() { + return this.names; + } + + @PutMapping("/names/{name}") + public void sayName(@PathVariable String name) { + this.names.add(name); + this.publisher.publishEvent( + new NameEvent(this, this.busServiceMatcher.getServiceId(), name)); + } + + @EventListener + public void handleNameSaid(NameEvent event) { + this.names.add(event.getName()); + } + + } - } } diff --git a/spring-cloud-bus/pom.xml b/spring-cloud-bus/pom.xml index 14b5caa..337ed1a 100644 --- a/spring-cloud-bus/pom.xml +++ b/spring-cloud-bus/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 spring-cloud-bus diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusAutoConfiguration.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusAutoConfiguration.java index 2b3aaab..5c2403b 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusAutoConfiguration.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -20,7 +19,6 @@ package org.springframework.cloud.bus; import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.trace.http.HttpTraceRepository; @@ -69,25 +67,34 @@ import org.springframework.util.PathMatcher; @ConditionalOnBusEnabled @EnableBinding(SpringCloudBusClient.class) @EnableConfigurationProperties(BusProperties.class) -@AutoConfigureBefore(BindingServiceConfiguration.class) // so stream bindings work properly -@AutoConfigureAfter(LifecycleMvcEndpointAutoConfiguration.class) // so actuator endpoints have needed dependencies +@AutoConfigureBefore(BindingServiceConfiguration.class) +// so stream bindings work properly +@AutoConfigureAfter(LifecycleMvcEndpointAutoConfiguration.class) +// so actuator endpoints have needed dependencies public class BusAutoConfiguration implements ApplicationEventPublisherAware { + /** + * Name of the Bus path matcher. + */ public static final String BUS_PATH_MATCHER_NAME = "busPathMatcher"; + /** + * Name of the Spring Cloud Config property. + */ public static final String CLOUD_CONFIG_NAME_PROPERTY = "spring.cloud.config.name"; - private MessageChannel cloudBusOutboundChannel; - - private ApplicationEventPublisher applicationEventPublisher; - private final ServiceMatcher serviceMatcher; private final BindingServiceProperties bindings; private final BusProperties bus; - public BusAutoConfiguration(ServiceMatcher serviceMatcher, BindingServiceProperties bindings, BusProperties bus) { + private MessageChannel cloudBusOutboundChannel; + + private ApplicationEventPublisher applicationEventPublisher; + + public BusAutoConfiguration(ServiceMatcher serviceMatcher, + BindingServiceProperties bindings, BusProperties bus) { this.serviceMatcher = serviceMatcher; this.bindings = bindings; this.bus = bus; @@ -103,7 +110,8 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware { } BindingProperties input = this.bindings.getBindings() .get(SpringCloudBusClient.INPUT); - if (input.getDestination() == null || input.getDestination().equals(SpringCloudBusClient.INPUT)) { + if (input.getDestination() == null + || input.getDestination().equals(SpringCloudBusClient.INPUT)) { input.setDestination(this.bus.getDestination()); } BindingProperties outputBinding = this.bindings.getBindings() @@ -114,7 +122,8 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware { } BindingProperties output = this.bindings.getBindings() .get(SpringCloudBusClient.OUTPUT); - if (output.getDestination() == null || output.getDestination().equals(SpringCloudBusClient.OUTPUT)) { + if (output.getDestination() == null + || output.getDestination().equals(SpringCloudBusClient.OUTPUT)) { output.setDestination(this.bus.getDestination()); } } @@ -173,6 +182,13 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware { } } + @Bean + @ConditionalOnProperty(value = "spring.cloud.bus.refresh.enabled", matchIfMissing = true) + @ConditionalOnBean(ContextRefresher.class) + public RefreshListener refreshListener(ContextRefresher contextRefresher) { + return new RefreshListener(contextRefresher); + } + @Configuration protected static class MatcherConfiguration { @@ -196,13 +212,6 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware { } - @Bean - @ConditionalOnProperty(value = "spring.cloud.bus.refresh.enabled", matchIfMissing = true) - @ConditionalOnBean(ContextRefresher.class) - public RefreshListener refreshListener(ContextRefresher contextRefresher) { - return new RefreshListener(contextRefresher); - } - @Configuration @ConditionalOnClass({ Endpoint.class, RefreshScope.class }) protected static class BusRefreshConfiguration { @@ -210,12 +219,14 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware { @Configuration @ConditionalOnBean(ContextRefresher.class) protected static class BusRefreshEndpointConfiguration { + @Bean @ConditionalOnEnabledEndpoint public RefreshBusEndpoint refreshBusEndpoint(ApplicationContext context, BusProperties bus) { return new RefreshBusEndpoint(context, bus.getId()); } + } } @@ -238,6 +249,7 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware { @ConditionalOnClass(EnvironmentManager.class) @ConditionalOnBean(EnvironmentManager.class) protected static class BusEnvironmentConfiguration { + @Bean @ConditionalOnProperty(value = "spring.cloud.bus.env.enabled", matchIfMissing = true) public EnvironmentChangeListener environmentChangeListener() { @@ -247,13 +259,16 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware { @Configuration @ConditionalOnClass(Endpoint.class) protected static class EnvironmentBusEndpointConfiguration { + @Bean @ConditionalOnEnabledEndpoint public EnvironmentBusEndpoint environmentBusEndpoint( ApplicationContext context, BusProperties bus) { return new EnvironmentBusEndpoint(context, bus.getId()); } + } + } } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusEnvironmentPostProcessor.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusEnvironmentPostProcessor.java index 56d55fd..852fbb4 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusEnvironmentPostProcessor.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusEnvironmentPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -31,7 +30,6 @@ import org.springframework.core.env.PropertySource; * {@link EnvironmentPostProcessor} that sets the default properties for the Bus. * * @author Dave Syer - * * @since 1.0.0 */ public class BusEnvironmentPostProcessor implements EnvironmentPostProcessor { @@ -51,9 +49,11 @@ public class BusEnvironmentPostProcessor implements EnvironmentPostProcessor { } // TODO: move this to commons + // @checkstyle:off private String getDefaultServiceId(ConfigurableEnvironment environment) { return "${vcap.application.name:${spring.application.name:application}}:${vcap.application.instance_index:${spring.application.index:${local.server.port:${server.port:0}}}}:${vcap.application.instance_id:${random.value}}"; } + // @checkstyle:on private void addOrReplace(MutablePropertySources propertySources, Map map) { diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusPathMatcher.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusPathMatcher.java index e7b82e2..e7432ea 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusPathMatcher.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusPathMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -28,7 +27,7 @@ import org.springframework.beans.factory.annotation.Qualifier; /** * Qualifier annotation for components to do with matching paths in the bus. - * + * * @author Dave Syer * */ diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusProperties.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusProperties.java index 52aa5f3..4ba6df2 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusProperties.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -30,49 +29,55 @@ public class BusProperties { * Environment change event related properties. */ private Env env = new Env(); + /** * Refresh event related properties. */ private Refresh refresh = new Refresh(); + /** * Properties related to acks. */ private Ack ack = new Ack(); + /** * Properties related to tracing of acks. */ private Trace trace = new Trace(); + /** * Name of Spring Cloud Stream destination for messages. */ private String destination = "springCloudBus"; + /** * The identifier for this application instance. */ private String id = "application"; + /** * Flag to indicate that the bus is enabled. */ private boolean enabled = true; public Env getEnv() { - return env; + return this.env; } public Refresh getRefresh() { - return refresh; + return this.refresh; } public Ack getAck() { - return ack; + return this.ack; } public Trace getTrace() { - return trace; + return this.trace; } public String getDestination() { - return destination; + return this.destination; } public void setDestination(String destination) { @@ -80,7 +85,7 @@ public class BusProperties { } public boolean isEnabled() { - return enabled; + return this.enabled; } public void setEnabled(boolean enabled) { @@ -88,55 +93,70 @@ public class BusProperties { } public String getId() { - return id; + return this.id; } public void setId(String id) { this.id = id; } + /** + * Spring Cloud Bus environment related properties. + */ public static class Env { + /** * Flag to switch off environment change events (default on). */ private boolean enabled = true; public boolean isEnabled() { - return enabled; + return this.enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; } + } + /** + * Spring Cloud Bus properties related to refreshing. + */ public static class Refresh { + /** * Flag to switch off refresh events (default on). */ private boolean enabled = true; public boolean isEnabled() { - return enabled; + return this.enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; } + } + /** + * Spring Cloud Bus properties related to acknowledgments. + */ public static class Ack { + /** * Flag to switch off acks (default on). */ private boolean enabled = true; + /** * Service that wants to listen to acks. By default null (meaning all services). */ private String destinationService; public boolean isEnabled() { - return enabled; + return this.enabled; } public void setEnabled(boolean enabled) { @@ -144,27 +164,33 @@ public class BusProperties { } public String getDestinationService() { - return destinationService; + return this.destinationService; } public void setDestinationService(String destinationService) { this.destinationService = destinationService; } + } + /** + * Spring Cloud Bus trace properties. + */ public static class Trace { + /** * Flag to switch on tracing of acks (default off). */ private boolean enabled = false; public boolean isEnabled() { - return enabled; + return this.enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; } + } } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusPropertiesAutoConfiguration.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusPropertiesAutoConfiguration.java index 5e06e52..7918ee3 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusPropertiesAutoConfiguration.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusPropertiesAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -27,4 +26,5 @@ import org.springframework.context.annotation.Configuration; @Configuration @EnableConfigurationProperties(BusProperties.class) public class BusPropertiesAutoConfiguration { + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ConditionalOnBusEnabled.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ConditionalOnBusEnabled.java index a2a0d4a..ce3c276 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ConditionalOnBusEnabled.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ConditionalOnBusEnabled.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -32,5 +31,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @Target({ ElementType.TYPE, ElementType.METHOD }) public @interface ConditionalOnBusEnabled { - public static String SPRING_CLOUD_BUS_ENABLED = "spring.cloud.bus.enabled"; + /** + * Property name to enable / disable Spring Cloud Bus. + */ + String SPRING_CLOUD_BUS_ENABLED = "spring.cloud.bus.enabled"; + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/DefaultBusPathMatcher.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/DefaultBusPathMatcher.java index 2273e24..e39c53b 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/DefaultBusPathMatcher.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/DefaultBusPathMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -22,14 +21,16 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.util.PathMatcher; import org.springframework.util.StringUtils; import static org.springframework.util.StringUtils.tokenizeToStringArray; /** - * {@link BusPathMatcher} that matches application context ids with multiple, comma-separated, profiles. - * Original https://gist.github.com/kelapure/61d3f948acf478cc95225ff1d7d239c4 + * {@link BusPathMatcher} that matches application context ids with multiple, + * comma-separated, profiles. Original + * https://gist.github.com/kelapure/61d3f948acf478cc95225ff1d7d239c4 * * See https://github.com/spring-cloud/spring-cloud-config/issues/678 * @@ -51,7 +52,7 @@ public class DefaultBusPathMatcher implements PathMatcher { log.debug("matchMultiProfile : " + pattern + ", " + idToMatch); // parse the id - String[] tokens = tokenizeToStringArray(idToMatch,":"); + String[] tokens = tokenizeToStringArray(idToMatch, ":"); if (tokens.length <= 1) { // no parts, default to delegate which already returned false; return false; @@ -59,7 +60,7 @@ public class DefaultBusPathMatcher implements PathMatcher { String selfProfiles = tokens[1]; // short circuit if possible - String[] profiles = tokenizeToStringArray(selfProfiles,","); + String[] profiles = tokenizeToStringArray(selfProfiles, ","); if (profiles.length == 1) { // there aren't multiple profiles to check, the delegate match was @@ -71,7 +72,7 @@ public class DefaultBusPathMatcher implements PathMatcher { String[] idsWithSingleProfile = new String[profiles.length]; for (int i = 0; i < profiles.length; i++) { - //replace comma separated profiles with single profile + // replace comma separated profiles with single profile String profile = profiles[i]; String[] newTokens = new String[tokens.length]; System.arraycopy(tokens, 0, newTokens, 0, tokens.length); @@ -80,7 +81,7 @@ public class DefaultBusPathMatcher implements PathMatcher { } for (String id : idsWithSingleProfile) { - if (delagateMatcher.match(pattern, id)) { + if (this.delagateMatcher.match(pattern, id)) { log.debug("matched true"); return true; } @@ -92,13 +93,13 @@ public class DefaultBusPathMatcher implements PathMatcher { @Override public boolean isPattern(String path) { - return delagateMatcher.isPattern(path); + return this.delagateMatcher.isPattern(path); } @Override public boolean match(String pattern, String path) { log.debug("In match: " + pattern + ", " + path); - if (!delagateMatcher.match(pattern, path)) { + if (!this.delagateMatcher.match(pattern, path)) { return matchMultiProfile(pattern, path); } return true; @@ -106,26 +107,27 @@ public class DefaultBusPathMatcher implements PathMatcher { @Override public boolean matchStart(String pattern, String path) { - return delagateMatcher.matchStart(pattern, path); + return this.delagateMatcher.matchStart(pattern, path); } @Override public String extractPathWithinPattern(String pattern, String path) { - return delagateMatcher.extractPathWithinPattern(pattern, path); + return this.delagateMatcher.extractPathWithinPattern(pattern, path); } @Override public Map extractUriTemplateVariables(String pattern, String path) { - return delagateMatcher.extractUriTemplateVariables(pattern, path); + return this.delagateMatcher.extractUriTemplateVariables(pattern, path); } @Override public Comparator getPatternComparator(String path) { - return delagateMatcher.getPatternComparator(path); + return this.delagateMatcher.getPatternComparator(path); } @Override public String combine(String pattern1, String pattern2) { - return delagateMatcher.combine(pattern1, pattern2); + return this.delagateMatcher.combine(pattern1, pattern2); } + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ServiceMatcher.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ServiceMatcher.java index d399c9b..89d77ce 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ServiceMatcher.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ServiceMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -24,8 +23,11 @@ import org.springframework.util.PathMatcher; * @author Spencer Gibb */ public class ServiceMatcher { + private final PathMatcher matcher; + private final String id; + private String[] configNames = new String[] {}; public ServiceMatcher(PathMatcher matcher, String id) { diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/SpringCloudBusClient.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/SpringCloudBusClient.java index b6dacee..dd52d3d 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/SpringCloudBusClient.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/SpringCloudBusClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -28,8 +27,14 @@ import org.springframework.messaging.SubscribableChannel; */ public interface SpringCloudBusClient { + /** + * Name of the input channel for Spring Cloud Bus. + */ String INPUT = "springCloudBusInput"; + /** + * Name of the output channel for Spring Cloud Bus. + */ String OUTPUT = "springCloudBusOutput"; @Output(SpringCloudBusClient.OUTPUT) @@ -37,4 +42,5 @@ public interface SpringCloudBusClient { @Input(SpringCloudBusClient.INPUT) SubscribableChannel springCloudBusInput(); + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/AbstractBusEndpoint.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/AbstractBusEndpoint.java index 59456a4..d36ae43 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/AbstractBusEndpoint.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/AbstractBusEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.endpoint; @@ -39,7 +38,7 @@ public class AbstractBusEndpoint { } protected void publish(ApplicationEvent event) { - context.publishEvent(event); + this.context.publishEvent(event); } } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/EnvironmentBusEndpoint.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/EnvironmentBusEndpoint.java index 96cfe57..60b76ac 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/EnvironmentBusEndpoint.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/EnvironmentBusEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,24 +12,23 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.endpoint; +import java.util.Collections; +import java.util.Map; + import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.Selector; import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEvent; import org.springframework.context.ApplicationEventPublisher; -import java.util.Collections; -import java.util.Map; - /** * @author Spencer Gibb */ -@Endpoint(id = "bus-env") //TODO: document +@Endpoint(id = "bus-env") // TODO: document public class EnvironmentBusEndpoint extends AbstractBusEndpoint { public EnvironmentBusEndpoint(ApplicationEventPublisher context, String id) { @@ -37,17 +36,18 @@ public class EnvironmentBusEndpoint extends AbstractBusEndpoint { } @WriteOperation - public void busEnvWithDestination(String name, String value, @Selector String destination) { //TODO: document params + public void busEnvWithDestination(String name, String value, + @Selector String destination) { // TODO: document params Map params = Collections.singletonMap(name, value); publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(), destination, params)); } @WriteOperation - public void busEnv(String name, String value) { //TODO: document params + public void busEnv(String name, String value) { // TODO: document params Map params = Collections.singletonMap(name, value); - publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(), - null, params)); + publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(), null, + params)); } } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpoint.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpoint.java index c8d8061..b838b20 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpoint.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.endpoint; @@ -26,7 +25,7 @@ import org.springframework.context.ApplicationEventPublisher; /** * @author Spencer Gibb */ -@Endpoint(id = "bus-refresh") //TODO: document new id +@Endpoint(id = "bus-refresh") // TODO: document new id public class RefreshBusEndpoint extends AbstractBusEndpoint { public RefreshBusEndpoint(ApplicationEventPublisher context, String id) { @@ -34,7 +33,9 @@ public class RefreshBusEndpoint extends AbstractBusEndpoint { } @WriteOperation - public void busRefreshWithDestination(@Selector String destination) { //TODO: document destination + public void busRefreshWithDestination(@Selector String destination) { // TODO: + // document + // destination publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), destination)); } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/AckRemoteApplicationEvent.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/AckRemoteApplicationEvent.java index 55834c3..c3a18f6 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/AckRemoteApplicationEvent.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/AckRemoteApplicationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.event; @@ -32,7 +31,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class AckRemoteApplicationEvent extends RemoteApplicationEvent { private final String ackId; + private final String ackDestinationService; + private Class event; @SuppressWarnings("unused") @@ -53,29 +54,31 @@ public class AckRemoteApplicationEvent extends RemoteApplicationEvent { } public String getAckId() { - return ackId; + return this.ackId; } public String getAckDestinationService() { - return ackDestinationService; + return this.ackDestinationService; } public Class getEvent() { - return event; + return this.event; } /** - * Used by Jackson to set the remote class name of the event implementation. If the implementing class is unknown to - * this app, set the event to {@link UnknownRemoteApplicationEvent}. - * - * @param eventName the fq class name of the event implementation, not null + * Used by Jackson to set the remote class name of the event implementation. If the + * implementing class is unknown to this app, set the event to + * {@link UnknownRemoteApplicationEvent}. + * @param eventName the fq class name of the event implementation, not null */ @JsonProperty("event") public void setEventName(String eventName) { try { - event = (Class) Class.forName(eventName); - } catch (ClassNotFoundException e) { - event = UnknownRemoteApplicationEvent.class; + this.event = (Class) Class + .forName(eventName); + } + catch (ClassNotFoundException e) { + this.event = UnknownRemoteApplicationEvent.class; } } @@ -83,40 +86,50 @@ public class AckRemoteApplicationEvent extends RemoteApplicationEvent { public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((ackDestinationService == null) ? 0 - : ackDestinationService.hashCode()); - result = prime * result + ((ackId == null) ? 0 : ackId.hashCode()); - result = prime * result + ((event == null) ? 0 : event.hashCode()); + result = prime * result + ((this.ackDestinationService == null) ? 0 + : this.ackDestinationService.hashCode()); + result = prime * result + ((this.ackId == null) ? 0 : this.ackId.hashCode()); + result = prime * result + ((this.event == null) ? 0 : this.event.hashCode()); return result; } @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (!super.equals(obj)) + } + if (!super.equals(obj)) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } AckRemoteApplicationEvent other = (AckRemoteApplicationEvent) obj; - if (ackDestinationService == null) { - if (other.ackDestinationService != null) + if (this.ackDestinationService == null) { + if (other.ackDestinationService != null) { return false; + } } - else if (!ackDestinationService.equals(other.ackDestinationService)) + else if (!this.ackDestinationService.equals(other.ackDestinationService)) { return false; - if (ackId == null) { - if (other.ackId != null) + } + if (this.ackId == null) { + if (other.ackId != null) { return false; + } } - else if (!ackId.equals(other.ackId)) + else if (!this.ackId.equals(other.ackId)) { return false; - if (event == null) { - if (other.event != null) + } + if (this.event == null) { + if (other.event != null) { return false; + } } - else if (!event.equals(other.event)) + else if (!this.event.equals(other.event)) { return false; + } return true; } + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeListener.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeListener.java index 62686e0..9d6e6ab 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeListener.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.event; @@ -21,6 +20,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.context.environment.EnvironmentManager; import org.springframework.context.ApplicationListener; @@ -42,7 +42,8 @@ public class EnvironmentChangeListener log.info("Received remote environment change request. Keys/values to update " + values); for (Map.Entry entry : values.entrySet()) { - env.setProperty(entry.getKey(), entry.getValue()); + this.env.setProperty(entry.getKey(), entry.getValue()); } } + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeRemoteApplicationEvent.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeRemoteApplicationEvent.java index 77fef8f..4b44b71 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeRemoteApplicationEvent.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeRemoteApplicationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.event; @@ -30,7 +29,7 @@ public class EnvironmentChangeRemoteApplicationEvent extends RemoteApplicationEv @SuppressWarnings("unused") private EnvironmentChangeRemoteApplicationEvent() { // for serializers - values = null; + this.values = null; } public EnvironmentChangeRemoteApplicationEvent(Object source, String originService, @@ -40,32 +39,37 @@ public class EnvironmentChangeRemoteApplicationEvent extends RemoteApplicationEv } public Map getValues() { - return values; + return this.values; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((values == null) ? 0 : values.hashCode()); + result = prime * result + ((this.values == null) ? 0 : this.values.hashCode()); return result; } @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - EnvironmentChangeRemoteApplicationEvent other = (EnvironmentChangeRemoteApplicationEvent) obj; - if (values == null) { - if (other.values != null) - return false; } - else if (!values.equals(other.values)) + if (!super.equals(obj)) { return false; + } + if (getClass() != obj.getClass()) { + return false; + } + EnvironmentChangeRemoteApplicationEvent other = (EnvironmentChangeRemoteApplicationEvent) obj; + if (this.values == null) { + if (other.values != null) { + return false; + } + } + else if (!this.values.equals(other.values)) { + return false; + } return true; } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshListener.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshListener.java index 433ac45..1be8a85 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshListener.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.event; @@ -21,6 +20,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.context.refresh.ContextRefresher; import org.springframework.context.ApplicationListener; @@ -40,7 +40,8 @@ public class RefreshListener @Override public void onApplicationEvent(RefreshRemoteApplicationEvent event) { - Set keys = contextRefresher.refresh(); + Set keys = this.contextRefresher.refresh(); log.info("Received remote refresh request. Keys refreshed " + keys); } + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshRemoteApplicationEvent.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshRemoteApplicationEvent.java index 00e0858..622df48 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshRemoteApplicationEvent.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshRemoteApplicationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.event; @@ -32,4 +31,5 @@ public class RefreshRemoteApplicationEvent extends RemoteApplicationEvent { String destinationService) { super(source, originService, destinationService); } + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RemoteApplicationEvent.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RemoteApplicationEvent.java index 4c2ff09..25497b2 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RemoteApplicationEvent.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RemoteApplicationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,19 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.event; import java.util.UUID; -import org.springframework.context.ApplicationEvent; -import org.springframework.util.StringUtils; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.springframework.context.ApplicationEvent; +import org.springframework.util.StringUtils; + /** * @author Spencer Gibb */ @@ -32,9 +31,13 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") @JsonIgnoreProperties("source") public abstract class RemoteApplicationEvent extends ApplicationEvent { + private static final Object TRANSIENT_SOURCE = new Object(); + private final String originService; + private final String destinationService; + private final String id; protected RemoteApplicationEvent() { @@ -49,8 +52,10 @@ public abstract class RemoteApplicationEvent extends ApplicationEvent { if (destinationService == null) { destinationService = "**"; } - // If the destinationService is not already a wildcard, match everything that follows - // if there at most two path elements, and last element is not a global wildcard already + // If the destinationService is not already a wildcard, match everything that + // follows + // if there at most two path elements, and last element is not a global wildcard + // already if (!"**".equals(destinationService)) { if (StringUtils.countOccurrencesOf(destinationService, ":") <= 1 && !StringUtils.endsWithIgnoreCase(destinationService, ":**")) { @@ -67,56 +72,66 @@ public abstract class RemoteApplicationEvent extends ApplicationEvent { } public String getOriginService() { - return originService; + return this.originService; } public String getDestinationService() { - return destinationService; + return this.destinationService; } public String getId() { - return id; + return this.id; } @Override public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ((this.destinationService == null) ? 0 + : this.destinationService.hashCode()); + result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); result = prime * result - + ((destinationService == null) ? 0 : destinationService.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result - + ((originService == null) ? 0 : originService.hashCode()); + + ((this.originService == null) ? 0 : this.originService.hashCode()); return result; } @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } RemoteApplicationEvent other = (RemoteApplicationEvent) obj; - if (destinationService == null) { - if (other.destinationService != null) + if (this.destinationService == null) { + if (other.destinationService != null) { return false; + } } - else if (!destinationService.equals(other.destinationService)) + else if (!this.destinationService.equals(other.destinationService)) { return false; - if (id == null) { - if (other.id != null) + } + if (this.id == null) { + if (other.id != null) { return false; + } } - else if (!id.equals(other.id)) + else if (!this.id.equals(other.id)) { return false; - if (originService == null) { - if (other.originService != null) + } + if (this.originService == null) { + if (other.originService != null) { return false; + } } - else if (!originService.equals(other.originService)) + else if (!this.originService.equals(other.originService)) { return false; + } return true; } + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/SentApplicationEvent.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/SentApplicationEvent.java index 82f55e8..80669b0 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/SentApplicationEvent.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/SentApplicationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,16 +12,15 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.event; -import org.springframework.context.ApplicationEvent; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.springframework.context.ApplicationEvent; + /** * An event signalling that a remote event was sent somewhere in the system. This is not * itself a {@link RemoteApplicationEvent}, so it isn't sent over the bus, instead it is @@ -38,9 +37,13 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; public class SentApplicationEvent extends ApplicationEvent { private static final Object TRANSIENT_SOURCE = new Object(); + private final String originService; + private final String destinationService; + private final String id; + private Class type; protected SentApplicationEvent() { @@ -66,7 +69,7 @@ public class SentApplicationEvent extends ApplicationEvent { } public Class getType() { - return type; + return this.type; } public void setType(Class type) { @@ -74,63 +77,75 @@ public class SentApplicationEvent extends ApplicationEvent { } public String getOriginService() { - return originService; + return this.originService; } public String getDestinationService() { - return destinationService; + return this.destinationService; } public String getId() { - return id; + return this.id; } @Override public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ((this.destinationService == null) ? 0 + : this.destinationService.hashCode()); + result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); result = prime * result - + ((destinationService == null) ? 0 : destinationService.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result - + ((originService == null) ? 0 : originService.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); + + ((this.originService == null) ? 0 : this.originService.hashCode()); + result = prime * result + ((this.type == null) ? 0 : this.type.hashCode()); return result; } @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } SentApplicationEvent other = (SentApplicationEvent) obj; - if (destinationService == null) { - if (other.destinationService != null) + if (this.destinationService == null) { + if (other.destinationService != null) { return false; + } } - else if (!destinationService.equals(other.destinationService)) + else if (!this.destinationService.equals(other.destinationService)) { return false; - if (id == null) { - if (other.id != null) + } + if (this.id == null) { + if (other.id != null) { return false; + } } - else if (!id.equals(other.id)) + else if (!this.id.equals(other.id)) { return false; - if (originService == null) { - if (other.originService != null) + } + if (this.originService == null) { + if (other.originService != null) { return false; + } } - else if (!originService.equals(other.originService)) + else if (!this.originService.equals(other.originService)) { return false; - if (type == null) { - if (other.type != null) + } + if (this.type == null) { + if (other.type != null) { return false; + } } - else if (!type.equals(other.type)) + else if (!this.type.equals(other.type)) { return false; + } return true; } + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/TraceListener.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/TraceListener.java index 067ad78..99bfbe0 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/TraceListener.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/TraceListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.event; @@ -22,6 +21,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.boot.actuate.trace.http.HttpTraceRepository; import org.springframework.context.event.EventListener; @@ -78,4 +78,5 @@ public class TraceListener { } return map; } + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/UnknownRemoteApplicationEvent.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/UnknownRemoteApplicationEvent.java index d289344..1c09253 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/UnknownRemoteApplicationEvent.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/UnknownRemoteApplicationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,18 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.event; /** - * * @author Stefan Pfeiffer */ public class UnknownRemoteApplicationEvent extends RemoteApplicationEvent { protected String typeInfo; + protected byte[] payload; @SuppressWarnings("unused") @@ -34,7 +33,8 @@ public class UnknownRemoteApplicationEvent extends RemoteApplicationEvent { } public UnknownRemoteApplicationEvent(Object source, String typeInfo, byte[] payload) { - // Initialize originService with an empty String, to avoid NullPointer in AntPathMatcher. + // Initialize originService with an empty String, to avoid NullPointer in + // AntPathMatcher. super(source, "", null); this.typeInfo = typeInfo; this.payload = payload; @@ -51,4 +51,5 @@ public class UnknownRemoteApplicationEvent extends RemoteApplicationEvent { public String getPayloadAsString() { return new String(this.payload); } + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/BusJacksonAutoConfiguration.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/BusJacksonAutoConfiguration.java index a2ddb2a..b77ea1c 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/BusJacksonAutoConfiguration.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/BusJacksonAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.jackson; @@ -59,17 +58,19 @@ import org.springframework.util.MimeTypeUtils; @Configuration @ConditionalOnBusEnabled @ConditionalOnClass({ RefreshBusEndpoint.class, ObjectMapper.class }) -@AutoConfigureBefore({ BusAutoConfiguration.class, JacksonAutoConfiguration.class}) +@AutoConfigureBefore({ BusAutoConfiguration.class, JacksonAutoConfiguration.class }) public class BusJacksonAutoConfiguration { // needed in the case where @RemoteApplicationEventScan is not used // otherwise RemoteApplicationEventRegistrar will register the bean - @Bean - @ConditionalOnMissingBean(name = "busJsonConverter") - @StreamMessageConverter - public AbstractMessageConverter busJsonConverter(@Autowired(required = false) ObjectMapper objectMapper) { - return new BusJacksonMessageConverter(objectMapper); - } + @Bean + @ConditionalOnMissingBean(name = "busJsonConverter") + @StreamMessageConverter + public AbstractMessageConverter busJsonConverter( + @Autowired(required = false) ObjectMapper objectMapper) { + return new BusJacksonMessageConverter(objectMapper); + } + } class BusJacksonMessageConverter extends AbstractMessageConverter @@ -81,29 +82,31 @@ class BusJacksonMessageConverter extends AbstractMessageConverter .getPackageName(RemoteApplicationEvent.class); private final ObjectMapper mapper; + private final boolean mapperCreated; private String[] packagesToScan = new String[] { DEFAULT_PACKAGE }; - public BusJacksonMessageConverter() { + BusJacksonMessageConverter() { this(null); - } + } - @Autowired(required = false) - public BusJacksonMessageConverter(ObjectMapper objectMapper) { + @Autowired(required = false) + BusJacksonMessageConverter(ObjectMapper objectMapper) { super(MimeTypeUtils.APPLICATION_JSON); if (objectMapper != null) { this.mapper = objectMapper; this.mapperCreated = false; - } else { + } + else { this.mapper = new ObjectMapper(); this.mapperCreated = true; } } public boolean isMapperCreated() { - return mapperCreated; + return this.mapperCreated; } public void setPackagesToScan(String[] packagesToScan) { @@ -136,7 +139,7 @@ class BusJacksonMessageConverter extends AbstractMessageConverter } } if (log.isDebugEnabled()) { - log.debug("Found sub types: "+types); + log.debug("Found sub types: " + types); } return types.toArray(new Class[0]); } @@ -157,17 +160,24 @@ class BusJacksonMessageConverter extends AbstractMessageConverter if (payload instanceof byte[]) { try { result = this.mapper.readValue((byte[]) payload, targetClass); - } catch (InvalidTypeIdException e) { - return new UnknownRemoteApplicationEvent(new Object(), e.getTypeId(), (byte[]) payload); } - } else if (payload instanceof String) { + catch (InvalidTypeIdException e) { + return new UnknownRemoteApplicationEvent(new Object(), e.getTypeId(), + (byte[]) payload); + } + } + else if (payload instanceof String) { try { result = this.mapper.readValue((String) payload, targetClass); - } catch (InvalidTypeIdException e) { - return new UnknownRemoteApplicationEvent(new Object(), e.getTypeId(), ((String) payload).getBytes()); } - // workaround for https://github.com/spring-cloud/spring-cloud-stream/issues/1564 - } else if (payload instanceof RemoteApplicationEvent) { + catch (InvalidTypeIdException e) { + return new UnknownRemoteApplicationEvent(new Object(), e.getTypeId(), + ((String) payload).getBytes()); + } + // workaround for + // https://github.com/spring-cloud/spring-cloud-stream/issues/1564 + } + else if (payload instanceof RemoteApplicationEvent) { return payload; } } @@ -183,4 +193,5 @@ class BusJacksonMessageConverter extends AbstractMessageConverter this.mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); this.mapper.registerModule(new SubtypeModule(findSubTypes())); } + } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventRegistrar.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventRegistrar.java index d477a22..ad78dc2 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventRegistrar.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.jackson; @@ -36,39 +35,45 @@ import org.springframework.util.StringUtils; */ public class RemoteApplicationEventRegistrar implements ImportBeanDefinitionRegistrar { - // patterned after Spring Integration IntegrationComponentScanRegistrar + // patterned after Spring Integration IntegrationComponentScanRegistrar - @Override - public void registerBeanDefinitions(final AnnotationMetadata importingClassMetadata, - final BeanDefinitionRegistry registry) { + @Override + public void registerBeanDefinitions(final AnnotationMetadata importingClassMetadata, + final BeanDefinitionRegistry registry) { - Map componentScan = importingClassMetadata - .getAnnotationAttributes(RemoteApplicationEventScan.class.getName(), false); + Map componentScan = importingClassMetadata + .getAnnotationAttributes(RemoteApplicationEventScan.class.getName(), + false); - Set basePackages = new HashSet<>(); - for (String pkg : (String[]) componentScan.get("value")) { - if (StringUtils.hasText(pkg)) { - basePackages.add(pkg); - } - } - for (String pkg : (String[]) componentScan.get("basePackages")) { - if (StringUtils.hasText(pkg)) { - basePackages.add(pkg); - } - } - for (Class clazz : (Class[]) componentScan.get("basePackageClasses")) { - basePackages.add(ClassUtils.getPackageName(clazz)); - } + Set basePackages = new HashSet<>(); + for (String pkg : (String[]) componentScan.get("value")) { + if (StringUtils.hasText(pkg)) { + basePackages.add(pkg); + } + } + for (String pkg : (String[]) componentScan.get("basePackages")) { + if (StringUtils.hasText(pkg)) { + basePackages.add(pkg); + } + } + for (Class clazz : (Class[]) componentScan.get("basePackageClasses")) { + basePackages.add(ClassUtils.getPackageName(clazz)); + } - if (basePackages.isEmpty()) { - basePackages.add(ClassUtils.getPackageName(importingClassMetadata.getClassName())); - } + if (basePackages.isEmpty()) { + basePackages.add( + ClassUtils.getPackageName(importingClassMetadata.getClassName())); + } - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(BusJacksonMessageConverter.class); - beanDefinitionBuilder.addPropertyValue("packagesToScan", basePackages.toArray(new String[basePackages.size()])); - AbstractBeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition(); + BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder + .genericBeanDefinition(BusJacksonMessageConverter.class); + beanDefinitionBuilder.addPropertyValue("packagesToScan", + basePackages.toArray(new String[basePackages.size()])); + AbstractBeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition(); + + BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, + "busJsonConverter"); + BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); + } - BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, "busJsonConverter"); - BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); - } } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScan.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScan.java index 6643ad0..41afdb4 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScan.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScan.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.jackson; @@ -24,7 +23,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.context.annotation.Import; -import org.springframework.core.annotation.AliasFor; /** * @author Donovan Muller @@ -35,9 +33,10 @@ import org.springframework.core.annotation.AliasFor; @Import(RemoteApplicationEventRegistrar.class) public @interface RemoteApplicationEventScan { - String[] value() default {}; + String[] value() default {}; - String[] basePackages() default {}; + String[] basePackages() default {}; + + Class[] basePackageClasses() default {}; - Class[] basePackageClasses() default {}; } diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/SubtypeModule.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/SubtypeModule.java index 12e9d48..7820c06 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/SubtypeModule.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/SubtypeModule.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.jackson; @@ -24,6 +23,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule; */ @SuppressWarnings("serial") public class SubtypeModule extends SimpleModule { + private Class[] subtypes; public SubtypeModule(Class... subtypes) { @@ -32,7 +32,8 @@ public class SubtypeModule extends SimpleModule { @Override public void setupModule(SetupContext context) { - context.registerSubtypes(subtypes); + context.registerSubtypes(this.subtypes); super.setupModule(context); } + } diff --git a/spring-cloud-bus/src/main/resources/META-INF/spring.factories b/spring-cloud-bus/src/main/resources/META-INF/spring.factories index 04bb294..066f40d 100644 --- a/spring-cloud-bus/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-bus/src/main/resources/META-INF/spring.factories @@ -2,7 +2,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.cloud.bus.BusPropertiesAutoConfiguration,\ org.springframework.cloud.bus.BusAutoConfiguration,\ org.springframework.cloud.bus.jackson.BusJacksonAutoConfiguration - # Environment Post Processor org.springframework.boot.env.EnvironmentPostProcessor=\ -org.springframework.cloud.bus.BusEnvironmentPostProcessor \ No newline at end of file +org.springframework.cloud.bus.BusEnvironmentPostProcessor diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationClassPathTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationClassPathTests.java index 5c9958d..d40efbb 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationClassPathTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationClassPathTests.java @@ -13,18 +13,18 @@ import org.springframework.cloud.test.ModifiedClassPathRunner; import static org.assertj.core.api.Assertions.assertThat; - @RunWith(ModifiedClassPathRunner.class) -@ClassPathExclusions({"spring-boot-actuator-*.jar", "spring-boot-starter-actuator-*.jar"}) +@ClassPathExclusions({ "spring-boot-actuator-*.jar", + "spring-boot-starter-actuator-*.jar" }) public class BusAutoConfigurationClassPathTests { - @Test - public void refreshListenerCreatedWithoutActuator() { - new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class, - BusAutoConfiguration.class)) - .run(context -> assertThat(context) - .hasSingleBean(RefreshListener.class) - .doesNotHaveBean(RefreshBusEndpoint.class)); - } + @Test + public void refreshListenerCreatedWithoutActuator() { + new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class, + BusAutoConfiguration.class)) + .run(context -> assertThat(context).hasSingleBean(RefreshListener.class) + .doesNotHaveBean(RefreshBusEndpoint.class)); + } + } diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationTests.java index 24f2a5a..8a4c6be 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -74,8 +73,9 @@ public class BusAutoConfigurationTests { @Test public void defaultId() { - this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--server.port=0"); - assertTrue("Wrong ID: " + context.getBean(BusProperties.class).getId(), + this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, + "--server.port=0"); + assertTrue("Wrong ID: " + this.context.getBean(BusProperties.class).getId(), this.context.getBean(BusProperties.class).getId() .startsWith("application:0:")); } @@ -287,12 +287,14 @@ public class BusAutoConfigurationTests { assertThat(output.getDestination()).isEqualTo(bus.getDestination()); } - private BusProperties setupBusAutoConfig(HashMap properties) { + private BusProperties setupBusAutoConfig( + HashMap properties) { BindingServiceProperties serviceProperties = mock(BindingServiceProperties.class); when(serviceProperties.getBindings()).thenReturn(properties); BusProperties bus = new BusProperties(); - BusAutoConfiguration configuration = new BusAutoConfiguration(mock(ServiceMatcher.class), serviceProperties, bus); + BusAutoConfiguration configuration = new BusAutoConfiguration( + mock(ServiceMatcher.class), serviceProperties, bus); configuration.init(); return bus; } @@ -302,7 +304,7 @@ public class BusAutoConfigurationTests { @Ignore // TODO: replicate problem public void serviceMatcherIdIsConstantAfterRefresh() { this.context = SpringApplication.run(new Class[] { RefreshConfig.class, }, - new String[] {"--spring.main.allow-bean-definition-overriding=true"}); + new String[] { "--spring.main.allow-bean-definition-overriding=true" }); String originalServiceId = this.context.getBean(ServiceMatcher.class) .getServiceId(); this.context.getBean(ContextRefresher.class).refresh(); @@ -313,6 +315,7 @@ public class BusAutoConfigurationTests { @Configuration @EnableAutoConfiguration protected static class RefreshConfig { + } @Configuration @@ -363,7 +366,8 @@ public class BusAutoConfigurationTests { @Import({ MessageConsumer.class, BusAutoConfiguration.class, TestSupportBinderAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) - protected static class InboundMessageHandlerConfiguration implements ApplicationListener { + protected static class InboundMessageHandlerConfiguration + implements ApplicationListener { private RefreshRemoteApplicationEvent refresh; @@ -375,8 +379,11 @@ public class BusAutoConfigurationTests { } @Configuration - protected static class SentMessageConfiguration implements ApplicationListener { + protected static class SentMessageConfiguration + implements ApplicationListener { + private SentApplicationEvent event; + private int count; @Override @@ -384,11 +391,15 @@ public class BusAutoConfigurationTests { this.event = event; this.count++; } + } @Configuration - protected static class AckMessageConfiguration implements ApplicationListener { + protected static class AckMessageConfiguration + implements ApplicationListener { + private AckRemoteApplicationEvent event; + private int count; @Override @@ -396,6 +407,7 @@ public class BusAutoConfigurationTests { this.event = event; this.count++; } + } } diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ConditionalOnBusEnabledTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ConditionalOnBusEnabledTests.java index ce46009..8686fae 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ConditionalOnBusEnabledTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ConditionalOnBusEnabledTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -49,7 +48,8 @@ public class ConditionalOnBusEnabledTests { @Test public void busEnabledTrue() { - load(MyBusEnabledConfig.class, ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED+":true"); + load(MyBusEnabledConfig.class, + ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED + ":true"); assertTrue("missing bean from @ConditionalOnBusEnabled config", this.context.containsBean("foo")); } @@ -63,11 +63,19 @@ public class ConditionalOnBusEnabledTests { @Test public void busDisabled() { - load(MyBusEnabledConfig.class, ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED+":false"); + load(MyBusEnabledConfig.class, + ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED + ":false"); assertFalse("bean exists from disabled @ConditionalOnBusEnabled config", this.context.containsBean("foo")); } + private void load(Class config, String... environment) { + this.context = new AnnotationConfigApplicationContext(); + TestPropertyValues.of(environment).applyTo(this.context); + this.context.register(config); + this.context.refresh(); + } + @Configuration @ConditionalOnBusEnabled protected static class MyBusEnabledConfig { @@ -79,10 +87,4 @@ public class ConditionalOnBusEnabledTests { } - private void load(Class config, String... environment) { - this.context = new AnnotationConfigApplicationContext(); - TestPropertyValues.of(environment).applyTo(this.context); - this.context.register(config); - this.context.refresh(); - } } diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java index 01212c8..654d1b3 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus; @@ -47,86 +46,87 @@ public class ServiceMatcherTests { private void initMatcher(String id) { BusProperties properties = new BusProperties(); properties.setId(id); - DefaultBusPathMatcher pathMatcher = new DefaultBusPathMatcher(new AntPathMatcher(":")); - matcher = new ServiceMatcher(pathMatcher, properties.getId()); + DefaultBusPathMatcher pathMatcher = new DefaultBusPathMatcher( + new AntPathMatcher(":")); + this.matcher = new ServiceMatcher(pathMatcher, properties.getId()); } @Test public void fromSelf() { - assertThat(matcher.isFromSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "one:two:8888", "foo:bar:spam", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isFromSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "one:two:8888", "foo:bar:spam", EMPTY_MAP)), is(true)); } @Test public void forSelf() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one:two:8888", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one:two:8888", EMPTY_MAP)), is(true)); } @Test public void forSelfWithWildcard() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one:two:*", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one:two:*", EMPTY_MAP)), is(true)); } @Test public void forSelfWithGlobalWildcard() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "**", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "**", EMPTY_MAP)), is(true)); } @Test public void forSelfWithWildcardName() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); } @Test public void forSelfWithWildcardNameAndProfile() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "o*:t*", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "o*:t*", EMPTY_MAP)), is(true)); } @Test public void forSelfWithWildcardString() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); } @Test public void notForSelfWithWildCardNameAndMismatchingProfile() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "o*:f*", EMPTY_MAP)), is(false)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "o*:f*", EMPTY_MAP)), is(false)); } @Test public void forSelfWithDoubleWildcard() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one:**", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one:**", EMPTY_MAP)), is(true)); } @Test public void forSelfWithNoWildcard() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one", EMPTY_MAP)), is(true)); } @Test public void forSelfWithProfileNoWildcard() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one:two", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one:two", EMPTY_MAP)), is(true)); } @Test public void notForSelf() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one:two:9999", EMPTY_MAP)), is(false)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one:two:9999", EMPTY_MAP)), is(false)); } @Test public void notFromSelf() { - assertThat(matcher.isFromSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "one:two:9999", "foo:bar:spam", EMPTY_MAP)), is(false)); + assertThat(this.matcher.isFromSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "one:two:9999", "foo:bar:spam", EMPTY_MAP)), is(false)); } /** @@ -135,8 +135,8 @@ public class ServiceMatcherTests { @Test public void forSelfWithMultipleProfiles() { initMatcher("customerportal:dev,cloud:80"); - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "customerportal:cloud:*", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "customerportal:cloud:*", EMPTY_MAP)), is(true)); } /** @@ -145,8 +145,8 @@ public class ServiceMatcherTests { @Test public void notForSelfWithMultipleProfiles() { initMatcher("customerportal:dev,cloud:80"); - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)), is(false)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)), is(false)); } /** @@ -156,7 +156,7 @@ public class ServiceMatcherTests { public void notForSelfWithMultipleProfilesDifferentPort() { initMatcher("customerportal:dev,cloud:80"); assertThat( - matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, + this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "customerportal:cloud:8008", EMPTY_MAP)), is(false)); } diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherWithConfigNamesTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherWithConfigNamesTests.java index de9412f..23fdfd8 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherWithConfigNamesTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherWithConfigNamesTests.java @@ -41,101 +41,102 @@ public class ServiceMatcherWithConfigNamesTests { @Before public void init() { - initMatcher("otherid:two:8888", new String[] {"one", "three"}); + initMatcher("otherid:two:8888", new String[] { "one", "three" }); } private void initMatcher(String id, String[] configNames) { BusProperties properties = new BusProperties(); properties.setId(id); - DefaultBusPathMatcher pathMatcher = new DefaultBusPathMatcher(new AntPathMatcher(":")); - matcher = new ServiceMatcher(pathMatcher, properties.getId(), configNames); + DefaultBusPathMatcher pathMatcher = new DefaultBusPathMatcher( + new AntPathMatcher(":")); + this.matcher = new ServiceMatcher(pathMatcher, properties.getId(), configNames); } @Test public void forSelfWithWildcard() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one:two:*", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one:two:*", EMPTY_MAP)), is(true)); } @Test public void forSelfWithWildcardAndOtherConfigName() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "three:two:*", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "three:two:*", EMPTY_MAP)), is(true)); } @Test public void forSelfWithGlobalWildcard() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "**", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "**", EMPTY_MAP)), is(true)); } @Test public void forSelfWithWildcardName() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); } @Test public void forSelfWithWildcardNameAndProfile() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "o*:t*", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "o*:t*", EMPTY_MAP)), is(true)); } @Test public void forSelfWithWildcardString() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "o*", EMPTY_MAP)), is(true)); } @Test public void notForSelfWithWildCardNameAndMismatchingProfile() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "o*:f*", EMPTY_MAP)), is(false)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "o*:f*", EMPTY_MAP)), is(false)); } @Test public void forSelfWithDoubleWildcard() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one:**", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one:**", EMPTY_MAP)), is(true)); } @Test public void forSelfWithNoWildcard() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one", EMPTY_MAP)), is(true)); } @Test public void forSelfWithProfileNoWildcard() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one:two", EMPTY_MAP)), is(true)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one:two", EMPTY_MAP)), is(true)); } @Test public void notForSelf() { - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one:two:9999", EMPTY_MAP)), is(false)); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one:two:9999", EMPTY_MAP)), is(false)); } @Test public void forSelfWithMultipleProfiles() { - initMatcher("customerportal:dev,cloud:80", new String[] {"one", "three"}); - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "one:cloud:*", EMPTY_MAP)), is(true)); + initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" }); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "one:cloud:*", EMPTY_MAP)), is(true)); } @Test public void notForSelfWithMultipleProfiles() { - initMatcher("customerportal:dev,cloud:80", new String[] {"one", "three"}); - assertThat(matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, - "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)), is(false)); + initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" }); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent( + this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)), is(false)); } @Test public void notForSelfWithMultipleProfilesDifferentPort() { - initMatcher("customerportal:dev,cloud:80", new String[] {"one", "three"}); + initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" }); assertThat( - matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, + this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "customerportal:cloud:8008", EMPTY_MAP)), is(false)); } diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpointTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpointTests.java index b6c867f..976dd6f 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpointTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,15 +12,14 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.endpoint; -import static org.junit.Assert.assertEquals; - import org.junit.Test; +import static org.junit.Assert.assertEquals; + /** * @author Dave Syer */ diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TestRemoteApplicationEvent.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TestRemoteApplicationEvent.java index 470b82c..90ac1e8 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TestRemoteApplicationEvent.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TestRemoteApplicationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.event.test; @@ -21,6 +20,7 @@ import org.springframework.cloud.bus.event.RemoteApplicationEvent; @SuppressWarnings("serial") public class TestRemoteApplicationEvent extends RemoteApplicationEvent { + @SuppressWarnings("unused") private TestRemoteApplicationEvent() { } @@ -33,4 +33,5 @@ public class TestRemoteApplicationEvent extends RemoteApplicationEvent { protected TestRemoteApplicationEvent(Object source, String originService) { super(source, originService); } -} \ No newline at end of file + +} diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TypedRemoteApplicationEvent.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TypedRemoteApplicationEvent.java index 2a0ef80..8dc4a79 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TypedRemoteApplicationEvent.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TypedRemoteApplicationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,18 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.event.test; -import org.springframework.cloud.bus.event.RemoteApplicationEvent; - import com.fasterxml.jackson.annotation.JsonTypeName; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; + @SuppressWarnings("serial") @JsonTypeName("typed") public class TypedRemoteApplicationEvent extends RemoteApplicationEvent { + @SuppressWarnings("unused") private TypedRemoteApplicationEvent() { } @@ -36,4 +36,5 @@ public class TypedRemoteApplicationEvent extends RemoteApplicationEvent { protected TypedRemoteApplicationEvent(Object source, String originService) { super(source, originService); } -} \ No newline at end of file + +} diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScanTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScanTests.java index 8f704b7..686c2ce 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScanTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.jackson; @@ -22,7 +21,11 @@ import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.jsontype.NamedType; import org.junit.Test; +import test.foo.bar.FooBarTestRemoteApplicationEvent; + import org.springframework.boot.Banner; import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; @@ -38,22 +41,17 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.test.util.ReflectionTestUtils; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.jsontype.NamedType; - import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import test.foo.bar.FooBarTestRemoteApplicationEvent; - public class RemoteApplicationEventScanTests { private BusJacksonMessageConverter converter; @Test public void importingClassMetadataPackageRegistered() { - converter = createTestContext(DefaultConfig.class) + this.converter = createTestContext(DefaultConfig.class) .getBean(BusJacksonMessageConverter.class); assertConverterBeanAfterPropertiesSet( @@ -65,7 +63,7 @@ public class RemoteApplicationEventScanTests { @Test public void annotationValuePackagesRegistered() { - converter = createTestContext(ValueConfig.class) + this.converter = createTestContext(ValueConfig.class) .getBean(BusJacksonMessageConverter.class); assertConverterBeanAfterPropertiesSet( @@ -77,7 +75,7 @@ public class RemoteApplicationEventScanTests { @Test public void annotationValueBasePackagesRegistered() { - converter = createTestContext(BasePackagesConfig.class) + this.converter = createTestContext(BasePackagesConfig.class) .getBean(BusJacksonMessageConverter.class); assertConverterBeanAfterPropertiesSet( @@ -89,7 +87,7 @@ public class RemoteApplicationEventScanTests { @Test public void annotationBasePackagesRegistered() { - converter = createTestContext(BasePackageClassesConfig.class) + this.converter = createTestContext(BasePackageClassesConfig.class) .getBean(BusJacksonMessageConverter.class); assertConverterBeanAfterPropertiesSet( @@ -106,8 +104,8 @@ public class RemoteApplicationEventScanTests { private void assertConverterBeanAfterPropertiesSet( final String[] expectedPackageToScan, final Class... expectedRegisterdClasses) { - final ObjectMapper mapper = (ObjectMapper) ReflectionTestUtils.getField(converter, - "mapper"); + final ObjectMapper mapper = (ObjectMapper) ReflectionTestUtils + .getField(this.converter, "mapper"); @SuppressWarnings("unchecked") final LinkedHashSet registeredSubtypes = (LinkedHashSet) ReflectionTestUtils @@ -125,7 +123,8 @@ public class RemoteApplicationEventScanTests { } assertThat("RemoteApplicationEvent packages not registered", - Arrays.asList((String[]) ReflectionTestUtils.getField(converter, "packagesToScan")), + Arrays.asList((String[]) ReflectionTestUtils.getField(this.converter, + "packagesToScan")), containsInAnyOrder(expectedPackageToScan)); } @@ -141,20 +140,26 @@ public class RemoteApplicationEventScanTests { @Configuration @RemoteApplicationEventScan static class DefaultConfig { + } @Configuration @RemoteApplicationEventScan({ "com.acme", "test.foo.bar" }) static class ValueConfig { + } @Configuration - @RemoteApplicationEventScan(basePackages = { "com.acme", "test.foo.bar", "fizz.buzz" }) + @RemoteApplicationEventScan(basePackages = { "com.acme", "test.foo.bar", + "fizz.buzz" }) static class BasePackagesConfig { + } @Configuration @RemoteApplicationEventScan(basePackageClasses = TestRemoteApplicationEvent.class) static class BasePackageClassesConfig { + } + } diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SerializationTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SerializationTests.java index 929dd4d..8a4f807 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SerializationTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SerializationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,23 +12,22 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.jackson; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - import java.util.Collections; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Test; + import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEvent; import org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent; import org.springframework.cloud.bus.event.RemoteApplicationEvent; -import com.fasterxml.jackson.databind.ObjectMapper; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** * @author Dave Syer diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SubtypeModuleTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SubtypeModuleTests.java index 45ad149..377310f 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SubtypeModuleTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SubtypeModuleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,12 +12,15 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package org.springframework.cloud.bus.jackson; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; import org.junit.Test; + import org.springframework.cloud.bus.event.AckRemoteApplicationEvent; import org.springframework.cloud.bus.event.RemoteApplicationEvent; import org.springframework.cloud.bus.event.UnknownRemoteApplicationEvent; @@ -25,10 +28,6 @@ import org.springframework.cloud.bus.event.test.TestRemoteApplicationEvent; import org.springframework.cloud.bus.event.test.TypedRemoteApplicationEvent; import org.springframework.messaging.support.MessageBuilder; -import com.fasterxml.jackson.annotation.JsonTypeName; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.PropertyNamingStrategy; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -70,21 +69,20 @@ public class SubtypeModuleTests { BusJacksonMessageConverter converter = new BusJacksonMessageConverter(mapper); converter.afterPropertiesSet(); - Object event = converter.fromMessage( - MessageBuilder.withPayload("{\"type\":\"TestRemoteApplicationEvent\", \"origin_service\":\"myorigin\"}").build(), - RemoteApplicationEvent.class); - assertThat(event) - .isNotNull() - .isInstanceOf(TestRemoteApplicationEvent.class); - assertThat(TestRemoteApplicationEvent.class.cast(event).getOriginService()).isEqualTo("myorigin"); + Object event = converter.fromMessage(MessageBuilder.withPayload( + "{\"type\":\"TestRemoteApplicationEvent\", \"origin_service\":\"myorigin\"}") + .build(), RemoteApplicationEvent.class); + assertThat(event).isNotNull().isInstanceOf(TestRemoteApplicationEvent.class); + assertThat(TestRemoteApplicationEvent.class.cast(event).getOriginService()) + .isEqualTo("myorigin"); } @Test public void testDeserializeWithMessageConverter() throws Exception { BusJacksonMessageConverter converter = new BusJacksonMessageConverter(); converter.afterPropertiesSet(); - Object event = converter.fromMessage( - MessageBuilder.withPayload("{\"type\":\"TestRemoteApplicationEvent\"}").build(), + Object event = converter.fromMessage(MessageBuilder + .withPayload("{\"type\":\"TestRemoteApplicationEvent\"}").build(), RemoteApplicationEvent.class); assertTrue("event is wrong type", event instanceof TestRemoteApplicationEvent); } @@ -93,12 +91,15 @@ public class SubtypeModuleTests { public void testDeserializeUnknownTypeWithMessageConverter() throws Exception { BusJacksonMessageConverter converter = new BusJacksonMessageConverter(); converter.afterPropertiesSet(); - Object event = converter.fromMessage( - MessageBuilder.withPayload("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}").build(), - RemoteApplicationEvent.class); + Object event = converter.fromMessage(MessageBuilder + .withPayload("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}") + .build(), RemoteApplicationEvent.class); assertTrue("event is wrong type", event instanceof UnknownRemoteApplicationEvent); - assertEquals("type information is wrong", "NotDefinedTestRemoteApplicationEvent", ((UnknownRemoteApplicationEvent)event).getTypeInfo()); - assertEquals("payload is wrong", "{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}", ((UnknownRemoteApplicationEvent)event).getPayloadAsString()); + assertEquals("type information is wrong", "NotDefinedTestRemoteApplicationEvent", + ((UnknownRemoteApplicationEvent) event).getTypeInfo()); + assertEquals("payload is wrong", + "{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}", + ((UnknownRemoteApplicationEvent) event).getPayloadAsString()); } @Test @@ -123,27 +124,31 @@ public class SubtypeModuleTests { .build(), RemoteApplicationEvent.class); assertTrue("event is no ack", event instanceof AckRemoteApplicationEvent); AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event); - assertEquals("inner ack event has wrong type", TestRemoteApplicationEvent.class, ackEvent.getEvent()); + assertEquals("inner ack event has wrong type", TestRemoteApplicationEvent.class, + ackEvent.getEvent()); } /** * see https://github.com/spring-cloud/spring-cloud-bus/issues/74 */ @Test - public void testDeserializeAckRemoteApplicationEventWithUnknownType() throws Exception { + public void testDeserializeAckRemoteApplicationEventWithUnknownType() + throws Exception { BusJacksonMessageConverter converter = new BusJacksonMessageConverter(); converter.afterPropertiesSet(); Object event = converter.fromMessage(MessageBuilder.withPayload( - "{\"type\":\"AckRemoteApplicationEvent\", \"event\":\"foo.bar.TestRemoteApplicationEvent\"}").build(), - RemoteApplicationEvent.class); + "{\"type\":\"AckRemoteApplicationEvent\", \"event\":\"foo.bar.TestRemoteApplicationEvent\"}") + .build(), RemoteApplicationEvent.class); assertTrue("event is no ack", event instanceof AckRemoteApplicationEvent); AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event); - assertEquals("inner ack event has wrong type", UnknownRemoteApplicationEvent.class, ackEvent.getEvent()); + assertEquals("inner ack event has wrong type", + UnknownRemoteApplicationEvent.class, ackEvent.getEvent()); } @SuppressWarnings("serial") @JsonTypeName("my") public static class MyRemoteApplicationEvent extends RemoteApplicationEvent { + @SuppressWarnings("unused") private MyRemoteApplicationEvent() { } @@ -156,11 +161,13 @@ public class SubtypeModuleTests { protected MyRemoteApplicationEvent(Object source, String originService) { super(source, originService); } + } @SuppressWarnings("serial") @JsonTypeName("another") public static class AnotherRemoteApplicationEvent extends RemoteApplicationEvent { + @SuppressWarnings("unused") private AnotherRemoteApplicationEvent() { } @@ -173,5 +180,7 @@ public class SubtypeModuleTests { protected AnotherRemoteApplicationEvent(Object source, String originService) { super(source, originService); } + } + } diff --git a/spring-cloud-bus/src/test/java/test/foo/bar/FooBarTestRemoteApplicationEvent.java b/spring-cloud-bus/src/test/java/test/foo/bar/FooBarTestRemoteApplicationEvent.java index c0e5618..80121dd 100644 --- a/spring-cloud-bus/src/test/java/test/foo/bar/FooBarTestRemoteApplicationEvent.java +++ b/spring-cloud-bus/src/test/java/test/foo/bar/FooBarTestRemoteApplicationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package test.foo.bar; @@ -21,6 +20,7 @@ import org.springframework.cloud.bus.event.RemoteApplicationEvent; @SuppressWarnings("serial") public class FooBarTestRemoteApplicationEvent extends RemoteApplicationEvent { + @SuppressWarnings("unused") private FooBarTestRemoteApplicationEvent() { } @@ -34,4 +34,5 @@ public class FooBarTestRemoteApplicationEvent extends RemoteApplicationEvent { final String originService) { super(source, originService); } + } diff --git a/spring-cloud-bus/src/test/resources/application.properties b/spring-cloud-bus/src/test/resources/application.properties index d18f0f6..c1902d2 100644 --- a/spring-cloud-bus/src/test/resources/application.properties +++ b/spring-cloud-bus/src/test/resources/application.properties @@ -1 +1 @@ -spring.main.web-environment: false \ No newline at end of file +spring.main.web-environment:false diff --git a/spring-cloud-starter-bus-amqp/pom.xml b/spring-cloud-starter-bus-amqp/pom.xml index 7cc9ab3..0936586 100644 --- a/spring-cloud-starter-bus-amqp/pom.xml +++ b/spring-cloud-starter-bus-amqp/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 org.springframework.cloud diff --git a/spring-cloud-starter-bus-kafka/pom.xml b/spring-cloud-starter-bus-kafka/pom.xml index bdd9f87..171c3bb 100644 --- a/spring-cloud-starter-bus-kafka/pom.xml +++ b/spring-cloud-starter-bus-kafka/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 org.springframework.cloud