Junit with Embedded Glassfish fails - JMS Resource Adapter should be EMBEDDED - junit

I'm trying to test a session bean (NetBeans 6.8, Glassfish V3). Unfortunately, the embedded glassfish is unable to start properly, as it tries to connect to a remote JMS Provider (at localhost:7676):
$ ant test
...
[junit] Mar 23, 2010 12:13:51 PM com.sun.messaging.jms.ra.ResourceAdapter start
[junit] INFO: MQJMSRA_RA1101: SJSMQ JMS Resource Adapter starting: REMOTE
[junit] Mar 23, 2010 12:13:51 PM com.sun.messaging.jmq.jmsclient.ExceptionHandler throwConnectionException
[junit] WARNING: [C4003]: Error occurred on connection creation [localhost:7676]. - cause: java.net.ConnectException: Connection refused
The error is in itself correct, as no (other) JMS provider is running. I was expecting the embedded glassfish to start the JMS provider in EMBEDDED mode.
My test uses javax.ejb.embeddable.EJBContainer :
#BeforeClass
public static void initContainer() throws Exception {
ec = EJBContainer.createEJBContainer();
ctx = ec.getContext();
}
When I start glassfish normally, it's fine:
$ bin/asadmin get server.jms-service.type
server.jms-service.type=EMBEDDED
How can I get my junit tests to use an embedded glassfish with an EMBEDDED JMS Provider?

Ok, I downloaded an official glassfish build (v3.0.1) from here, and now it's starting the JMS Provider EMBEDDED as expected.

Related

TIBCO BW failing to debug successfully a REST service .I have created a jdbc resource and tested the connection was a success but i have this error

<>#BWEclipseAppNode> 12:12:32.545 INFO [main] com.tibco.thor.frwk.Deployer - Started by BusinessStudio.
12:12:34.970 INFO [main] com.tibco.bw.frwk.engine.BWEngine - TIBCO-BW-FRWK-300002: BW Engine [Main] started successfully.
12:12:35.355 INFO [Framework Event Dispatcher: Equinox Container: 80edabb3-8e47-001c-18c5-90bdbc610de0] com.tibco.thor.frwk.Deployer - TIBCO-THOR-FRWK-300001: Started OSGi Framework of AppNode [BWEclipseAppNode] in AppSpace [BWEclipseAppSpace] of Domain [BWEclipseDomain]
12:12:35.483 INFO [Framework Event Dispatcher: Equinox Container: 80edabb3-8e47-001c-18c5-90bdbc610de0] com.tibco.thor.frwk.Application - TIBCO-THOR-FRWK-300018: Deploying BW Application [RESTservice2.application:1.0].
12:12:40.067 INFO [Framework Event Dispatcher: Equinox Container: 80edabb3-8e47-001c-18c5-90bdbc610de0] com.tibco.thor.frwk.Application - TIBCO-THOR-FRWK-300021: All Application dependencies are resolved for Application [RESTservice2.application:1.0]
12:12:41.431 INFO [Thread-28] com.tibco.thor.frwk.Application - TIBCO-THOR-FRWK-300019: BW Application [RESTservice2.application:1.0] is impaired.
12:12:41.435 INFO [Framework Event Dispatcher: Equinox Container: 80edabb3-8e47-001c-18c5-90bdbc610de0] com.tibco.thor.frwk.Application - Started by BusinessStudio, ignoring .enabled settings.
12:12:41.438 ERROR [CM Configuration Updater (Update: pid=bw.resource.jdbc.916120c9-fbcb-45de-a13c-b22e3edf76ec)] com.tibco.bw.sharedresource.runtime.dependency.ReferenceDependency - TIBCO-BW-SR-FRWK-503000: Unable to start SharedResource [restservice2.JDBCConnectionResource] from Module [RESTservice2:1.0.0.qualifier], DeploymentUnit [RESTservice2.application:1.0]. <Reason>: TIBCO-BW-SR-JDBC-500003: The database driver [com.mysql.jdbc.Driver] is not found. Ensure that DataSourceFactory bundle providing this driver is available in the environment.
so this is the error i am getting as a result i cant run OSGi commands to request endpoint urls and for my rest service even though my code has no errors before debug ,i am getting this during debug ,please help.
In order to use the MySql JDBC driver you need to install it in the BusinessWorks environment of your machine.
This is done by running the command 'bwinstall mysql-driver' from the <TIBCO_HOME>bw/6.X/bin folder.
As Emmanuel suggested, according to the error, you probably missed the required JDBC driver installation.
Once you execute the command, it will start successfully.

