Skip to content

Commit

Permalink
- supports Java19, jakarta package
Browse files Browse the repository at this point in the history
  • Loading branch information
zbum committed Jan 9, 2023
1 parent 7b54842 commit f9dd4b7
Show file tree
Hide file tree
Showing 20 changed files with 1,054 additions and 85 deletions.
21 changes: 14 additions & 7 deletions scouter.agent.java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.29.0-GA</version>
<version>3.29.2-GA</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.8.1</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
Expand All @@ -51,7 +51,7 @@
<target>
<jar destfile="${project.build.directory}/${scouter.http.jar}">
<fileset dir="${project.build.outputDirectory}">
<include name="scouter/xtra/http/*.class" />
<include name="scouter/xtra/http/**/*.class" />
</fileset>
</jar>
<jar destfile="${project.build.directory}/${scouter.jdbc.jar}">
Expand Down Expand Up @@ -208,7 +208,7 @@
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.21.0-GA</version>
<version>3.29.2-GA</version>
</dependency>
</dependencies>
<build>
Expand Down Expand Up @@ -384,12 +384,12 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.2</version>
<version>9.4</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>9.2</version>
<version>9.4</version>
</dependency>
<!-- local lib -->
<dependency>
Expand All @@ -414,6 +414,13 @@
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down Expand Up @@ -546,7 +553,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static void reload() {

// //////////////////////////////////////////////////////////////
// boot class이지만 Hooking되어야하는 클래스를 등록한다.
private static HashMap asynchook = new HashMap();
private static final HashMap<Integer, String> asynchook = new HashMap<Integer, String>();

static {
asynchook.put("sun/net/www/protocol/http/HttpURLConnection".hashCode(), "sun/net/www/protocol/http/HttpURLConnection");
Expand Down Expand Up @@ -218,7 +218,7 @@ public byte[] transform(final ClassLoader loader, String className, final Class
return null;
}
if (loader == null) {
if (conf._hook_boot_prefix == null || conf._hook_boot_prefix.length() == 0 || false == className.startsWith(conf._hook_boot_prefix)) {
if (conf._hook_boot_prefix == null || conf._hook_boot_prefix.length() == 0 || !className.startsWith(conf._hook_boot_prefix)) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import scouter.util.ThreadUtil;
public class BackJobs extends Thread {
private static BackJobs instance = null;
public final static synchronized BackJobs getInstance() {
public static synchronized BackJobs getInstance() {
if (instance == null) {
instance = new BackJobs();
instance.setDaemon(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
import scouter.agent.trace.TraceMain;

import java.util.HashSet;
import java.util.Set;

public class HttpServiceASM implements IASM, Opcodes {
public HashSet<String> servlets = new HashSet<String>();
public Set<String> servlets = new HashSet<String>();
public HttpServiceASM() {
servlets.add("javax/servlet/http/HttpServlet");
servlets.add("weblogic/servlet/jsp/JspBase");
servlets.add("jakarta/servlet/http/HttpServlet");
servlets.add("weblogic/servlet/jsp/JspBase");
}

public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc classDesc) {
if (Configure.getInstance()._hook_serivce_enabled == false) {
if (!Configure.getInstance()._hook_serivce_enabled) {
return cv;
}
if (servlets.contains(className)) {
Expand All @@ -42,14 +45,19 @@ public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc class
if ("javax/servlet/Filter".equals(classDesc.interfaces[i])) {
return new HttpServiceCV(cv, className);
}

if ("jakarta/servlet/Filter".equals(classDesc.interfaces[i])) {
return new HttpServiceCV(cv, className);
}
}
return cv;
}
}
class HttpServiceCV extends ClassVisitor implements Opcodes {
private static String TARGET_SERVICE = "service";
private static String TARGET_DOFILTER = "doFilter";
private static String TARGET_SIGNATURE = "(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;";
private static final String TARGET_SERVICE = "service";
private static final String TARGET_DOFILTER = "doFilter";
private static final String TARGET_SIGNATURE = "(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;";
private static final String TARGET_SIGNATURE_JAKARTA = "(Ljakarta/servlet/ServletRequest;Ljakarta/servlet/ServletResponse;";
private String className;
public HttpServiceCV(ClassVisitor cv, String className) {
super(ASM9, cv);
Expand All @@ -61,7 +69,7 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
if (mv == null) {
return mv;
}
if (desc.startsWith(TARGET_SIGNATURE)) {
if (desc.startsWith(TARGET_SIGNATURE) || desc.startsWith(TARGET_SIGNATURE_JAKARTA)) {
if (TARGET_SERVICE.equals(name)) {
Logger.println("A103", "HTTP " + className);
return new HttpServiceMV(access, desc, mv, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
import scouter.agent.ClassDesc;

public interface IASM {
public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc classDesc);
ClassVisitor transform(ClassVisitor cv, String className, ClassDesc classDesc);
}
Loading

0 comments on commit f9dd4b7

Please sign in to comment.