Skip to content

Commit

Permalink
Polish "HTTP server instrumentation TCK"
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Sep 27, 2022
1 parent 9425188 commit 7bde2f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Expand Up @@ -45,7 +45,7 @@ public abstract class HttpServerTimingInstrumentationVerificationTests extends I
* A default is provided that should be preferred by new instrumentations. Existing
* instrumentations that use a different value to maintain backwards compatibility may
* override this method to run tests with a different name used in assertions.
* @return name of the meter timing http client requests
* @return name of the meter timing http server requests
*/
protected String timerName() {
return "http.server.requests";
Expand Down
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.jetty.servlet.ServletHandler;
import org.junit.jupiter.api.Disabled;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -60,26 +59,31 @@ protected void stopInstrumentedServer() throws Exception {
public static class MyWebServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (req.getPathInfo().contentEquals("/")) {
resp.setStatus(200);
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
if (req.getPathInfo().contentEquals(InstrumentedRoutes.ROOT)) {
resp.setStatus(HttpServletResponse.SC_OK);
resp.getWriter().print("hello");
}
else if (req.getPathInfo().startsWith("/home/")) {
resp.setStatus(200);
else if (req.getPathInfo().startsWith("/hello/")) {
resp.setStatus(HttpServletResponse.SC_OK);
resp.getWriter().print("hello " + "world");
}
else if (req.getPathInfo().contentEquals("/foundRedirect")) {
else if (req.getPathInfo().contentEquals(InstrumentedRoutes.REDIRECT)) {
resp.sendRedirect("/");
}
else {
resp.sendError(400);
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPost(req, resp);
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
if (req.getPathInfo().contentEquals(InstrumentedRoutes.ERROR)) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
else {
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}

}
Expand Down

0 comments on commit 7bde2f5

Please sign in to comment.