Eviware Forum

soapUI => soapUI => Topic started by: Joey Seekata on September 20, 2007, 02:40:07 pm



Title: Log4j and extending the HtmlLayout layout class
Post by: Joey Seekata on September 20, 2007, 02:40:07 pm
I think this is really about hooking in java code in general, but my specific need is to extend HTMLLayout (org.apache.log4j.HTMLLayout).  In the version of log4j that comes with SOAPui, the output from HTMLLayout is fixed (HTMLLayout does not derive from PatternLayout and therefore does not accept an ConversionPattern).

If I were to extend HTMLLayout in java, can I hook that code into SOAPui?  For example, I currently have this in soapui-log4j.xml:

  <appender name="testResults" class="org.apache.log4j.FileAppender">
     <param name="File" value="testResults.html"/>
     <layout class="org.apache.log4j.HTMLLayout">
      </layout>
   </appender>

What I would like to do is (for example):

  <appender name="testResults" class="org.apache.log4j.FileAppender">
     <param name="File" value="testResults.html"/>
     <layout class="com.company.project.MyHtmlLayout">
      </layout>
   </appender>

Where would I put the jar file that contains com.company.project.MyHtmlLayout such that SOAPui will load it up at startup?

Thanks for your attention to this matter.

Joey


Title: Re: Log4j and extending the HtmlLayout layout class
Post by: omatzura on September 20, 2007, 10:40:35 pm
Hi Joey,

normally you would be able to drop the jar-file into the <soapui>\bin\ext folder, but since the log4j configuration is read before this folder is processed, you will need to manually add your jar to the classpath in soapui.bat.. unless log4j doesn't actually instantiate your layout until after the bin\ext folder has been processed (which is just after the log4j.xml file has been read), in which case you should be able to just put your jar in the bin\ext folder..

Hope this helps!

regards!

/Ole
eviware.com


Title: Re: Log4j and extending the HtmlLayout layout class
Post by: Joey Seekata on October 11, 2007, 06:49:00 pm
Omatzura,

Thanks so much.  Turns out log4j is processed first so the soapui-pro.bat file needed to be modified. 

Next task, resetting the log file when a test case is run.  log4j's FileAppender has a property "Append" and it is set to false.  So when SoapUI-Pro starts up, the old log file is cleared (emptied of data).  That is great, but what I am being asked to do requires that same emptying for each test case run.  Any thoughts?  I have, of course, poured over the log4j documents and do not see anything that looks promising, so I am asking here.

Thanks again,

Joey


Title: Re: Log4j and extending the HtmlLayout layout class
Post by: omatzura on October 11, 2007, 07:16:55 pm
Hi Joey,

maybe you can create a groovy-script first in your testcase that gets the loggers' FileAppender and calls its activateOptions method? ie

Logger.getLogger(..).getAppender( .. ).activateOptions()

which should reset the log (if I understand the javadocs correctly)!?

Hope this helps!

regards,

/Ole
eviware.com


Title: Re: Log4j and extending the HtmlLayout layout class
Post by: Joey Seekata on October 11, 2007, 08:49:39 pm
Omatzura,

I don't know how you got that from the javadocs, but it was brilliant.  I used:

Logger.getRootLogger().getAppender("testResults").activateOptions();

and sure enough, it closed and reopened it.  With append set to false, it reopened it "clean".

I could not figure out what name to put into the Logger.getLogger call, so I used getRootLogger instead.

Who said there are no pointers in java?  You pointed me in the right direction with some java code.

But still, how did you get that behavior from the javadocs?  Some kind of secret decoder ring or what?

Thanks so much!

Joey