From bd620dd3a0e3861e419e5f9626cd78b39cb0df3c Mon Sep 17 00:00:00 2001 From: idawda Date: Fri, 24 May 2024 16:15:09 +0530 Subject: [PATCH] API Endpoint Phase 2: Add Endpoint route in RestEasy-3 Framework --- .../MethodExpression_Instrumentation.java | 22 +++++++++++++++++++ .../resteasy3/test/APIEndpointTest.java | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 instrumentation-security/resteasy-3/src/main/java/org/jboss/resteasy/core/MethodExpression_Instrumentation.java diff --git a/instrumentation-security/resteasy-3/src/main/java/org/jboss/resteasy/core/MethodExpression_Instrumentation.java b/instrumentation-security/resteasy-3/src/main/java/org/jboss/resteasy/core/MethodExpression_Instrumentation.java new file mode 100644 index 000000000..eebdb551a --- /dev/null +++ b/instrumentation-security/resteasy-3/src/main/java/org/jboss/resteasy/core/MethodExpression_Instrumentation.java @@ -0,0 +1,22 @@ +package org.jboss.resteasy.core; + +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.weaver.Weave; +import com.newrelic.api.agent.weaver.Weaver; +import org.jboss.resteasy.spi.HttpRequest; + +import java.util.regex.Matcher; + +@Weave(originalName = "org.jboss.resteasy.core.registry.MethodExpression") +public abstract class MethodExpression_Instrumentation { + public abstract String getPathExpression(); + public void populatePathParams(HttpRequest request, Matcher matcher, String path){ + Weaver.callOriginal(); + try { + if (NewRelicSecurity.isHookProcessingActive()) { + NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setEndpointRoute(getPathExpression()); + } + } catch (Exception e) { + } + } +} \ No newline at end of file diff --git a/instrumentation-security/resteasy-3/src/test/java/com/nr/instrumentation/resteasy3/test/APIEndpointTest.java b/instrumentation-security/resteasy-3/src/test/java/com/nr/instrumentation/resteasy3/test/APIEndpointTest.java index c4b70025c..1e673bc91 100644 --- a/instrumentation-security/resteasy-3/src/test/java/com/nr/instrumentation/resteasy3/test/APIEndpointTest.java +++ b/instrumentation-security/resteasy-3/src/test/java/com/nr/instrumentation/resteasy3/test/APIEndpointTest.java @@ -67,7 +67,7 @@ private void assertMapping(String method, String path, String handler, Applicati @Trace(dispatcher = true) private void service() throws IOException { - HttpURLConnection conn = (HttpURLConnection)TestApplication.getEndPoint("customers/getStuff/users").openConnection(); + HttpURLConnection conn = (HttpURLConnection)TestApplication.getEndPoint("users/count/9").openConnection(); conn.connect(); conn.getResponseCode(); }