Added checkstyle

This commit is contained in:
Marcin Grzejszczak
2019-02-02 10:34:59 +01:00
parent c954a3b53c
commit b10aaa7d2d
52 changed files with 793 additions and 584 deletions

14
.editorconfig Normal file
View File

@@ -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

View File

@@ -1,66 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<servers>
<server>
<id>repo.spring.io</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<!--
N.B. this profile is only here to support users and IDEs that do not use Maven 3.3.
It isn't needed on the command line if you use the wrapper script (mvnw) or if you use
a native Maven with the right version. Eclipse users should points their Maven tooling to
this settings file, or copy the profile into their ~/.m2/settings.xml.
-->
<id>spring</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<servers>
<server>
<id>repo.spring.io</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<!--
N.B. this profile is only here to support users and IDEs that do not use Maven 3.3.
It isn't needed on the command line if you use the wrapper script (mvnw) or if you use
a native Maven with the right version. Eclipse users should points their Maven tooling to
this settings file, or copy the profile into their ~/.m2/settings.xml.
-->
<id>spring</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>

0
.springformat Normal file
View File

View File

@@ -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

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bus-docs</artifactId>
@@ -16,14 +18,14 @@
<main.basedir>${basedir}/..</main.basedir>
<docs.whitelisted.branches>1.1.x,1.2.x,1.3.x</docs.whitelisted.branches>
</properties>
<build>
<build>
<plugins>
<plugin>
<!--skip deploy (this is just a test module) -->
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<!--skip deploy (this is just a test module) -->
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
@@ -31,31 +33,31 @@
<profile>
<id>docs</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<inherited>false</inherited>
</plugin>
<plugin>
<groupId>com.agilejava.docbkx</groupId>
<artifactId>docbkx-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<inherited>false</inherited>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<inherited>false</inherited>
</plugin>
</plugins>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<inherited>false</inherited>
</plugin>
<plugin>
<groupId>com.agilejava.docbkx</groupId>
<artifactId>docbkx-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<inherited>false</inherited>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<inherited>false</inherited>
</plugin>
</plugins>
</build>
</profile>
</profiles>

30
pom.xml
View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -30,6 +31,9 @@
<spring-cloud-commons.version>2.1.1.BUILD-SNAPSHOT</spring-cloud-commons.version>
<spring-cloud-stream.version>Fishtown.BUILD-SNAPSHOT</spring-cloud-stream.version>
<bintray.package>bus</bintray.package>
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
<maven-checkstyle-plugin.failsOnViolation>true
</maven-checkstyle-plugin.failsOnViolation>
</properties>
<build>
@@ -43,9 +47,26 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</reporting>
<profiles>
<profile>
<id>spring</id>
@@ -142,8 +163,11 @@
<scm>
<url>https://github.com/spring-cloud/spring-cloud-bus</url>
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-bus.git</connection>
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-bus.git</developerConnection>
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-bus.git
</connection>
<developerConnection>
scm:git:ssh://git@github.com/spring-cloud/spring-cloud-bus.git
</developerConnection>
<tag>HEAD</tag>
</scm>

View File

@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>spring-cloud-dependencies-parent</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>2.1.3.BUILD-SNAPSHOT</version>
<relativePath/>
<relativePath/>
</parent>
<artifactId>spring-cloud-bus-dependencies</artifactId>
<version>2.1.1.BUILD-SNAPSHOT</version>

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-bus-tests</artifactId>

View File

@@ -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 {
}
}

View File

@@ -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<List> response = rest.getForEntity("http://localhost:" + port + "/names", List.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).contains("foo", "bar");
}
ResponseEntity<List> 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<String> names = ConcurrentHashMap.newKeySet();
@Autowired
private ServiceMatcher busServiceMatcher;
@Autowired
private ApplicationEventPublisher publisher;
}
@GetMapping("/names")
public Collection<String> 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<String> 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<String> 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());
}
}
}
}

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-bus</artifactId>

View File

@@ -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());
}
}
}
}

View File

@@ -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<String, Object> map) {

View File

@@ -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
*
*/

View File

@@ -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;
}
}
}

View File

@@ -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 {
}

View File

@@ -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";
}

View File

@@ -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<String, String> extractUriTemplateVariables(String pattern, String path) {
return delagateMatcher.extractUriTemplateVariables(pattern, path);
return this.delagateMatcher.extractUriTemplateVariables(pattern, path);
}
@Override
public Comparator<String> 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);
}
}

View File

@@ -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) {

View File

@@ -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();
}

View File

@@ -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);
}
}

View File

@@ -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<String, String> 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<String, String> params = Collections.singletonMap(name, value);
publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(),
null, params));
publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(), null,
params));
}
}

View File

@@ -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));
}

View File

@@ -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<? extends RemoteApplicationEvent> 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<? extends RemoteApplicationEvent> 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<? extends RemoteApplicationEvent>) Class.forName(eventName);
} catch (ClassNotFoundException e) {
event = UnknownRemoteApplicationEvent.class;
this.event = (Class<? extends RemoteApplicationEvent>) 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;
}
}

View File

@@ -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<String, String> entry : values.entrySet()) {
env.setProperty(entry.getKey(), entry.getValue());
this.env.setProperty(entry.getKey(), entry.getValue());
}
}
}

View File

@@ -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<String, String> 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;
}

View File

@@ -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<String> keys = contextRefresher.refresh();
Set<String> keys = this.contextRefresher.refresh();
log.info("Received remote refresh request. Keys refreshed " + keys);
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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<? extends RemoteApplicationEvent> type;
protected SentApplicationEvent() {
@@ -66,7 +69,7 @@ public class SentApplicationEvent extends ApplicationEvent {
}
public Class<? extends RemoteApplicationEvent> getType() {
return type;
return this.type;
}
public void setType(Class<? extends RemoteApplicationEvent> 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;
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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()));
}
}

View File

@@ -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<String, Object> componentScan = importingClassMetadata
.getAnnotationAttributes(RemoteApplicationEventScan.class.getName(), false);
Map<String, Object> componentScan = importingClassMetadata
.getAnnotationAttributes(RemoteApplicationEventScan.class.getName(),
false);
Set<String> 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<String> 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);
}
}

View File

@@ -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 {};
}

View File

@@ -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);
}
}

View File

@@ -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
org.springframework.cloud.bus.BusEnvironmentPostProcessor

View File

@@ -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));
}
}

View File

@@ -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<String, BindingProperties> properties) {
private BusProperties setupBusAutoConfig(
HashMap<String, BindingProperties> 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<RefreshRemoteApplicationEvent> {
protected static class InboundMessageHandlerConfiguration
implements ApplicationListener<RefreshRemoteApplicationEvent> {
private RefreshRemoteApplicationEvent refresh;
@@ -375,8 +379,11 @@ public class BusAutoConfigurationTests {
}
@Configuration
protected static class SentMessageConfiguration implements ApplicationListener<SentApplicationEvent> {
protected static class SentMessageConfiguration
implements ApplicationListener<SentApplicationEvent> {
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<AckRemoteApplicationEvent> {
protected static class AckMessageConfiguration
implements ApplicationListener<AckRemoteApplicationEvent> {
private AckRemoteApplicationEvent event;
private int count;
@Override
@@ -396,6 +407,7 @@ public class BusAutoConfigurationTests {
this.event = event;
this.count++;
}
}
}

View File

@@ -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();
}
}

View File

@@ -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));
}

View File

@@ -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));
}

View File

@@ -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
*/

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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<NamedType> registeredSubtypes = (LinkedHashSet<NamedType>) 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 {
}
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}

View File

@@ -1 +1 @@
spring.main.web-environment: false
spring.main.web-environment:false

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>