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
64a74c3b
Commit
64a74c3b
authored
Feb 27, 2019
by
Dmytro Nosan
Committed by
Stephane Nicoll
Feb 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix NullPointerException with empty X-Forwarded-For header
See gh-16046
parent
0c1efe3a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
3 deletions
+111
-3
ServerWebExchangeTraceableRequest.java
...web/trace/reactive/ServerWebExchangeTraceableRequest.java
+10
-3
ServerWebExchangeTraceableRequestTests.java
...race/reactive/ServerWebExchangeTraceableRequestTests.java
+101
-0
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/trace/reactive/ServerWebExchangeTraceableRequest.java
View file @
64a74c3b
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
actuate
.
web
.
trace
.
reactive
;
import
java.net.InetAddress
;
import
java.net.InetSocketAddress
;
import
java.net.URI
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
...
...
@@ -45,8 +47,7 @@ class ServerWebExchangeTraceableRequest implements TraceableRequest {
this
.
method
=
request
.
getMethodValue
();
this
.
headers
=
request
.
getHeaders
();
this
.
uri
=
request
.
getURI
();
this
.
remoteAddress
=
(
request
.
getRemoteAddress
()
!=
null
)
?
request
.
getRemoteAddress
().
getAddress
().
toString
()
:
null
;
this
.
remoteAddress
=
getRemoteAddress
(
request
);
}
@Override
...
...
@@ -69,4 +70,10 @@ class ServerWebExchangeTraceableRequest implements TraceableRequest {
return
this
.
remoteAddress
;
}
private
static
String
getRemoteAddress
(
ServerHttpRequest
request
)
{
InetSocketAddress
remoteAddress
=
request
.
getRemoteAddress
();
InetAddress
address
=
(
remoteAddress
!=
null
)
?
remoteAddress
.
getAddress
()
:
null
;
return
(
address
!=
null
)
?
address
.
toString
()
:
null
;
}
}
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/trace/reactive/ServerWebExchangeTraceableRequestTests.java
0 → 100644
View file @
64a74c3b
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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
.
boot
.
actuate
.
web
.
trace
.
reactive
;
import
java.net.InetSocketAddress
;
import
java.net.URI
;
import
java.util.Collections
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.web.server.ServerWebExchange
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
entry
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link ServerWebExchangeTraceableRequest}.
*
* @author Dmytro Nosan
*/
public
class
ServerWebExchangeTraceableRequestTests
{
private
ServerWebExchange
exchange
;
private
ServerHttpRequest
request
;
@Before
public
void
setUp
()
{
this
.
exchange
=
mock
(
ServerWebExchange
.
class
);
this
.
request
=
mock
(
ServerHttpRequest
.
class
);
doReturn
(
this
.
request
).
when
(
this
.
exchange
).
getRequest
();
}
@Test
public
void
getMethod
()
{
String
method
=
"POST"
;
doReturn
(
method
).
when
(
this
.
request
).
getMethodValue
();
ServerWebExchangeTraceableRequest
traceableRequest
=
new
ServerWebExchangeTraceableRequest
(
this
.
exchange
);
assertThat
(
traceableRequest
.
getMethod
()).
isSameAs
(
method
);
}
@Test
public
void
getUri
()
{
URI
uri
=
URI
.
create
(
"http://localhost:8080/"
);
doReturn
(
uri
).
when
(
this
.
request
).
getURI
();
ServerWebExchangeTraceableRequest
traceableRequest
=
new
ServerWebExchangeTraceableRequest
(
this
.
exchange
);
assertThat
(
traceableRequest
.
getUri
()).
isSameAs
(
uri
);
}
@Test
public
void
getHeaders
()
{
HttpHeaders
httpHeaders
=
new
HttpHeaders
();
httpHeaders
.
add
(
"name"
,
"value"
);
doReturn
(
httpHeaders
).
when
(
this
.
request
).
getHeaders
();
ServerWebExchangeTraceableRequest
traceableRequest
=
new
ServerWebExchangeTraceableRequest
(
this
.
exchange
);
assertThat
(
traceableRequest
.
getHeaders
())
.
containsOnly
(
entry
(
"name"
,
Collections
.
singletonList
(
"value"
)));
}
@Test
public
void
getUnresolvedRemoteAddress
()
{
InetSocketAddress
socketAddress
=
InetSocketAddress
.
createUnresolved
(
""
,
0
);
doReturn
(
socketAddress
).
when
(
this
.
request
).
getRemoteAddress
();
ServerWebExchangeTraceableRequest
traceableRequest
=
new
ServerWebExchangeTraceableRequest
(
this
.
exchange
);
assertThat
(
traceableRequest
.
getRemoteAddress
()).
isNull
();
}
@Test
public
void
getRemoteAddress
()
{
InetSocketAddress
socketAddress
=
new
InetSocketAddress
(
0
);
doReturn
(
socketAddress
).
when
(
this
.
request
).
getRemoteAddress
();
ServerWebExchangeTraceableRequest
traceableRequest
=
new
ServerWebExchangeTraceableRequest
(
this
.
exchange
);
assertThat
(
traceableRequest
.
getRemoteAddress
())
.
isEqualTo
(
socketAddress
.
getAddress
().
toString
());
}
}
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