SoapUI jetty thread still hanging after MockService stopped [SoapUI API] - testing

I'm using SoapUI 4.0 and i'm starting my mockservices via SoapUI API :
public static void startMockServices(String soapuiProject) throws Exception
{
WsdlProject proj = new WsdlProject(soapuiProject);
List<MockService> mockList = proj.getMockServiceList();
for (MockService mockService : mockList) {
mockService.addMockRunListener(new LogListener());
mockService.start();
}
}
public static void finishMocks() {
SoapUI.getThreadPool().shutdown();
try {
SoapUI.getThreadPool().awaitTermination(5l, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
SoapUI.shutdown();
}
The MockServices start well, but when I try to tear them down, the thread where jetty is running is still hanging up and my process does not finish.
I've tried to stop it via MockRunner.stop() as well but the thread still does not stop as well.
Is there any way I can stop the jetty thread so that my process finishes?

I know, better late than never.
On SoapUi 5.x.x, in the setting file, set the
con:setting id="HttpSettings#leave_mockengine to false!
In java, after, on the runner, you can set the settings file :)

Related

org.openqa.selenium.remote.server.WebDriverServlet has hardcoded session timeout

In one of our project we starting long time jobs on remote nodes. Those jobs sometimes can take few hours.
We've used old version some application which uses old version of Selenium WebDriver. And it works perfectly many years.
Now we've switched to new version of those application which uses new version of selenium WebDriver. And it stop to work.
I've reviewed all stack trace and see issue in class
org.openqa.selenium.remote.server.WebDriverServlet
When you execute any executor you hardcoded timeout for 10 minutes.
try {
execution.get(10, MINUTES);
} catch (ExecutionException e) {
resp.reset();
JeeInterop.execute(new ExceptionHandler(e), req, resp);
} catch (InterruptedException e) {
logger.log(Level.WARNING, "Unexpectedly interrupted: " + e.getMessage(), e);
invalidateSession = true;
Thread.currentThread().interrupt();
} catch (TimeoutException e) {
invalidateSession = true;
}
This is exactly what I'm seeing in our new application. I trying to set any timeout, but it closed session in 10 minutes.
Could you please explain why you do this?
Seems this is a bug.
Do you know any workaround to make it works?
Sincerely

How to catch org.jboss.weld.context.ContextNotActiveException

I understand that this is a RuntimeException but for my usecase I need to catch it and set some attributes.
Context: I am using JPA EntityListeners for auditing and everything works fine when user accesses the application. The problem occurs when the application is accessed remotely using RemoteEJB. I am using a session object (Credentials which captures the user) in the EntityListener, so when the call is from RemoteEJB and because there is no session it fails as expected. This is the only exception I anticipate so I want to catch it and hardcode the auditing in this RemoteEJB accessing case. But somehow I am not able to catch it. I tried to catch javax.enterprise.context.ContextNotActiveException but to no avail.
public class CreateListener {
#Inject #Named("credentials") private Credentials credentials;
#PrePersist
public void setCreateAttributes(Auditable entity){
try {
entity.setCreateUserName(credentials.getUserName());
} catch (RuntimeException e) {
entity.setCreateUserName("RemoteEJB");
}
entity.setCreateTmstmp(new Date());
}
}
Environment: JDK 1.8, JBOSS EAP 7.1, hibernate-jpa-2.1-api, Hibernate 5.2.12.Final
Any help of alternative approach is appreciated.
TIA
-Avi

How to catch error when message have been sent from JMS

I am sending an message through my standalone application that uses EJB MDB to communicate to my other application server that is running on JBOSS server.My application server is connected to a MSSQL server. In certain scenario, connection to the database is lost on application server side and we get following error -
Connection is reset.
Later , when i try to send message i don't get any error at my standalone EJB MDB logs and the process just stops executing.I get error log on application server side logs but same logs don't get propagated to my EJB MDB error logs.
As per my understanding, when db connection is lost all the ejb bean present in jboss container get nullified too.(I could be wrong here, i am new to EJB).
I tried implementing below code in my code that use to send message -
QueueConnection qcon = null;
#PostConstruct
public void initialize() {
System.out.println("In PostConstruct");
try {
qcon = qconFactory.createQueueConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
#PreDestroy
public void releaseResources() {
System.out.println("In PreDestroy");
try {
if(qcon != null)
{
qcon.close();
}
if(qcon== null){
throw new Exception(" new exception occured.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
I was in a impression that Queueconnection object will be nullified, when our db connection have been lost(as we are creating bean and making connection for message). But it doesn't seem to work.
I did found a way to call back my application after sending message. I used a separate temporary queue and used setJMSReplyTo method to set the reply destination. More info could be obtained from this
link. Hope this helps others.

How can my WCF service recover from unavailable message queue?

I have a WCF service that receives messages from the Microsoft Message Queue (netMsmqBinding).
I want my service to recover if the message queue is unavailable. My code should fail to open the service, but then try again after a delay.
I have code to recognize the error when the queue is unavailable:
static bool ExceptionIsBecauseMsmqNotStarted(TypeInitializationException ex)
{
MsmqException msmqException = ex.InnerException as MsmqException;
return ((msmqException != null) && msmqException.HResult == (unchecked((int)(0xc00e000b))));
}
So this should be straightforward: I call ServiceHost.Open(), catch this exception, wait for a second or two, then repeat until my Open call is successful.
The problem is, if this exception gets thrown once, it continues to be thrown. The message queue might have become available, but my running process is in a bad state and I continue to get the TypeInitializationException until I shut down my process and restart it.
Is there a way around this problem? Can I make WCF forgive the queue and genuinely try to listen to it again?
Here is my service opening code:
public async void Start()
{
try
{
_log.Debug("Starting the data warehouse service");
while(!_cancellationTokenSource.IsCancellationRequested)
{
try
{
_serviceHost = new ServiceHost(_dataWarehouseWriter);
_serviceHost.Open();
return;
}
catch (TypeInitializationException ex)
{
_serviceHost.Abort();
if(!ExceptionIsBecauseMsmqNotStarted(ex))
{
throw;
}
}
await Task.Delay(1000, _cancellationTokenSource.Token);
}
}
catch (Exception ex)
{
_log.Error("Failed to start the service host", ex);
}
}
And here is the stack information. The first time it is thrown the stack trace of the inner exception is:
at System.ServiceModel.Channels.MsmqQueue.GetMsmqInformation(Version& version, Boolean& activeDirectoryEnabled)
at System.ServiceModel.Channels.Msmq..cctor()
And the top entries of the outer exception stack:
at System.ServiceModel.Channels.MsmqChannelListenerBase`1.get_TransportManagerTable()
at System.ServiceModel.Channels.TransportManagerContainer..ctor(TransportChannelListener listener)
Microsoft have made the source code to WCF visible, so now we can work out exactly what's going on.
The bad news: WCF is implemented in such a way that if the initial call to ServiceModel.Start() triggers a queueing error there is no way to recover.
The WCF framework includes an internal class called MsmqQueue. This class has a static constructor. The static constructor invokes GetMsmqInformation, which can throw an exception.
Reading the C# Programming Guide on static constructors:
If a static constructor throws an exception, the runtime will not invoke it a second time, and the type will remain uninitialized for the lifetime of the application domain in which your program is running.
There is a programming lesson here: Don't put exception throwing code in a static constructor!
The obvious solution lies outside of the code. When I create my hosting service, I could add a service dependency on the message queue service. However, I would rather fix this problem with code then configuration.
Another solution is to manually check that the queue is available using non-WCF code.
The method System.Messaging.MessageQueue.Exists returns false if the message queue service is unavailable. Knowing this, the following works:
private const string KNOWN_QUEUE_PATH = #".\Private$\datawarehouse";
private static string GetMessageQueuePath()
{
// We can improve this by extracting the queue path from the configuration file
return KNOWN_QUEUE_PATH;
}
public async void Start()
{
try
{
_log.Debug("Starting the data warehouse service");
string queuePath = GetMessageQueuePath();
while(!_cancellationTokenSource.IsCancellationRequested)
{
if (!(System.Messaging.MessageQueue.Exists(queuePath)))
{
_log.Warn($"Unable to find the queue {queuePath}. Will try again shortly");
await Task.Delay(60000, _cancellationTokenSource.Token);
}
else
{
_serviceHost = new ServiceHost(_dataWarehouseWriter);
_serviceHost.Open();
return;
}
}
}
catch(System.OperationCanceledException)
{
_log.Debug("The service start operation was cancelled");
}
catch (Exception ex)
{
_log.Error("Failed to start the service host", ex);
}
}

How do I force GlassFish 2 to load EJBs on startup?

We're using EJB3 on GlassFish v2.
My application includes a GenericServlet called StartupServlet, which has an init method. java.util.TimerTask pollers started from this method cannot lookup facades from the InitialContext.
However if I make an HTTP request and do a lookup, it succeeds. Therefore I have a workaround now where my poller startup code makes an HTTP connection to a page which looks up the interfaces they need.
How can I rearrange my application so I don't need to use such a hack? If possible the solution needs to work on GFv3 as well.
Thanks in advance for your help!
On GF 2, I have a servlet that on start ensures that my timer is created. This looks up a remote session bean and calls it successfully from the init() (not actual code, distilled down to the important parts):
#EJB(name="TimerSessionRef", beanInterface=TimerSessionRemote.class)
public class StartTimers extends HttpServlet {
#Override
public void init() throws ServletException {
super.init();
try {
Context ctx = new InitialContext();
TimerSessionRemote timerSession = (TimerSessionRemote) ctx.lookup("java:comp/env/TimerSessionRef");
timerSession.createTimer();
} catch (NamingException ex) {
logger.blah();
}