@@ -36,72 +36,74 @@ class UndertowServerTest extends HttpServerTest<Undertow> implements AgentTestTr
36
36
37
37
@Override
38
38
Undertow startServer (int port ) {
39
- Undertow server = Undertow . builder()
40
- .addHttpListener(port, " localhost" )
41
- .setHandler(Handlers . path()
42
- .addExactPath(SUCCESS . rawPath()) { exchange ->
43
- controller(SUCCESS ) {
44
- exchange. getResponseSender(). send(SUCCESS . body)
45
- }
46
- }
47
- .addExactPath(QUERY_PARAM . rawPath()) { exchange ->
48
- controller(QUERY_PARAM ) {
49
- exchange. getResponseSender(). send(exchange. getQueryString())
50
- }
51
- }
52
- .addExactPath(REDIRECT . rawPath()) { exchange ->
53
- controller(REDIRECT ) {
54
- exchange. setStatusCode(StatusCodes . FOUND )
55
- exchange. getResponseHeaders(). put(Headers . LOCATION , REDIRECT . body)
56
- exchange. endExchange()
57
- }
58
- }
59
- .addExactPath(CAPTURE_HEADERS . rawPath()) { exchange ->
60
- controller(CAPTURE_HEADERS ) {
61
- exchange. setStatusCode(StatusCodes . OK )
62
- exchange. getResponseHeaders(). put(new HttpString (" X-Test-Response" ), exchange. getRequestHeaders(). getFirst(" X-Test-Request" ))
63
- exchange. getResponseSender(). send(CAPTURE_HEADERS . body)
64
- }
65
- }
66
- .addExactPath(ERROR . rawPath()) { exchange ->
67
- controller(ERROR ) {
68
- exchange. setStatusCode(ERROR . status)
69
- exchange. getResponseSender(). send(ERROR . body)
70
- }
71
- }
72
- .addExactPath(EXCEPTION . rawPath()) { exchange ->
73
- controller(EXCEPTION ) {
74
- throw new Exception (EXCEPTION . body)
75
- }
76
- }
77
- .addExactPath(INDEXED_CHILD . rawPath()) { exchange ->
78
- controller(INDEXED_CHILD ) {
79
- INDEXED_CHILD . collectSpanAttributes { name -> exchange. getQueryParameters(). get(name). peekFirst() }
80
- exchange. getResponseSender(). send(INDEXED_CHILD . body)
81
- }
82
- }
83
- .addExactPath(" sendResponse" ) { exchange ->
84
- Span . current(). addEvent(" before-event" )
85
- runWithSpan(" sendResponse" ) {
86
- exchange. setStatusCode(StatusCodes . OK )
87
- exchange. getResponseSender(). send(" sendResponse" )
88
- }
89
- // event is added only when server span has not been ended
90
- // we need to make sure that sending response does not end server span
91
- Span . current(). addEvent(" after-event" )
92
- }
93
- .addExactPath(" sendResponseWithException" ) { exchange ->
94
- Span . current(). addEvent(" before-event" )
95
- runWithSpan(" sendResponseWithException" ) {
96
- exchange. setStatusCode(StatusCodes . OK )
97
- exchange. getResponseSender(). send(" sendResponseWithException" )
98
- }
99
- // event is added only when server span has not been ended
100
- // we need to make sure that sending response does not end server span
101
- Span . current(). addEvent(" after-event" )
102
- throw new Exception (" exception after sending response" )
103
- }
104
- ). build()
39
+ Undertow.Builder builder = Undertow . builder()
40
+ .addHttpListener(port, " localhost" )
41
+ .setHandler(Handlers . path()
42
+ .addExactPath(SUCCESS . rawPath()) { exchange ->
43
+ controller(SUCCESS ) {
44
+ exchange. getResponseSender(). send(SUCCESS . body)
45
+ }
46
+ }
47
+ .addExactPath(QUERY_PARAM . rawPath()) { exchange ->
48
+ controller(QUERY_PARAM ) {
49
+ exchange. getResponseSender(). send(exchange. getQueryString())
50
+ }
51
+ }
52
+ .addExactPath(REDIRECT . rawPath()) { exchange ->
53
+ controller(REDIRECT ) {
54
+ exchange. setStatusCode(StatusCodes . FOUND )
55
+ exchange. getResponseHeaders(). put(Headers . LOCATION , REDIRECT . body)
56
+ exchange. endExchange()
57
+ }
58
+ }
59
+ .addExactPath(CAPTURE_HEADERS . rawPath()) { exchange ->
60
+ controller(CAPTURE_HEADERS ) {
61
+ exchange. setStatusCode(StatusCodes . OK )
62
+ exchange. getResponseHeaders(). put(new HttpString (" X-Test-Response" ), exchange. getRequestHeaders(). getFirst(" X-Test-Request" ))
63
+ exchange. getResponseSender(). send(CAPTURE_HEADERS . body)
64
+ }
65
+ }
66
+ .addExactPath(ERROR . rawPath()) { exchange ->
67
+ controller(ERROR ) {
68
+ exchange. setStatusCode(ERROR . status)
69
+ exchange. getResponseSender(). send(ERROR . body)
70
+ }
71
+ }
72
+ .addExactPath(EXCEPTION . rawPath()) { exchange ->
73
+ controller(EXCEPTION ) {
74
+ throw new Exception (EXCEPTION . body)
75
+ }
76
+ }
77
+ .addExactPath(INDEXED_CHILD . rawPath()) { exchange ->
78
+ controller(INDEXED_CHILD ) {
79
+ INDEXED_CHILD . collectSpanAttributes { name -> exchange. getQueryParameters(). get(name). peekFirst() }
80
+ exchange. getResponseSender(). send(INDEXED_CHILD . body)
81
+ }
82
+ }
83
+ .addExactPath(" sendResponse" ) { exchange ->
84
+ Span . current(). addEvent(" before-event" )
85
+ runWithSpan(" sendResponse" ) {
86
+ exchange. setStatusCode(StatusCodes . OK )
87
+ exchange. getResponseSender(). send(" sendResponse" )
88
+ }
89
+ // event is added only when server span has not been ended
90
+ // we need to make sure that sending response does not end server span
91
+ Span . current(). addEvent(" after-event" )
92
+ }
93
+ .addExactPath(" sendResponseWithException" ) { exchange ->
94
+ Span . current(). addEvent(" before-event" )
95
+ runWithSpan(" sendResponseWithException" ) {
96
+ exchange. setStatusCode(StatusCodes . OK )
97
+ exchange. getResponseSender(). send(" sendResponseWithException" )
98
+ }
99
+ // event is added only when server span has not been ended
100
+ // we need to make sure that sending response does not end server span
101
+ Span . current(). addEvent(" after-event" )
102
+ throw new Exception (" exception after sending response" )
103
+ }
104
+ )
105
+ configureUndertow(builder)
106
+ Undertow server = builder. build()
105
107
server. start()
106
108
return server
107
109
}
@@ -111,6 +113,9 @@ class UndertowServerTest extends HttpServerTest<Undertow> implements AgentTestTr
111
113
undertow. stop()
112
114
}
113
115
116
+ void configureUndertow (Undertow.Builder builder ) {
117
+ }
118
+
114
119
@Override
115
120
Set<AttributeKey<?> > httpAttributes (ServerEndpoint endpoint ) {
116
121
def attributes = super . httpAttributes(endpoint)
@@ -147,14 +152,15 @@ class UndertowServerTest extends HttpServerTest<Undertow> implements AgentTestTr
147
152
eventName " after-event"
148
153
}
149
154
155
+ def protocolVersion = useHttp2() ? " 2" : " 1.1"
150
156
attributes {
151
157
" $ClientAttributes . CLIENT_ADDRESS " TEST_CLIENT_IP
152
158
" $UrlAttributes . URL_SCHEME " uri. getScheme()
153
159
" $UrlAttributes . URL_PATH " uri. getPath()
154
160
" $HttpAttributes . HTTP_REQUEST_METHOD " " GET"
155
161
" $HttpAttributes . HTTP_RESPONSE_STATUS_CODE " 200
156
162
" $UserAgentAttributes . USER_AGENT_ORIGINAL " TEST_USER_AGENT
157
- " $NetworkAttributes . NETWORK_PROTOCOL_VERSION " " 1.1 "
163
+ " $NetworkAttributes . NETWORK_PROTOCOL_VERSION " protocolVersion
158
164
" $ServerAttributes . SERVER_ADDRESS " uri. host
159
165
" $ServerAttributes . SERVER_PORT " uri. port
160
166
" $NetworkAttributes . NETWORK_PEER_ADDRESS " " 127.0.0.1"
@@ -196,14 +202,15 @@ class UndertowServerTest extends HttpServerTest<Undertow> implements AgentTestTr
196
202
}
197
203
errorEvent(Exception , " exception after sending response" , 2 )
198
204
205
+ def protocolVersion = useHttp2() ? " 2" : " 1.1"
199
206
attributes {
200
207
" $ClientAttributes . CLIENT_ADDRESS " TEST_CLIENT_IP
201
208
" $UrlAttributes . URL_SCHEME " uri. getScheme()
202
209
" $UrlAttributes . URL_PATH " uri. getPath()
203
210
" $HttpAttributes . HTTP_REQUEST_METHOD " " GET"
204
211
" $HttpAttributes . HTTP_RESPONSE_STATUS_CODE " 200
205
212
" $UserAgentAttributes . USER_AGENT_ORIGINAL " TEST_USER_AGENT
206
- " $NetworkAttributes . NETWORK_PROTOCOL_VERSION " " 1.1 "
213
+ " $NetworkAttributes . NETWORK_PROTOCOL_VERSION " protocolVersion
207
214
" $ServerAttributes . SERVER_ADDRESS " uri. host
208
215
" $ServerAttributes . SERVER_PORT " uri. port
209
216
" $NetworkAttributes . NETWORK_PEER_ADDRESS " " 127.0.0.1"
0 commit comments