|
7 | 7 |
|
8 | 8 | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS;
|
9 | 9 | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR;
|
10 |
| -import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; |
11 | 10 | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD;
|
12 | 11 | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM;
|
13 | 12 | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM;
|
@@ -108,17 +107,6 @@ protected HttpServer setupServer() throws IOException {
|
108 | 107 | "controller", () -> sendResponse(ctx, ERROR.getStatus(), ERROR.getBody())));
|
109 | 108 |
|
110 | 109 | contexts.add(context);
|
111 |
| - context = |
112 |
| - server.createContext( |
113 |
| - EXCEPTION.getPath(), |
114 |
| - ctx -> |
115 |
| - testing() |
116 |
| - .runWithSpan( |
117 |
| - "controller", |
118 |
| - () -> { |
119 |
| - throw new IllegalStateException(EXCEPTION.getBody()); |
120 |
| - })); |
121 |
| - contexts.add(context); |
122 | 110 | context =
|
123 | 111 | server.createContext(
|
124 | 112 | "/query",
|
@@ -221,10 +209,15 @@ public void doFilter(HttpExchange exchange, Chain chain) throws IOException {
|
221 | 209 | }
|
222 | 210 | exchange.getResponseHeaders().set("decoratingfunction", "ok");
|
223 | 211 | exchange.getResponseHeaders().set("decoratinghttpservicefunction", "ok");
|
224 |
| - chain.doFilter(exchange); |
225 | 212 |
|
226 |
| - // server will hang if nothing is sent |
| 213 | + try { |
| 214 | + chain.doFilter(exchange); |
| 215 | + } catch (Exception e) { |
| 216 | + sendResponse(exchange, 500, e.getMessage()); |
| 217 | + } |
| 218 | + |
227 | 219 | if (exchange.getResponseCode() == -1) {
|
| 220 | + |
228 | 221 | sendResponse(exchange, 500, "nothing");
|
229 | 222 | }
|
230 | 223 | }
|
|
0 commit comments