Problem (small concise version): I have a jar file that I can edit, but I want to make a method, in a specific class in that jar to call another class that will be under another jar. The idea is that the existing.jar would only have the method call the external.jar and the external.jar would return a value to the existing.jar in order to continue its processing.
Problem (long detailed version): I use p6spy to capture the sqls that my application generates but I need to filter that sql to a very specific level, not only the function "sqlExpression" of p6spy does not work as even if it did it would not be sufficient. I currently have decompiled (I did not find the sources of the project, and yes, it is an open source project) p6spy and edited the formattedlogger.class in order to suit my need. My problem is, this is a "solution" that many people will have to use and the filter that I applied is not enough to some and to other simply doesnt work because they need something I need excluded. I did a bit of research and decided that I should take the adapter route, I decided that the p6spy.jar will remain untouched, but it will call a class from another jar file which will then contain the specificity of the filter.
But I do not know how to do that. :(
Scenario: OS: CentOS release 6.4 (Final) Which most likely is a virtual machine. Application Server: jboss-4.3.0.GA Which contains multiple instances under the server folder. I have the p6spy.jar under the app_server/server/instance/lib I understand that I will have to have the adapter under the same folder.
Does anyone have any idea how this should be done, where I could read about such things or how I should proceed, maybe a different solution or perhaps another idea. I'm open to suggestions.
*Edit 1: I have a p6spy.jar file which contains a class that I edit to suit my needs. (FormattedLogger.class)
the class is at it follows:
package com.p6spy.engine.logging.appender;
public abstract class FormattedLogger
{
protected String lastEntry;
public void logSQL(int connectionId, String now, long elapsed, String category, String prepared, String sql)
{
String logEntry = now + "|" + elapsed + "|" + ((connectionId == -1) ? "" : String.valueOf(connectionId)) + "|" + category + "|" + prepared + "|" + sql;
logText(logEntry);
}
public abstract void logText(String paramString);
public void setLastEntry(String inVar)
{
this.lastEntry = inVar;
}
public String getLastEntry() {
return this.lastEntry;
}
}
I need it to look something like this:
package com.p6spy.engine.logging.appender;
public abstract class FormattedLogger
{
protected String lastEntry;
public void logSQL(int connectionId, String now, long elapsed, String category, String prepared, String sql)
{
sql = method_in_another_class_and_in_other_jar_file(sql);
logText(sql);
}
public abstract void logText(String paramString);
public void setLastEntry(String inVar)
{
this.lastEntry = inVar;
}
public String getLastEntry() {
return this.lastEntry;
}
}
this "method_in_another_class_and_in_other_jar_file(sql)" would, as the name says, be outside this jar, in order to be easly edited and such.
The issue has not been solved (yet) but the replies have been of great help.
Jim Harrison suggested bytecode modification as a solution, unfortunately that is not the path I'll take.
markbernard got the source files @ sourceforge.net/projects/p6spy/files/p6spy and I'll re-write the driver/software to fit my scenario.
Thank you all for the help. :D!