Forum Discussion

William_Willafo's avatar
William_Willafo
Occasional Contributor
15 years ago

[Res] Help extending soapui with external compiled JAR

Hi,

Novice java programmer here. I know this is not a programming help forum, but I have a question about soapUI's API.

I already have a custom compiled JAR file that contains classes and public functions that do things for me, such as modifying text files on my system and executing remote system commands. I call these functions from soapUI Groovy Test Steps.

Now I'm interested in hooking into some of soapUI's logging functions. I've figured out I have to (i think) import the soapui jar file (C:\Program Files\eviware\soapUI-Pro-3.5.1\lib\soapui-3.5.1.jar) into my Netbeans project.

Now I am unsure of what to do next. This is what I am trying to achieve:
1. Inside a Groovy Test Step, call my custom function. My custom function will perform some actions (as it currently does), and then be able to log messages to the current logger, i.e.:
2. If I am running the Groovy Test Step manually, my function should log to the testStep log output.
3. If I am running the TestCase/TestSuite/Project, my function should log to the corresponding logger.

Could anyone point me to the correct class and/or function to call on?

Currently, inside a groovy script I would simply say

log.info "Hello World from groovy!"


But what I want to do is something like (pseudo-code):
My Java Source:

package soapui.demo;

import com.eviware.soapui.....?????

public class MyDemo {
public static void HelloWorld() {
com.eviware.soapui....???.log.info("Hello World from custom JAR!")
}
}

And use it in Groovy Test Step:

import soapui.demo.MyDemo

MyDemo.HelloWorld;


Either method would result is same effect. Except with 2nd method, my custom functions are able to output status messages to soapUI log output.

Thanks!

3 Replies

  • Hi!

    Maybe you could just pass the log as an argument to your methods (it is of type org.apache.log4j.Logger), so you would call

    MyDemo.HelloWorld( log )

    and in the method use

    log.info( "..." )

    ?

    regards,

    /Ole
    eviware.com
  • William_Willafo's avatar
    William_Willafo
    Occasional Contributor
    Thank you! This is just what I was looking for.

    For anyone else who is interested, here are my code snippets:

    Java class:
    ( import the log4j library jar into your project, find it in the <soapui_program_dir>/bin/ )

    package soapui.sandbox;

    public class LogTest {
    public static void HelloWorld(org.apache.log4j.Logger log) {
    log.info("Hello World!");
    }
    }


    Build and compile then place the jar file in <soapui_program_dir>/bin/ext/
    Restart soapUI
    Groovy Script within soapUI:

    import soapui.sandbox.LogTest;

    LogTest.HelloWorld(log);


    Run the groovy script within soapUI and the following is output in the Log Output:

    Thu Mar 10 09:06:48 EST 2011:INFO:Hello World!