com.highway2urhell.transformer.Struts2PrepareTransformer Maven / Gradle / Ivy
package com.highway2urhell.transformer;
import javassist.CtClass;
import javassist.CtMethod;
public class Struts2PrepareTransformer extends AbstractLeechTransformer {
public Struts2PrepareTransformer() {
super("org/apache/struts2/dispatcher/ng/filter/StrutsPrepareFilter");
addImportPackage(
"com.opensymphony.xwork2.config",
"com.opensymphony.xwork2.config.entities",
"java.util",
"java.lang.reflect",
"org.objectweb.asm");
}
@Override
protected void doTransform(CtClass cc) throws Exception {
CtMethod m = cc
.getMethod("postInit",
"(Lorg/apache/struts2/dispatcher/Dispatcher;Ljavax/servlet/FilterConfig;)V");
String h2hHookCode = "" +
"List listEntryPath = new ArrayList();" +
"ConfigurationManager cm = dispatcher.getConfigurationManager();" +
"Configuration cf = cm.getConfiguration();" +
"Collection colPackages = cf.getPackageConfigs().values();" +
"if (colPackages != null) {" +
" Iterator ite = colPackages.iterator();" +
" while(ite.hasNext()) {" +
" PackageConfig pack = (PackageConfig) ite.next();" +
" Collection colActionConfigs = pack.getActionConfigs().values();" +
" Iterator iteCol = colActionConfigs.iterator();" +
" while(iteCol.hasNext()){" +
" ActionConfig action = (ActionConfig) iteCol.next();" +
" if (action.getClassName() != null && !\"\".equals(action.getClassName())) {" +
" try {" +
" Class c = Class.forName(action.getClassName());" +
" Method[] tabM = c.getDeclaredMethods();" +
" for (int i=0;i