Configure Mysql with Liferay 7?

I am trying to configure mysql 8.0.3 database for liferay 7.I am getting this error while configuring db.
08:10:26,259 ERROR [http-nio-8080-exec-3][PoolBase:429] HikariPool-5 -
Failed to execute isValid() for connection, configure connection test
query (null). 24-Oct-2017 08:10:26.260 SEVERE [http-nio-8080-exec-3]
org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service()
for servlet [Main Servlet] in context with path [] threw exception
[Servlet execution threw an exception] with root cause
java.lang.AbstractMethodError at
com.zaxxer.hikari.pool.PoolBase.checkDriverSupport(PoolBase.java:422)
at com.zaxxer.hikari.pool.PoolBase.setupConnection(PoolBase.java:393)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:351)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:196)
at
com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:442)
at
com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:505)
at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:113)
this is not complete stack trace please let me if full stack trace is required.

Jdbc error after update java 8

I have a server linux Ubuntu (14.04.4) with Tomcat and Java in it.
I recently upgraded Java from 7 to 8 (leaving Tomcat 7)
this is the situation
my web application starts but throws an exception during the db connection
Jul 11, 2016 3:41:19 PM org.apache.tomcat.jdbc.pool.ConnectionPool init
SEVERE: Unable to create initial connections of pool.
java.sql.SQLException: com.mysql.jdbc.Driver
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:701)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:486)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:144)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)
this is the connection URL: jdbc:mysql://localhost:3306/
NOTE 1: mysql-connector-java-5.0.8-bin.jar is in tomcat lib
NOTE 2: I tried to put mysql-connector-java-5.0.8-bin.jar even in WEB-INF/lib
NOTE 3: the same application with the same configuration of Tomcat and Java works fine in my local pc.
UPDATE:
here the configuration:
PoolProperties p = new PoolProperties();
p.setRemoveAbandoned(Boolean.parseBoolean(System.getProperties().getProperty(pathContestoString+"db.removeAbandoned")));
p.setRemoveAbandonedTimeout(Integer.parseInt(System.getProperties().getProperty(pathContestoString+"db.removeAbandonedTimeout")));
p.setLogAbandoned(Boolean.parseBoolean(System.getProperties().getProperty(pathContestoString+"db.logAbandoned")));
p.setMaxActive(Integer.parseInt(System.getProperties().getProperty(pathContestoString+"db.maxActive")));
p.setMaxIdle(Integer.parseInt(System.getProperties().getProperty(pathContestoString+"db.maxIdle")));
p.setMaxWait(Integer.parseInt(System.getProperties().getProperty(pathContestoString+"db.maxWait")));
p.setUsername(System.getProperties().getProperty(pathContestoString+"db.user"));
p.setPassword(System.getProperties().getProperty(pathContestoString+"db.pwd"));
p.setDriverClassName("com.mysql.jdbc.Driver");
p.setUrl(System.getProperties().getProperty(pathContestoString+"db.url")+System.getProperties().getProperty(pathContestoString+"db.dbname")+"?useEncoding=true&characterEncoding=UTF-8&ssl=true");
// factory?
// closeMethod?
p.setValidationQuery("SELECT 1");
p.setTestOnBorrow(true);
App.properties:
db.user=myUser
db.pwd=myPwd
db.url=jdbc:mysql://localhost:3306/
db.dbname=myDbName
db.maxActive=50
db.maxIdle=30
db.maxWait=50000
db.removeAbandoned=true
db.removeAbandonedTimeout=20
db.logAbandoned=true

