Remove test exclusion for Tomcat testErrorBody
MODIFY
instrumentation/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat7/TestServlet.java
instrumentation/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat7/TestServlet.java
@@ -29,7 +29,7 @@ public class TestServlet extends HttpServlet {
if (serverEndpoint == HttpServerTest.ServerEndpoint.REDIRECT) {
resp.sendRedirect(serverEndpoint.getBody());
} else if (serverEndpoint == HttpServerTest.ServerEndpoint.ERROR) {
- resp.sendError(serverEndpoint.getStatus());
+ resp.sendError(serverEndpoint.getStatus(), serverEndpoint.getBody());
} else {
resp.setStatus(serverEndpoint.getStatus());
}

MODIFY
instrumentation/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat7/TomcatHandlerTest.groovy
instrumentation/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat7/TomcatHandlerTest.groovy
@@ -12,7 +12,11 @@ import io.opentelemetry.instrumentation.test.AgentTestTrait
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
import io.opentelemetry.instrumentation.test.base.HttpServerTest
import org.apache.catalina.Context
+import org.apache.catalina.connector.Request
+import org.apache.catalina.connector.Response
+import org.apache.catalina.core.StandardHost
import org.apache.catalina.startup.Tomcat
+import org.apache.catalina.valves.ErrorReportValve
class TomcatHandlerTest extends HttpServerTest<Tomcat> implements AgentTestTrait {
@@ -41,6 +45,9 @@ class TomcatHandlerTest extends HttpServerTest<Tomcat> implements AgentTestTrait
ServerEndpoint.values().each {
ctx.addServletMappingDecoded(it.path, "testServlet")
}
+
+ (tomcat.host as StandardHost).errorReportValveClass = ErrorHandlerValve.name
+
tomcat.start()
return tomcat
@@ -56,11 +63,6 @@ class TomcatHandlerTest extends HttpServerTest<Tomcat> implements AgentTestTrait
endpoint == REDIRECT || endpoint == ERROR
}
- @Override
- boolean testErrorBody() {
- false
- }
-
@Override
void responseSpan(TraceAssert trace, int index, Object parent, String method, ServerEndpoint endpoint) {
switch (endpoint) {
@@ -73,3 +75,17 @@ class TomcatHandlerTest extends HttpServerTest<Tomcat> implements AgentTestTrait
}
}
}
+
+class ErrorHandlerValve extends ErrorReportValve {
+ @Override
+ protected void report(Request request, Response response, Throwable t) {
+ if (response.getStatus() < 400 || response.getContentWritten() > 0 || !response.setErrorReported()) {
+ return
+ }
+ try {
+ response.writer.print(t ? t.cause.message : response.message)
+ } catch (IOException e) {
+ e.printStackTrace()
+ }
+ }
+}

Remove test exclusion for Tomcat testErrorBody (#2657)