All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.highway2urhell.service.TransformerService Maven / Gradle / Ivy
package com.highway2urhell.service;
import com.highway2urhell.domain.EntryPathData;
import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TransformerService {
private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
public void transformAllClassScanByH2h(Instrumentation inst,
Set entryClassName) {
for (String classNameNormalized : entryClassName) {
String className = classNameNormalized.replaceAll("/", ".");
LOGGER.error("Transform class {}", className);
transformOneClass(inst, className);
}
}
private void transformOneClass(Instrumentation inst, String className) {
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
try {
inst.retransformClasses(classLoader.loadClass(className));
} catch (ClassNotFoundException | UnmodifiableClassException e) {
LOGGER.error("Error while transform Class {} msg {}", className, e);
}
}
public Map> transformDataFromLeechPluginForTransformation(
Collection leechService) {
Map> mapToTransform = new HashMap>();
for (LeechService leech : leechService) {
for (EntryPathData entryPath : leech.getFrameworkInformations()
.getListEntryPath()) {
if (entryPath.getMethodName() != null && entryPath.getAudit()) {
switch (entryPath.getTypePath()) {
case SERVLET:
createRegistrerBreakerData(
entryPath,
mapToTransform,
"doGet",
"(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V");
createRegistrerBreakerData(
entryPath,
mapToTransform,
"doPost",
"(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V");
createRegistrerBreakerData(
entryPath,
mapToTransform,
"service",
"(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V");
break;
case FILTER:
createRegistrerBreakerData(
entryPath,
mapToTransform,
"doFilter",
"(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V");
break;
default:
createRegistrerBreakerData(entryPath, mapToTransform,
entryPath.getMethodName(),
entryPath.getSignatureName());
break;
}
}
}
}
return mapToTransform;
}
private void createRegistrerBreakerData(EntryPathData entryPath,
Map> mapToTransform, String methodName,
String signatureName) {
EntryPathData entry = new EntryPathData();
entry.setClassName(entryPath.getClassName());
entry.setMethodName(methodName);
String classNameNormalized = entryPath.getClassName().replaceAll("\\.",
"/");
entry.setClassNameNormalized(classNameNormalized);
entry.setSignatureName(signatureName);
entry.setTypePath(entryPath.getTypePath());
List listEntry = mapToTransform.get(classNameNormalized);
if (listEntry == null) {
// first time
listEntry = new ArrayList();
listEntry.add(entry);
mapToTransform.put(classNameNormalized, listEntry);
} else {
listEntry.add(entry);
}
}
public List collectBreakerDataFromLeechPlugin(
Collection leechService) {
List listBreaker = new ArrayList();
for (LeechService leech : leechService) {
for (EntryPathData entryPath : leech.getFrameworkInformations()
.getListEntryPath()) {
if (entryPath.getMethodName() != null) {
switch (entryPath.getTypePath()) {
case SERVLET:
listBreaker.add(createBreakerData(entryPath, "doGet", "(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V"));
listBreaker.add(createBreakerData(entryPath, "doPost", "(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V"));
listBreaker.add(createBreakerData(entryPath, "service", "(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V"));
break;
case FILTER:
listBreaker.add(createBreakerData(entryPath, "doFilter", "(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V"));
break;
default:
listBreaker.add(createBreakerData(entryPath, entryPath.getMethodName(), entryPath.getSignatureName()));
break;
}
}
}
}
return listBreaker;
}
private EntryPathData createBreakerData(EntryPathData entryPath,
String methodName, String signatureName) {
entryPath.setMethodName(methodName);
String classNameNormalized = entryPath.getClassName().replaceAll("\\.",
"/");
entryPath.setClassNameNormalized(classNameNormalized);
entryPath.setSignatureName(signatureName);
return entryPath;
}
}