Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
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
openSource
spring-cloud-netflix
Commits
a81eb771
Unverified
Commit
a81eb771
authored
Jan 26, 2018
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates for new HttpTraceRepository
parent
acf42797
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
44 deletions
+98
-44
ZuulProxyAutoConfiguration.java
...mework/cloud/netflix/zuul/ZuulProxyAutoConfiguration.java
+2
-2
TraceProxyRequestHelper.java
...k/cloud/netflix/zuul/filters/TraceProxyRequestHelper.java
+71
-7
FormZuulProxyApplicationTests.java
...ork/cloud/netflix/zuul/FormZuulProxyApplicationTests.java
+4
-13
FormZuulServletProxyApplicationTests.java
...ud/netflix/zuul/FormZuulServletProxyApplicationTests.java
+4
-13
ProxyRequestHelperTests.java
...k/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java
+9
-9
TestAutoConfiguration.java
...mework/cloud/netflix/zuul/test/TestAutoConfiguration.java
+8
-0
No files found.
spring-cloud-netflix-zuul/src/main/java/org/springframework/cloud/netflix/zuul/ZuulProxyAutoConfiguration.java
View file @
a81eb771
...
...
@@ -23,7 +23,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.
trace.
TraceRepository
;
import
org.springframework.boot.actuate.
web.trace.Http
TraceRepository
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
...
...
@@ -163,7 +163,7 @@ public class ZuulProxyAutoConfiguration extends ZuulServerAutoConfiguration {
protected
static
class
EndpointConfiguration
{
@Autowired
(
required
=
false
)
private
TraceRepository
traces
;
private
Http
TraceRepository
traces
;
@Bean
@ConditionalOnEnabledEndpoint
...
...
spring-cloud-netflix-zuul/src/main/java/org/springframework/cloud/netflix/zuul/filters/TraceProxyRequestHelper.java
View file @
a81eb771
...
...
@@ -20,26 +20,37 @@ package org.springframework.cloud.netflix.zuul.filters;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.net.URI
;
import
java.nio.charset.Charset
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Enumeration
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
org.springframework.boot.actuate.trace.TraceRepository
;
import
org.springframework.boot.actuate.web.trace.HttpExchangeTracer
;
import
org.springframework.boot.actuate.web.trace.HttpTrace
;
import
org.springframework.boot.actuate.web.trace.HttpTraceRepository
;
import
org.springframework.boot.actuate.web.trace.Include
;
import
org.springframework.boot.actuate.web.trace.TraceableRequest
;
import
org.springframework.util.MultiValueMap
;
import
com.netflix.zuul.context.RequestContext
;
import
org.springframework.util.StringUtils
;
import
javax.servlet.http.HttpServletRequest
;
/**
* @author Spencer Gibb
*/
public
class
TraceProxyRequestHelper
extends
ProxyRequestHelper
{
private
TraceRepository
traces
;
private
HttpTraceRepository
traces
;
private
final
HttpExchangeTracer
tracer
=
new
HttpExchangeTracer
(
Include
.
defaultIncludes
());
public
void
setTraces
(
TraceRepository
traces
)
{
public
void
setTraces
(
Http
TraceRepository
traces
)
{
this
.
traces
=
traces
;
}
...
...
@@ -60,19 +71,72 @@ public class TraceProxyRequestHelper extends ProxyRequestHelper {
trace
.
put
(
"request"
,
input
);
info
.
put
(
"headers"
,
trace
);
debugHeaders
(
headers
,
input
);
RequestContext
ctx
=
RequestContext
.
getCurrentContex
t
();
if
(
shouldDebugBody
(
c
tx
))
{
HttpServletRequest
request
=
context
.
getReques
t
();
if
(
shouldDebugBody
(
c
ontext
))
{
// Prevent input stream from being read if it needs to go downstream
if
(
requestEntity
!=
null
)
{
debugRequestEntity
(
info
,
ctx
.
getRequest
()
.
getInputStream
());
debugRequestEntity
(
info
,
request
.
getInputStream
());
}
}
this
.
traces
.
add
(
info
);
HttpTrace
httpTrace
=
tracer
.
receivedRequest
(
new
ServletTraceableRequest
(
request
));
this
.
traces
.
add
(
httpTrace
);
return
info
;
}
return
info
;
}
private
class
ServletTraceableRequest
implements
TraceableRequest
{
private
HttpServletRequest
request
;
public
ServletTraceableRequest
(
HttpServletRequest
request
)
{
this
.
request
=
request
;
}
@Override
public
String
getMethod
()
{
return
request
.
getMethod
();
}
@Override
public
URI
getUri
()
{
StringBuffer
urlBuffer
=
request
.
getRequestURL
();
if
(
StringUtils
.
hasText
(
request
.
getQueryString
()))
{
urlBuffer
.
append
(
"?"
);
urlBuffer
.
append
(
request
.
getQueryString
());
}
return
URI
.
create
(
urlBuffer
.
toString
());
}
@Override
public
Map
<
String
,
List
<
String
>>
getHeaders
()
{
return
extractHeaders
();
}
@Override
public
String
getRemoteAddress
()
{
return
request
.
getRemoteAddr
();
}
private
Map
<
String
,
List
<
String
>>
extractHeaders
()
{
Map
<
String
,
List
<
String
>>
headers
=
new
LinkedHashMap
<>();
Enumeration
<
String
>
names
=
request
.
getHeaderNames
();
while
(
names
.
hasMoreElements
())
{
String
name
=
names
.
nextElement
();
headers
.
put
(
name
,
toList
(
request
.
getHeaders
(
name
)));
}
return
headers
;
}
private
List
<
String
>
toList
(
Enumeration
<
String
>
enumeration
)
{
List
<
String
>
list
=
new
ArrayList
<>();
while
(
enumeration
.
hasMoreElements
())
{
list
.
add
(
enumeration
.
nextElement
());
}
return
list
;
}
}
void
debugHeaders
(
MultiValueMap
<
String
,
String
>
headers
,
Map
<
String
,
Object
>
map
)
{
for
(
Entry
<
String
,
List
<
String
>>
entry
:
headers
.
entrySet
())
{
Collection
<
String
>
collection
=
entry
.
getValue
();
...
...
spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulProxyApplicationTests.java
View file @
a81eb771
...
...
@@ -18,7 +18,6 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
;
import
java.io.IOException
;
import
java.util.Map
;
import
javax.inject.Inject
;
import
javax.servlet.http.Part
;
...
...
@@ -27,8 +26,8 @@ import org.junit.After;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.actuate.
trace.InMemory
TraceRepository
;
import
org.springframework.boot.actuate.
trace.
TraceRepository
;
import
org.springframework.boot.actuate.
web.trace.Http
TraceRepository
;
import
org.springframework.boot.actuate.
web.trace.InMemoryHttp
TraceRepository
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
...
...
@@ -289,16 +288,8 @@ class FormZuulProxyApplication {
}
@Bean
public
TraceRepository
traceRepository
()
{
return
new
InMemoryTraceRepository
()
{
@Override
public
void
add
(
Map
<
String
,
Object
>
map
)
{
if
(
map
.
containsKey
(
"body"
))
{
map
.
get
(
"body"
);
}
super
.
add
(
map
);
}
};
public
HttpTraceRepository
traceRepository
()
{
return
new
InMemoryHttpTraceRepository
();
}
public
static
void
main
(
String
[]
args
)
{
...
...
spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulServletProxyApplicationTests.java
View file @
a81eb771
...
...
@@ -19,7 +19,6 @@ package org.springframework.cloud.netflix.zuul;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Map
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
...
...
@@ -28,8 +27,8 @@ import org.junit.Before;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.
trace.InMemory
TraceRepository
;
import
org.springframework.boot.actuate.
trace.
TraceRepository
;
import
org.springframework.boot.actuate.
web.trace.Http
TraceRepository
;
import
org.springframework.boot.actuate.
web.trace.InMemoryHttp
TraceRepository
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
...
...
@@ -205,16 +204,8 @@ class FormZuulServletProxyApplication {
}
@Bean
public
TraceRepository
traceRepository
()
{
return
new
InMemoryTraceRepository
()
{
@Override
public
void
add
(
Map
<
String
,
Object
>
map
)
{
if
(
map
.
containsKey
(
"body"
))
{
map
.
get
(
"body"
);
}
super
.
add
(
map
);
}
};
public
HttpTraceRepository
traceRepository
()
{
return
new
InMemoryHttpTraceRepository
();
}
}
...
...
spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java
View file @
a81eb771
...
...
@@ -21,14 +21,15 @@ import java.util.List;
import
com.netflix.zuul.context.RequestContext
;
import
org.assertj.core.api.Assertions
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.Mock
;
import
org.springframework.boot.actuate.
trace.InMemoryTraceRepository
;
import
org.springframework.boot.actuate.
trace.Trace
;
import
org.springframework.boot.actuate.
trace.
TraceRepository
;
import
org.springframework.boot.actuate.
web.trace.HttpTrace
;
import
org.springframework.boot.actuate.
web.trace.HttpTraceRepository
;
import
org.springframework.boot.actuate.
web.trace.InMemoryHttp
TraceRepository
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.mock.web.MockHttpServletRequest
;
...
...
@@ -53,7 +54,7 @@ import static org.springframework.cloud.netflix.zuul.filters.support.FilterConst
public
class
ProxyRequestHelperTests
{
@Mock
private
TraceRepository
traceRepository
;
private
Http
TraceRepository
traceRepository
;
@Before
public
void
init
()
{
...
...
@@ -81,16 +82,15 @@ public class ProxyRequestHelperTests {
RequestContext
.
getCurrentContext
().
setRequest
(
request
);
TraceProxyRequestHelper
helper
=
new
TraceProxyRequestHelper
();
this
.
traceRepository
=
new
InMemoryTraceRepository
();
this
.
traceRepository
=
new
InMemory
Http
TraceRepository
();
helper
.
setTraces
(
this
.
traceRepository
);
MultiValueMap
<
String
,
String
>
headers
=
helper
.
buildZuulRequestHeaders
(
request
);
helper
.
debug
(
"POST"
,
"http://example.com"
,
headers
,
new
LinkedMultiValueMap
<
String
,
String
>(),
request
.
getInputStream
());
Trace
actual
=
this
.
traceRepository
.
findAll
().
get
(
0
);
assertThat
((
String
)
actual
.
getInfo
().
get
(
"body"
),
equalTo
(
"{}"
));
new
LinkedMultiValueMap
<>(),
request
.
getInputStream
());
HttpTrace
actual
=
this
.
traceRepository
.
findAll
().
get
(
0
);
Assertions
.
assertThat
(
actual
.
getRequest
().
getHeaders
()).
containsKeys
(
"singleName"
,
"multiName"
);
}
@Test
...
...
spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/test/TestAutoConfiguration.java
View file @
a81eb771
...
...
@@ -24,7 +24,9 @@ import org.springframework.context.annotation.Import;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.builders.WebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.web.firewall.StrictHttpFirewall
;
/**
* @author Spencer Gibb
...
...
@@ -43,6 +45,12 @@ public class TestAutoConfiguration {
super
(
true
);
}
@Override
public
void
configure
(
WebSecurity
web
)
throws
Exception
{
StrictHttpFirewall
httpFirewall
=
new
StrictHttpFirewall
();
httpFirewall
.
setAllowSemicolon
(
true
);
web
.
httpFirewall
(
httpFirewall
);
}
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
...
...
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