From 602fde15076b162e306b758701771357196e7c72 Mon Sep 17 00:00:00 2001 From: Shashank Patidar Date: Thu, 28 Jan 2021 13:58:17 +0530 Subject: [PATCH 1/4] adding struts2.3 framework support tests --- instrumentation/struts-2.3/build.gradle.kts | 25 +++ .../hypertrace/struts/Struts2Action.java | 49 ++++++ .../struts/StrutsInstrumentationTest.java | 142 ++++++++++++++++++ .../struts-2.3/src/test/resources/struts.xml | 30 ++++ settings.gradle.kts | 2 + 5 files changed, 248 insertions(+) create mode 100644 instrumentation/struts-2.3/build.gradle.kts create mode 100644 instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java create mode 100644 instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java create mode 100644 instrumentation/struts-2.3/src/test/resources/struts.xml diff --git a/instrumentation/struts-2.3/build.gradle.kts b/instrumentation/struts-2.3/build.gradle.kts new file mode 100644 index 000000000..a3f40c684 --- /dev/null +++ b/instrumentation/struts-2.3/build.gradle.kts @@ -0,0 +1,25 @@ +plugins { + `java-library` + id("io.opentelemetry.instrumentation.auto-instrumentation") +} + +repositories { + mavenCentral() +} +val versions: Map by extra +dependencies { + api("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-3.0:${versions["opentelemetry_java_agent"]}") + testImplementation("junit:junit:4.12") + testImplementation("org.apache.struts:struts2-core:2.3.1") + testImplementation("org.apache.struts:struts2-json-plugin:2.3.1") + testImplementation("org.apache.struts:struts2-convention-plugin:2.3.1") + testImplementation("org.eclipse.jetty:jetty-server:8.0.0.v20110901") + testImplementation("org.eclipse.jetty:jetty-servlet:8.0.0.v20110901") + testImplementation("javax.servlet:javax.servlet-api:3.0.1") + testImplementation("javax.servlet:jsp-api:2.0") + testImplementation(project(":testing-common")) { + exclude(group ="org.eclipse.jetty", module= "jetty-server") + } + testImplementation(project(":instrumentation:servlet:servlet-rw")) + testImplementation(project(":instrumentation:servlet:servlet-3.0-no-wrapping")) +} diff --git a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java new file mode 100644 index 000000000..0e9044085 --- /dev/null +++ b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java @@ -0,0 +1,49 @@ +/* + * Copyright The Hypertrace Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opentelemetry.javaagent.instrumentation.hypertrace.struts; + +import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.convention.annotation.ParentPackage; +import org.apache.struts2.convention.annotation.Result; + +import java.io.IOException; + +@Result(type = "json") +@ParentPackage("json-default") +public class Struts2Action extends ActionSupport { + + private String jsonString; + + public static String sample = "{'balance':1000.21,'is_vip':true,'num':100,'name':'foo'}"; + + public String body() throws IOException { + jsonString = sample; + return "body"; + } + + public String headers() { + return "headers"; + } + + public String getJsonString() { + return jsonString; + } + + public void setJsonString(String jsonString) { + this.jsonString = jsonString; + } +} diff --git a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java new file mode 100644 index 000000000..238cdb346 --- /dev/null +++ b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java @@ -0,0 +1,142 @@ +/* + * Copyright The Hypertrace Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opentelemetry.javaagent.instrumentation.hypertrace.struts; + +import java.io.IOException; +import java.util.EnumSet; +import java.util.List; +import java.util.concurrent.TimeoutException; +import javax.servlet.DispatcherType; + +import io.opentelemetry.sdk.trace.data.SpanData; +import okhttp3.MediaType; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.DefaultServlet; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.util.resource.FileResource; +import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes; +import org.hypertrace.agent.testing.AbstractInstrumenterTest; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class StrutsInstrumentationTest extends AbstractInstrumenterTest { + + private static final String REQUEST_BODY = "hello"; + private static final String REQUEST_HEADER = "requestheader"; + private static final String REQUEST_HEADER_VALUE = "requestvalue"; + private static final String RESPONSE_HEADER = "headerName"; + private static final String RESPONSE_HEADER_VALUE = "headerValue"; + + private static Server server = new Server(0); + private static int serverPort; + + @BeforeAll + public static void startServer() throws Exception { + ServletContextHandler handler = new ServletContextHandler(); + FileResource resource = new FileResource(StrutsInstrumentationTest.class.getResource("/")); + handler.setContextPath("/context"); + handler.setBaseResource(resource); + handler.addServlet(DefaultServlet.class, "/"); + handler.addFilter(StrutsPrepareAndExecuteFilter.class, "/*", EnumSet.allOf(DispatcherType.class)); + server.setHandler(handler); + server.start(); + serverPort = server.getConnectors()[0].getLocalPort(); + } + + @AfterAll + public static void stopServer() throws Exception { + server.stop(); + } + + @Test + public void testBody() throws IOException, TimeoutException, InterruptedException { + Request request = + new Request.Builder() + .url(String.format("http://localhost:%d/context/body", serverPort)) + .post(RequestBody.create(REQUEST_BODY, MediaType.get("application/x-www-form-urlencoded"))) + .build(); + try (Response response = httpClient.newCall(request).execute()) { + assertEquals(200, response.code()); + } + + TEST_WRITER.waitForTraces(1); + List> traces = TEST_WRITER.getTraces(); + assertEquals(1, traces.size()); + List spans = traces.get(0); + assertEquals(1, spans.size()); + SpanData spanData = spans.get(0); + assertEquals("\"" + Struts2Action.sample + "\"", spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY)); + assertEquals(REQUEST_BODY, spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_REQUEST_BODY)); + } + + @Test + public void testHeaders() throws IOException, TimeoutException, InterruptedException { + Request request = + new Request.Builder() + .url(String.format("http://localhost:%d/context/headers", serverPort)) + .get() + .header(REQUEST_HEADER, REQUEST_HEADER_VALUE) + .build(); + try (Response response = httpClient.newCall(request).execute()) { + assertEquals(200, response.code()); + } + + TEST_WRITER.waitForTraces(1); + List> traces = TEST_WRITER.getTraces(); + assertEquals(1, traces.size()); + List spans = traces.get(0); + assertEquals(1, spans.size()); + SpanData spanData = spans.get(0); + assertEquals(RESPONSE_HEADER_VALUE, spanData.getAttributes().get(HypertraceSemanticAttributes.httpResponseHeader(RESPONSE_HEADER))); + assertEquals(REQUEST_HEADER_VALUE, spanData.getAttributes().get(HypertraceSemanticAttributes.httpRequestHeader(REQUEST_HEADER))); + } + + @Test + public void testBlocking() throws IOException, TimeoutException, InterruptedException { + Request request = + new Request.Builder() + .url(String.format("http://localhost:%d/context/body", serverPort)) + .get() + .header("mockblock", "true") + .build(); + try (Response response = httpClient.newCall(request).execute()) { + Assertions.assertEquals(403, response.code()); + } + + TEST_WRITER.waitForTraces(1); + List> traces = TEST_WRITER.getTraces(); + Assertions.assertEquals(1, traces.size()); + List spans = traces.get(0); + Assertions.assertEquals(1, spans.size()); + SpanData spanData = spans.get(0); + Assertions.assertNull( + spanData.getAttributes().get(HypertraceSemanticAttributes.httpResponseHeader(RESPONSE_HEADER))); + Assertions.assertNull( + spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_REQUEST_BODY)); + Assertions.assertNull( + spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY)); + } + +} diff --git a/instrumentation/struts-2.3/src/test/resources/struts.xml b/instrumentation/struts-2.3/src/test/resources/struts.xml new file mode 100644 index 000000000..45385f54e --- /dev/null +++ b/instrumentation/struts-2.3/src/test/resources/struts.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + headerValue + + + + + + + + + true + true + jsonString + + + + + \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 56a32c81d..38dd36f31 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -59,3 +59,5 @@ include("instrumentation:servlet:servlet-3.0-no-wrapping") findProject(":instrumentation:servlet:servlet-3.0-no-wrapping")?.name = "servlet-3.0-no-wrapping" include("instrumentation:servlet:servlet-rw") findProject(":instrumentation:servlet:servlet-rw")?.name = "servlet-rw" +include("instrumentation:struts-2.3") +findProject(":instrumentation:struts-2.3")?.name = "struts-2.3" From feb48cc5007893e58b44001281be42b7befed8af Mon Sep 17 00:00:00 2001 From: Shashank Patidar Date: Thu, 28 Jan 2021 14:04:03 +0530 Subject: [PATCH 2/4] spotless apply for build --- .../hypertrace/struts/Struts2Action.java | 3 +- .../struts/StrutsInstrumentationTest.java | 62 ++++++++++++------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java index 0e9044085..6b82ccc1f 100644 --- a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java +++ b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java @@ -17,11 +17,10 @@ package io.opentelemetry.javaagent.instrumentation.hypertrace.struts; import com.opensymphony.xwork2.ActionSupport; +import java.io.IOException; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; -import java.io.IOException; - @Result(type = "json") @ParentPackage("json-default") public class Struts2Action extends ActionSupport { diff --git a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java index 238cdb346..d240f935c 100644 --- a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java +++ b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java @@ -16,13 +16,14 @@ package io.opentelemetry.javaagent.instrumentation.hypertrace.struts; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import io.opentelemetry.sdk.trace.data.SpanData; import java.io.IOException; import java.util.EnumSet; import java.util.List; import java.util.concurrent.TimeoutException; import javax.servlet.DispatcherType; - -import io.opentelemetry.sdk.trace.data.SpanData; import okhttp3.MediaType; import okhttp3.Request; import okhttp3.RequestBody; @@ -39,8 +40,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class StrutsInstrumentationTest extends AbstractInstrumenterTest { private static final String REQUEST_BODY = "hello"; @@ -59,7 +58,8 @@ public static void startServer() throws Exception { handler.setContextPath("/context"); handler.setBaseResource(resource); handler.addServlet(DefaultServlet.class, "/"); - handler.addFilter(StrutsPrepareAndExecuteFilter.class, "/*", EnumSet.allOf(DispatcherType.class)); + handler.addFilter( + StrutsPrepareAndExecuteFilter.class, "/*", EnumSet.allOf(DispatcherType.class)); server.setHandler(handler); server.start(); serverPort = server.getConnectors()[0].getLocalPort(); @@ -75,7 +75,9 @@ public void testBody() throws IOException, TimeoutException, InterruptedExceptio Request request = new Request.Builder() .url(String.format("http://localhost:%d/context/body", serverPort)) - .post(RequestBody.create(REQUEST_BODY, MediaType.get("application/x-www-form-urlencoded"))) + .post( + RequestBody.create( + REQUEST_BODY, MediaType.get("application/x-www-form-urlencoded"))) .build(); try (Response response = httpClient.newCall(request).execute()) { assertEquals(200, response.code()); @@ -87,18 +89,21 @@ public void testBody() throws IOException, TimeoutException, InterruptedExceptio List spans = traces.get(0); assertEquals(1, spans.size()); SpanData spanData = spans.get(0); - assertEquals("\"" + Struts2Action.sample + "\"", spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY)); - assertEquals(REQUEST_BODY, spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_REQUEST_BODY)); + assertEquals( + "\"" + Struts2Action.sample + "\"", + spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY)); + assertEquals( + REQUEST_BODY, spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_REQUEST_BODY)); } @Test public void testHeaders() throws IOException, TimeoutException, InterruptedException { Request request = - new Request.Builder() - .url(String.format("http://localhost:%d/context/headers", serverPort)) - .get() - .header(REQUEST_HEADER, REQUEST_HEADER_VALUE) - .build(); + new Request.Builder() + .url(String.format("http://localhost:%d/context/headers", serverPort)) + .get() + .header(REQUEST_HEADER, REQUEST_HEADER_VALUE) + .build(); try (Response response = httpClient.newCall(request).execute()) { assertEquals(200, response.code()); } @@ -109,18 +114,26 @@ public void testHeaders() throws IOException, TimeoutException, InterruptedExcep List spans = traces.get(0); assertEquals(1, spans.size()); SpanData spanData = spans.get(0); - assertEquals(RESPONSE_HEADER_VALUE, spanData.getAttributes().get(HypertraceSemanticAttributes.httpResponseHeader(RESPONSE_HEADER))); - assertEquals(REQUEST_HEADER_VALUE, spanData.getAttributes().get(HypertraceSemanticAttributes.httpRequestHeader(REQUEST_HEADER))); + assertEquals( + RESPONSE_HEADER_VALUE, + spanData + .getAttributes() + .get(HypertraceSemanticAttributes.httpResponseHeader(RESPONSE_HEADER))); + assertEquals( + REQUEST_HEADER_VALUE, + spanData + .getAttributes() + .get(HypertraceSemanticAttributes.httpRequestHeader(REQUEST_HEADER))); } @Test public void testBlocking() throws IOException, TimeoutException, InterruptedException { Request request = - new Request.Builder() - .url(String.format("http://localhost:%d/context/body", serverPort)) - .get() - .header("mockblock", "true") - .build(); + new Request.Builder() + .url(String.format("http://localhost:%d/context/body", serverPort)) + .get() + .header("mockblock", "true") + .build(); try (Response response = httpClient.newCall(request).execute()) { Assertions.assertEquals(403, response.code()); } @@ -132,11 +145,12 @@ public void testBlocking() throws IOException, TimeoutException, InterruptedExce Assertions.assertEquals(1, spans.size()); SpanData spanData = spans.get(0); Assertions.assertNull( - spanData.getAttributes().get(HypertraceSemanticAttributes.httpResponseHeader(RESPONSE_HEADER))); + spanData + .getAttributes() + .get(HypertraceSemanticAttributes.httpResponseHeader(RESPONSE_HEADER))); Assertions.assertNull( - spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_REQUEST_BODY)); + spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_REQUEST_BODY)); Assertions.assertNull( - spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY)); + spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY)); } - } From c3abb8d97f3ca610a76eb1767fff2b406cadee13 Mon Sep 17 00:00:00 2001 From: Shashank Patidar Date: Thu, 28 Jan 2021 19:11:27 +0530 Subject: [PATCH 3/4] polishing, review comments --- README.md | 1 + instrumentation/struts-2.3/build.gradle.kts | 24 ++++++++++++------- .../hypertrace/struts/Struts2Action.java | 2 +- .../struts/StrutsInstrumentationTest.java | 6 ++--- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 34dc9c2d4..774f0dab5 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ List of supported frameworks with additional capabilities: | [Spark Web Framework](https://github.com/perwendel/spark) | 2.3+ | | [Spring Webflux](https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/reactive/package-summary.html) | 5.0+ | | [Vert.x](https://vertx.io) | 3.0+ | +| [Struts](https://struts.apache.org/) | 2.3+ | ### Adding custom filter implementation diff --git a/instrumentation/struts-2.3/build.gradle.kts b/instrumentation/struts-2.3/build.gradle.kts index a3f40c684..27ff5c03d 100644 --- a/instrumentation/struts-2.3/build.gradle.kts +++ b/instrumentation/struts-2.3/build.gradle.kts @@ -1,15 +1,26 @@ plugins { `java-library` id("io.opentelemetry.instrumentation.auto-instrumentation") + muzzle } -repositories { - mavenCentral() +muzzle { + pass { + group = "org.apache.struts" + module = "struts2-core" + versions = "[2.3.1,)" + } } + val versions: Map by extra + dependencies { - api("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-3.0:${versions["opentelemetry_java_agent"]}") - testImplementation("junit:junit:4.12") + testImplementation(project(":instrumentation:servlet:servlet-rw")) + testImplementation(project(":instrumentation:servlet:servlet-3.0-no-wrapping")) + testImplementation(project(":testing-common")) { + exclude(group ="org.eclipse.jetty", module= "jetty-server") + } + testImplementation("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-3.0:${versions["opentelemetry_java_agent"]}") testImplementation("org.apache.struts:struts2-core:2.3.1") testImplementation("org.apache.struts:struts2-json-plugin:2.3.1") testImplementation("org.apache.struts:struts2-convention-plugin:2.3.1") @@ -17,9 +28,4 @@ dependencies { testImplementation("org.eclipse.jetty:jetty-servlet:8.0.0.v20110901") testImplementation("javax.servlet:javax.servlet-api:3.0.1") testImplementation("javax.servlet:jsp-api:2.0") - testImplementation(project(":testing-common")) { - exclude(group ="org.eclipse.jetty", module= "jetty-server") - } - testImplementation(project(":instrumentation:servlet:servlet-rw")) - testImplementation(project(":instrumentation:servlet:servlet-3.0-no-wrapping")) } diff --git a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java index 6b82ccc1f..eb4891ea4 100644 --- a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java +++ b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java @@ -27,7 +27,7 @@ public class Struts2Action extends ActionSupport { private String jsonString; - public static String sample = "{'balance':1000.21,'is_vip':true,'num':100,'name':'foo'}"; + static final String sample = "{'balance':1000.21,'is_vip':true,'num':100,'name':'foo'}"; public String body() throws IOException { jsonString = sample; diff --git a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java index d240f935c..0acc67bb8 100644 --- a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java +++ b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java @@ -71,7 +71,7 @@ public static void stopServer() throws Exception { } @Test - public void testBody() throws IOException, TimeoutException, InterruptedException { + public void postUrlEncoded() throws IOException, TimeoutException, InterruptedException { Request request = new Request.Builder() .url(String.format("http://localhost:%d/context/body", serverPort)) @@ -97,7 +97,7 @@ public void testBody() throws IOException, TimeoutException, InterruptedExceptio } @Test - public void testHeaders() throws IOException, TimeoutException, InterruptedException { + public void getHeaders() throws IOException, TimeoutException, InterruptedException { Request request = new Request.Builder() .url(String.format("http://localhost:%d/context/headers", serverPort)) @@ -127,7 +127,7 @@ public void testHeaders() throws IOException, TimeoutException, InterruptedExcep } @Test - public void testBlocking() throws IOException, TimeoutException, InterruptedException { + public void block() throws IOException, TimeoutException, InterruptedException { Request request = new Request.Builder() .url(String.format("http://localhost:%d/context/body", serverPort)) From 6ad5bd915fb5bf57ae1277825e0be341275b1450 Mon Sep 17 00:00:00 2001 From: Shashank Patidar Date: Thu, 28 Jan 2021 20:13:07 +0530 Subject: [PATCH 4/4] refining code --- .../instrumentation/hypertrace/struts/Struts2Action.java | 8 ++------ .../hypertrace/struts/StrutsInstrumentationTest.java | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java index eb4891ea4..8acff7764 100644 --- a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java +++ b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/Struts2Action.java @@ -17,7 +17,6 @@ package io.opentelemetry.javaagent.instrumentation.hypertrace.struts; import com.opensymphony.xwork2.ActionSupport; -import java.io.IOException; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; @@ -25,12 +24,9 @@ @ParentPackage("json-default") public class Struts2Action extends ActionSupport { - private String jsonString; + private String jsonString = "{'balance':1000.21,'is_vip':true,'num':100,'name':'foo'}"; - static final String sample = "{'balance':1000.21,'is_vip':true,'num':100,'name':'foo'}"; - - public String body() throws IOException { - jsonString = sample; + public String body() { return "body"; } diff --git a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java index 0acc67bb8..627e3e4f5 100644 --- a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java +++ b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java @@ -90,7 +90,7 @@ public void postUrlEncoded() throws IOException, TimeoutException, InterruptedEx assertEquals(1, spans.size()); SpanData spanData = spans.get(0); assertEquals( - "\"" + Struts2Action.sample + "\"", + "\"" + new Struts2Action().getJsonString() + "\"", spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY)); assertEquals( REQUEST_BODY, spanData.getAttributes().get(HypertraceSemanticAttributes.HTTP_REQUEST_BODY));