use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.
the class ResteasyRegistryPlugin method patchFilterDispatcher.
/**
* @param ctClass
* @param classPool
*/
@OnClassLoadEvent(classNameRegexp = "org.jboss.resteasy.plugins.server.servlet.FilterDispatcher")
public static void patchFilterDispatcher(CtClass ctClass, ClassPool classPool) {
try {
CtMethod init = ctClass.getDeclaredMethod("init");
init.insertAfter(//
"" + //
"java.lang.ClassLoader $$cl = Thread.currentThread().getContextClassLoader();" + //
"java.lang.Object $$servletContext = servletConfig.getServletContext();" + //
PluginManagerInvoker.buildInitializePlugin(ResteasyRegistryPlugin.class, "$$cl") + PluginManagerInvoker.buildCallPluginMethod("$$cl", ResteasyRegistryPlugin.class, "registerContext", "$$servletContext", //
"java.lang.Object") + PluginManagerInvoker.buildCallPluginMethod("$$cl", ResteasyRegistryPlugin.class, "registerServletContainerDispatcher", "servletContainerDispatcher", //
"java.lang.Object"));
} catch (NotFoundException | CannotCompileException e) {
LOGGER.error("Error patching FilterDispatcher", e);
}
}
use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.
the class ResteasyRegistryPlugin method patchServletDispatcher.
@OnClassLoadEvent(classNameRegexp = "org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher")
public static void patchServletDispatcher(CtClass ctClass, ClassPool classPool) {
try {
CtMethod init = ctClass.getDeclaredMethod("init");
init.insertAfter(//
"" + //
"java.lang.Object $$servletContext = servletConfig.getServletContext();" + //
"java.lang.ClassLoader $$cl = Thread.currentThread().getContextClassLoader();" + //
PluginManagerInvoker.buildInitializePlugin(ResteasyRegistryPlugin.class, "$$cl") + PluginManagerInvoker.buildCallPluginMethod("$$cl", ResteasyRegistryPlugin.class, "registerContext", "$$servletContext", //
"java.lang.Object") + PluginManagerInvoker.buildCallPluginMethod("$$cl", ResteasyRegistryPlugin.class, "registerServletContainerDispatcher", "servletContainerDispatcher", //
"java.lang.Object"));
} catch (NotFoundException | CannotCompileException e) {
LOGGER.error("Error patching HttpServletDispatcher", e);
}
}
use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.
the class CtClassJavaProxyGenerator method addProxyMethod.
/**
* Add another method to be proxied, either by creating a new ProxyMethod object or augmenting an old one for a
* duplicate method.
*
* "fromClass" indicates the proxy interface that the method was found through, which may be different from (a
* subinterface of) the method's "declaring class". Note that the first Method object passed for a given name and
* descriptor identifies the Method object (and thus the declaring class) that will be passed to the invocation
* handler's "invoke" method for a given set of duplicate methods.
*/
private void addProxyMethod(CtMethod m, CtClass fromClass) {
String name = m.getName();
CtClass[] parameterTypes;
CtClass returnType;
CtClass[] exceptionTypes;
try {
parameterTypes = m.getParameterTypes();
returnType = m.getReturnType();
exceptionTypes = m.getExceptionTypes();
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
String sig = name + getParameterDescriptors(parameterTypes);
List<ProxyMethod> sigmethods = proxyMethods.get(sig);
if (sigmethods != null) {
for (ProxyMethod pm : sigmethods) {
if (returnType == pm.returnType || returnType.getName().equals(pm.returnType.getName())) {
/*
* Found a match: reduce exception types to the greatest set of exceptions that can thrown
* compatibly with the throws clauses of both overridden methods.
*/
List<CtClass> legalExceptions = new ArrayList<>();
collectCompatibleTypes(exceptionTypes, pm.exceptionTypes, legalExceptions);
collectCompatibleTypes(pm.exceptionTypes, exceptionTypes, legalExceptions);
pm.exceptionTypes = new CtClass[legalExceptions.size()];
pm.exceptionTypes = legalExceptions.toArray(pm.exceptionTypes);
return;
}
}
} else {
sigmethods = new ArrayList<>(3);
proxyMethods.put(sig, sigmethods);
}
sigmethods.add(new ProxyMethod(name, parameterTypes, returnType, exceptionTypes, fromClass));
}
use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.
the class CtClassJavaProxyGenerator method getFriendlyMethodSignature.
/**
* Returns a human-readable string representing the signature of a method with the given name and parameter types.
*/
private static String getFriendlyMethodSignature(String name, CtClass[] parameterTypes) {
StringBuilder sig = new StringBuilder(name);
sig.append('(');
for (int i = 0; i < parameterTypes.length; i++) {
if (i > 0) {
sig.append(',');
}
CtClass parameterType = parameterTypes[i];
int dimensions = 0;
while (parameterType.isArray()) {
try {
parameterType = parameterType.getComponentType();
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
dimensions++;
}
sig.append(parameterType.getName());
while (dimensions-- > 0) {
sig.append("[]");
}
}
sig.append(')');
return sig.toString();
}
use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.
the class DeltaSpikeProxyTransformer method instrumentTryToLoadClassForName.
private static void instrumentTryToLoadClassForName(CtClass ctClass, String methodName) throws CannotCompileException {
try {
CtMethod getProxyClassMethod = ctClass.getDeclaredMethod(methodName);
getProxyClassMethod.instrument(new ExprEditor() {
public void edit(MethodCall m) throws CannotCompileException {
if (m.getClassName().equals("org.apache.deltaspike.core.util.ClassUtils") && m.getMethodName().equals("tryToLoadClassForName"))
m.replace("{ $_ = org.hotswap.agent.plugin.deltaspike.proxy.ProxyClassLoadingDelegate.tryToLoadClassForName($$); }");
}
});
} catch (NotFoundException e) {
LOGGER.debug("Method '{}' not found in '{}'.", methodName, ctClass.getName());
}
}
Aggregations