Forum Discussion

aepdwm's avatar
aepdwm
New Contributor
12 years ago

Jetty Server stop after testrun(project)

Hi all,

can somebody help me at following problem.

Problem:
I try to get the Jetty Server Instance from SoapUI, which is initialized at the runtime, for example a project with mock responses is started.

Background information:
My goal is to stop the "Jetty server" with a groovy script after a testrun.

So far I have achieved, to managed and create a own server instance with following script.

import com.eviware.soapui.impl.wsdl.monitor.jettyproxy.JettyServer
js = new JettyServer()
js.start()
js.stop()
log.info(js.isRunning())


Thanks a lot and regards.
aepdwm
  • aepdwm's avatar
    aepdwm
    New Contributor
    Hi all,

    here a small addendum:
    what I am looking for is, that a "mock response" is stoped after his run.
    And after the last "mock response" was invoked, the server should be terminated.
    This makes soapui even if LEAVE_MOCKENGINE = false(set in preferences).
    But unfortunately, the server is stopped, before the last message "mock response" is sent.

    in the SoapUI log I can find the following entry.
    Failed to wait for idle... stopping connector anyway..

    Question: Can i self edit the "JettyMockEngine.java", and if so, in which directory can I find this file.

    Thanks a lot and regards.
    aepdwm
  • aepdwm's avatar
    aepdwm
    New Contributor
    first best thanks for your help, I have found the file and was able to further analyze the problem.

    Addendum, what I've found so far:
    If I disable the property "leave_MockEngine", then the connector is closed before the MockResponse is sent to the server.
    The StopMockService () function is called before the MockResponse is passed to the SoapUIHttpClient.
    If the property "leave_MockEngine" is disabled, the connector is stopped and no response passed to the SoapUIHttpClient.
    If the "leave_MockEngine" property is enabled, only the MockRunner is removed but the Connector is still running and the response will sent (passed to the SoapUIHttpClient)

    My approach:
    To close the connector at the end of the test, I created an additional function that I call via groovy step at the end of the case.
    Function, which i have created in the JettyMockEngine Class:

     public boolean stopConnector( Integer port ) throws Exception
    {
    synchronized( server )
    {
    SoapUIConnector connector = connectors.get( port );
    if( connector == null )
    {
    log.warn( "Missing connectors on port [" + port + "]" );
    return false;
    }
    else
    {
    try
    {
    log.info( "Stopping connector on port [" + port + "]" );
    connector.stop();
    }
    catch( Exception e )
    {
    SoapUI.logError( e );
    }
    server.removeConnector( connector );
    runners.remove( port );
    return true;
    }
    }
    }


    Groovy Script:

    import com.eviware.soapui.SoapUI
    SoapUI.getMockEngine().stopConnector(8080)


    Now to my questions:
    I've downloaded the source files from the git and tested my modification with the following command "mvn exec: java". But how can I create an install file from this project?

    Thanks a lot and regards.
    aepdwm
  • aepdwm's avatar
    aepdwm
    New Contributor
    So I'm now one step further.

    Instructions:
    1. installed SoapUI 4.6.1
    2. generate a package from the „git version“ with comand mvn -package
    3. move the new created package „soapui-4.6.1“ into the program directory
    from \soapui\soapui\target\
    to \Program Files\SmartBear\SoapUI-4.6.1\bin

    that's all. I don't know if this is the right way but it works:)

    but it gives me a new question:
    Now I would execute the function automatically after each "test case" run, without a groovy script step.

    Can someone tell me from which class, I could call my function?

    Thanks a lot and regards.
    aepdwm