Spring Boot: Getting error "Cannot determine embedded database driver class for database type NONE" when running JUnit test from eclipse

I'm having a little problems running JUnit tests from Eclipse directly (using the "Run As JUnit test" on the JUnit test file I want to run) on a simple Spring Boot application.
I'm using Gradle as a build tool. Now, when running the test as a Gradle task it works just fine, but when running it as an Eclipse JUnit task it fails with the follwoing error
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
My application.properties files does define a local MySQL database and that seems to work fine with gradle:
spring.datasource.url: jdbc:mysql://localhost:3306/test
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
My Application Class:
#SpringBootApplication
public class Application {
My Application test:
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = Application.class)
#WebAppConfiguration
public class ApplicationTests {
Any ideas?

The web application [] appears to have started a thread named [Abandoned connection cleanup thread] com.mysql.jdbc.AbandonedConnectionCleanupThread

In the middle of my web-development I just close my web-app in my eclipse IDE, about a minute, I just saw a WARNING in my eclipse console.
WARNING: The web application [/Spring.MVC] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Sep 06, 2014 8:31:55 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
WARNING: The web application [/Spring.MVC] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(Unknown Source)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:40)
Sep 06, 2014 8:32:00 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Sep 06, 2014 8:32:00 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Sep 06, 2014 8:32:03 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
name: personPU
...]
It did not caused any memory leak so far, I checked my VisualVM, everything is working as usual, but as I search more about this thing I realize that this warning is caused by the MySQL driver not releasing resources or not being closed properly(I dont know how to say it exactly) and I ended up in this post at SO related issue
and the OP is right the answer of "don't worry about it" won't be sufficient. This warning bothers me because it may give me some future persistence problems and that worries me a lot, I tried the code the OP has written but I'm having a problem what Libraries should I use to make this code work. This is what I got sor far..
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import org.hibernate.annotations.common.util.impl.LoggerFactory;
import com.mysql.jdbc.AbandonedConnectionCleanupThread;
#WebListener
public class ContextFinalizer implements ServletContextListener {
private static final Logger LOGGER = LoggerFactory.getLogger(ContextFinalizer.class);
public void contextInitialized(ServletContextEvent sce) {
}
public void contextDestroyed(ServletContextEvent sce) {
Enumeration<Driver> drivers = DriverManager.getDrivers();
Driver d = null;
while (drivers.hasMoreElements()) {
try {
d = drivers.nextElement();
DriverManager.deregisterDriver(d);
LOGGER.warn(String.format("Driver %s deregistered", d));
}
catch (SQLException ex) {
LOGGER.warn(String.format("Error deregistering driver %s", d), ex);
}
}
try {
AbandonedConnectionCleanupThread.shutdown();
}
catch (InterruptedException e) {
logger.warn("SEVERE problem cleaning up: " + e.getMessage());
e.printStackTrace();
}
}
}
I just want to know what Libraries do I need or If I'm using the right libraries to implement this properly, I do not even know what Logger should I use, thank you for any help,
See this answer. It seems that MySQL driver should be in {$TOMCAT]/lib shared between applications. Check that you are not including it with each application. At least it worked for me and I have been able to remove the warning.
If you are using Maven mark the dependency as provided.
UPDATE:
root cause is that Tomcat have problems to garbage collect the driver because it is registered in a singleton common to several applications. Closing one application does not allow Tomcat to release the driver. See this answer.
For me i stop mysql (service mysql start) and then i stop tomcat (./shutdown.sh) in bin folder and the problem was fixed.
This works for me.
Issue was with elastic search in my case.
Send a DELETE request from postman to below endpoint and restart your application .
http://localhost:9200/*