java - How to call WebApp with premain -
i have webapplication in java has 3 threads sends data program calls application , saves data (log files log4j) h2 database.
now don't want have 3 threads more or less same. i'm trying inject code javassist , agent after tries think result want! if code right( i'll post later nice if take look) bytecode inserted 3 thread methods before called but....
i used tutorial http://appcrawler.com/wordpress/2013/01/02/simple-byte-code-injection-example-with-javassist/
and if want call application need write java -javaagent:myagent.jar foo says tutorial webapplication gets called other java program can call , agent inserts bytecode work? not, think. nice if tell me how or maybe how advance code don't need it.
code: transform class (bytecode gets inserted)
public class mytransformer implements classfiletransformer { @override public byte[] transform(classloader loader, string classname, class redefiningclass, protectiondomain protectiondomain, byte[] bytes) throws illegalclassformatexception { return transformclass(redefiningclass, bytes); } private byte[] transformclass(class classtotransform, byte[] b) { classpool pool = classpool.getdefault(); ctclass cl = null; try { cl = pool.get("de.test.ws.myapplication"); } catch (javassist.notfoundexception e) { e.printstacktrace(); } try { assert cl != null; ctmethod[] methods = cl.getmethods(); (int = 0; < methods.length; i++) { if (methods[i].isempty() == false) { changemethod(methods[i]); } } b = cl.tobytecode(); } catch (exception e) { e.printstacktrace(); } { if (cl != null) { cl.detach(); } } return b; } private void changemethod(ctmethod method) throws notfoundexception, cannotcompileexception { if (method.hasannotation(loggable.class)) { method.insertbefore(" thread thread0 = new thread(new runnable() {\n" + "\n" + " @override\n" + " public void run() {\n" + "\n" + "\n" + " try {\n" + " threadlogger.logcall(webservice.class.getmethod(\"startthread0\"),\"thread0\");\n" + " } catch (exception e) {\n" + " e.printstacktrace();\n" + " }\n" + " }\n" + " });\n" + " thread0.start();"); } } }
Comments
Post a Comment