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
4b0fb8ff
Commit
4b0fb8ff
authored
Sep 28, 2019
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish 'Add @LocalRSocketServerPort support'
See gh-18287
parent
3c8fa3bb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
32 deletions
+42
-32
RSocketServerAutoConfigurationTests.java
...onfigure/rsocket/RSocketServerAutoConfigurationTests.java
+1
-1
LocalRSocketServerPort.java
...ramework/boot/rsocket/context/LocalRSocketServerPort.java
+1
-1
RSocketPortInfoApplicationContextInitializer.java
...context/RSocketPortInfoApplicationContextInitializer.java
+37
-27
spring.factories
.../spring-boot/src/main/resources/META-INF/spring.factories
+2
-2
LocalRSocketServerPortTests.java
...ork/boot/rsocket/context/LocalRSocketServerPortTests.java
+1
-1
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java
View file @
4b0fb8ff
...
...
@@ -19,12 +19,12 @@ package org.springframework.boot.autoconfigure.rsocket;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer
;
import
org.springframework.boot.rsocket.server.RSocketServerBootstrap
;
import
org.springframework.boot.rsocket.server.RSocketServerFactory
;
import
org.springframework.boot.rsocket.server.ServerRSocketFactoryCustomizer
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner
;
import
org.springframework.boot.web.context.RSocketPortInfoApplicationContextInitializer
;
import
org.springframework.boot.web.server.WebServerFactoryCustomizer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/
web/server
/LocalRSocketServerPort.java
→
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/
rsocket/context
/LocalRSocketServerPort.java
View file @
4b0fb8ff
...
...
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
web
.
server
;
package
org
.
springframework
.
boot
.
rsocket
.
context
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/
web
/context/RSocketPortInfoApplicationContextInitializer.java
→
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/
rsocket
/context/RSocketPortInfoApplicationContextInitializer.java
View file @
4b0fb8ff
...
...
@@ -14,13 +14,12 @@
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
web
.
context
;
package
org
.
springframework
.
boot
.
rsocket
.
context
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.rsocket.context.RSocketServerInitializedEvent
;
import
org.springframework.boot.rsocket.server.RSocketServer
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextInitializer
;
...
...
@@ -45,41 +44,52 @@ import org.springframework.core.env.PropertySource;
* @since 2.2.0
*/
public
class
RSocketPortInfoApplicationContextInitializer
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>,
ApplicationListener
<
RSocketServerInitializedEvent
>
{
private
ConfigurableApplicationContext
applicationContext
;
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>
{
@Override
public
void
initialize
(
ConfigurableApplicationContext
applicationContext
)
{
applicationContext
.
addApplicationListener
(
this
);
this
.
applicationContext
=
applicationContext
;
applicationContext
.
addApplicationListener
(
new
Listener
(
applicationContext
));
}
@Override
public
void
onApplicationEvent
(
RSocketServerInitializedEvent
event
)
{
String
propertyName
=
"local.rsocket.server.port"
;
setPortProperty
(
this
.
applicationContext
,
propertyName
,
event
.
getrSocketServer
().
address
().
getPort
());
}
private
static
class
Listener
implements
ApplicationListener
<
RSocketServerInitializedEvent
>
{
private
static
final
String
PROPERTY_NAME
=
"local.rsocket.server.port"
;
private
ConfigurableApplicationContext
applicationContext
;
Listener
(
ConfigurableApplicationContext
applicationContext
)
{
this
.
applicationContext
=
applicationContext
;
}
private
void
setPortProperty
(
ApplicationContext
context
,
String
propertyName
,
int
port
)
{
if
(
context
instanceof
ConfigurableApplicationContex
t
)
{
setPortProperty
(
((
ConfigurableApplicationContext
)
context
).
getEnvironment
(),
propertyName
,
port
);
@Override
public
void
onApplicationEvent
(
RSocketServerInitializedEvent
even
t
)
{
setPortProperty
(
this
.
applicationContext
,
event
.
getrSocketServer
().
address
().
getPort
()
);
}
if
(
context
.
getParent
()
!=
null
)
{
setPortProperty
(
context
.
getParent
(),
propertyName
,
port
);
private
void
setPortProperty
(
ApplicationContext
context
,
int
port
)
{
if
(
context
instanceof
ConfigurableApplicationContext
)
{
setPortProperty
(((
ConfigurableApplicationContext
)
context
).
getEnvironment
(),
port
);
}
if
(
context
.
getParent
()
!=
null
)
{
setPortProperty
(
context
.
getParent
(),
port
);
}
}
}
@SuppressWarnings
(
"unchecked"
)
private
void
setPortProperty
(
ConfigurableEnvironment
environment
,
String
propertyName
,
int
port
)
{
MutablePropertySources
sources
=
environment
.
getPropertySources
();
PropertySource
<?>
source
=
sources
.
get
(
"server.ports"
);
if
(
source
==
null
)
{
source
=
new
MapPropertySource
(
"server.ports"
,
new
HashMap
<>());
sources
.
addFirst
(
source
);
private
void
setPortProperty
(
ConfigurableEnvironment
environment
,
int
port
)
{
MutablePropertySources
sources
=
environment
.
getPropertySources
();
PropertySource
<?>
source
=
sources
.
get
(
"server.ports"
);
if
(
source
==
null
)
{
source
=
new
MapPropertySource
(
"server.ports"
,
new
HashMap
<>());
sources
.
addFirst
(
source
);
}
setPortProperty
(
port
,
source
);
}
((
Map
<
String
,
Object
>)
source
.
getSource
()).
put
(
propertyName
,
port
);
@SuppressWarnings
(
"unchecked"
)
private
void
setPortProperty
(
int
port
,
PropertySource
<?>
source
)
{
((
Map
<
String
,
Object
>)
source
.
getSource
()).
put
(
PROPERTY_NAME
,
port
);
}
}
}
spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories
View file @
4b0fb8ff
...
...
@@ -16,8 +16,8 @@ org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\
org.springframework.boot.context.ContextIdApplicationContextInitializer,\
org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\
org.springframework.boot.
web.context.Server
PortInfoApplicationContextInitializer,\
org.springframework.boot.web.context.
RSocket
PortInfoApplicationContextInitializer
org.springframework.boot.
rsocket.context.RSocket
PortInfoApplicationContextInitializer,\
org.springframework.boot.web.context.
Server
PortInfoApplicationContextInitializer
# Application Listeners
org.springframework.context.ApplicationListener=\
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/
web/server
/LocalRSocketServerPortTests.java
→
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/
rsocket/context
/LocalRSocketServerPortTests.java
View file @
4b0fb8ff
...
...
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
web
.
server
;
package
org
.
springframework
.
boot
.
rsocket
.
context
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
...
...
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