Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
a4ca1d02
Commit
a4ca1d02
authored
Nov 25, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x' into 2.2.x
Closes gh-19112
parents
36f4d2f0
d386ee09
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
8 deletions
+35
-8
RabbitProperties.java
...ngframework/boot/autoconfigure/amqp/RabbitProperties.java
+13
-8
RabbitPropertiesTests.java
...mework/boot/autoconfigure/amqp/RabbitPropertiesTests.java
+22
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java
View file @
a4ca1d02
...
@@ -189,7 +189,7 @@ public class RabbitProperties {
...
@@ -189,7 +189,7 @@ public class RabbitProperties {
private
List
<
Address
>
parseAddresses
(
String
addresses
)
{
private
List
<
Address
>
parseAddresses
(
String
addresses
)
{
List
<
Address
>
parsedAddresses
=
new
ArrayList
<>();
List
<
Address
>
parsedAddresses
=
new
ArrayList
<>();
for
(
String
address
:
StringUtils
.
commaDelimitedListToStringArray
(
addresses
))
{
for
(
String
address
:
StringUtils
.
commaDelimitedListToStringArray
(
addresses
))
{
parsedAddresses
.
add
(
new
Address
(
address
));
parsedAddresses
.
add
(
new
Address
(
address
,
getSsl
().
isEnabled
()
));
}
}
return
parsedAddresses
;
return
parsedAddresses
;
}
}
...
@@ -390,7 +390,7 @@ public class RabbitProperties {
...
@@ -390,7 +390,7 @@ public class RabbitProperties {
return
isEnabled
();
return
isEnabled
();
}
}
Address
address
=
RabbitProperties
.
this
.
parsedAddresses
.
get
(
0
);
Address
address
=
RabbitProperties
.
this
.
parsedAddresses
.
get
(
0
);
return
address
.
secureConnection
;
return
address
.
determineSslEnabled
(
isEnabled
())
;
}
}
public
void
setEnabled
(
boolean
enabled
)
{
public
void
setEnabled
(
boolean
enabled
)
{
...
@@ -989,14 +989,14 @@ public class RabbitProperties {
...
@@ -989,14 +989,14 @@ public class RabbitProperties {
private
String
virtualHost
;
private
String
virtualHost
;
private
b
oolean
secureConnection
;
private
B
oolean
secureConnection
;
private
Address
(
String
input
)
{
private
Address
(
String
input
,
boolean
sslEnabled
)
{
input
=
input
.
trim
();
input
=
input
.
trim
();
input
=
trimPrefix
(
input
);
input
=
trimPrefix
(
input
);
input
=
parseUsernameAndPassword
(
input
);
input
=
parseUsernameAndPassword
(
input
);
input
=
parseVirtualHost
(
input
);
input
=
parseVirtualHost
(
input
);
parseHostAndPort
(
input
);
parseHostAndPort
(
input
,
sslEnabled
);
}
}
private
String
trimPrefix
(
String
input
)
{
private
String
trimPrefix
(
String
input
)
{
...
@@ -1005,7 +1005,8 @@ public class RabbitProperties {
...
@@ -1005,7 +1005,8 @@ public class RabbitProperties {
return
input
.
substring
(
PREFIX_AMQP_SECURE
.
length
());
return
input
.
substring
(
PREFIX_AMQP_SECURE
.
length
());
}
}
if
(
input
.
startsWith
(
PREFIX_AMQP
))
{
if
(
input
.
startsWith
(
PREFIX_AMQP
))
{
input
=
input
.
substring
(
PREFIX_AMQP
.
length
());
this
.
secureConnection
=
false
;
return
input
.
substring
(
PREFIX_AMQP
.
length
());
}
}
return
input
;
return
input
;
}
}
...
@@ -1036,11 +1037,11 @@ public class RabbitProperties {
...
@@ -1036,11 +1037,11 @@ public class RabbitProperties {
return
input
;
return
input
;
}
}
private
void
parseHostAndPort
(
String
input
)
{
private
void
parseHostAndPort
(
String
input
,
boolean
sslEnabled
)
{
int
portIndex
=
input
.
indexOf
(
':'
);
int
portIndex
=
input
.
indexOf
(
':'
);
if
(
portIndex
==
-
1
)
{
if
(
portIndex
==
-
1
)
{
this
.
host
=
input
;
this
.
host
=
input
;
this
.
port
=
(
this
.
secureConnection
)
?
DEFAULT_PORT_SECURE
:
DEFAULT_PORT
;
this
.
port
=
(
determineSslEnabled
(
sslEnabled
)
)
?
DEFAULT_PORT_SECURE
:
DEFAULT_PORT
;
}
}
else
{
else
{
this
.
host
=
input
.
substring
(
0
,
portIndex
);
this
.
host
=
input
.
substring
(
0
,
portIndex
);
...
@@ -1048,6 +1049,10 @@ public class RabbitProperties {
...
@@ -1048,6 +1049,10 @@ public class RabbitProperties {
}
}
}
}
private
boolean
determineSslEnabled
(
boolean
sslEnabled
)
{
return
(
this
.
secureConnection
!=
null
)
?
this
.
secureConnection
:
sslEnabled
;
}
}
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitPropertiesTests.java
View file @
a4ca1d02
...
@@ -102,6 +102,14 @@ class RabbitPropertiesTests {
...
@@ -102,6 +102,14 @@ class RabbitPropertiesTests {
assertThat
(
this
.
properties
.
determinePort
()).
isEqualTo
(
5671
);
assertThat
(
this
.
properties
.
determinePort
()).
isEqualTo
(
5671
);
}
}
@Test
void
determinePortReturnsDefaultAmqpsPortWhenFirstAddressHasNoExplicitPortButSslEnabled
()
{
this
.
properties
.
getSsl
().
setEnabled
(
true
);
this
.
properties
.
setPort
(
1234
);
this
.
properties
.
setAddresses
(
"rabbit1.example.com,rabbit2.example.com:2345"
);
assertThat
(
this
.
properties
.
determinePort
()).
isEqualTo
(
5671
);
}
@Test
@Test
void
virtualHostDefaultsToNull
()
{
void
virtualHostDefaultsToNull
()
{
assertThat
(
this
.
properties
.
getVirtualHost
()).
isNull
();
assertThat
(
this
.
properties
.
getVirtualHost
()).
isNull
();
...
@@ -241,6 +249,20 @@ class RabbitPropertiesTests {
...
@@ -241,6 +249,20 @@ class RabbitPropertiesTests {
assertThat
(
this
.
properties
.
getSsl
().
determineEnabled
()).
isTrue
();
assertThat
(
this
.
properties
.
getSsl
().
determineEnabled
()).
isTrue
();
}
}
@Test
void
sslDetermineEnabledIsTrueWhenAddressHasNoProtocolAndSslIsEnabled
()
{
this
.
properties
.
getSsl
().
setEnabled
(
true
);
this
.
properties
.
setAddresses
(
"root:password@otherhost"
);
assertThat
(
this
.
properties
.
getSsl
().
determineEnabled
()).
isTrue
();
}
@Test
void
sslDetermineEnabledIsFalseWhenAddressHasNoProtocolAndSslIsDisabled
()
{
this
.
properties
.
getSsl
().
setEnabled
(
false
);
this
.
properties
.
setAddresses
(
"root:password@otherhost"
);
assertThat
(
this
.
properties
.
getSsl
().
determineEnabled
()).
isFalse
();
}
@Test
@Test
void
determineSslUsingAmqpReturnsStateOfFirstAddress
()
{
void
determineSslUsingAmqpReturnsStateOfFirstAddress
()
{
this
.
properties
.
setAddresses
(
"amqp://root:password@otherhost,amqps://root:password2@otherhost2"
);
this
.
properties
.
setAddresses
(
"amqp://root:password@otherhost,amqps://root:password2@otherhost2"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment