HikariCP times out when switching from jdk 1.7 to 1.8 - java-8

In Jenkins switching from env.JAVA_HOME="${tool 'JDK_7u80'}" to javaHome = tool 'JDK_8u74' causes timeout and checkFailFast.
I'm using
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.0.0</version>
</dependency>
and
#Bean(destroyMethod = "close")
DataSource dataSource(Environment env) {
HikariConfig dataSourceConfig = new HikariConfig();
dataSourceConfig.setDriverClassName(env.getRequiredProperty("db.driver"));
dataSourceConfig.setJdbcUrl(env.getRequiredProperty("db.url"));
dataSourceConfig.setUsername(env.getRequiredProperty("db.username"));
dataSourceConfig.setPassword(env.getRequiredProperty("db.password"));
System.out.println("Trying to connect to: " + dataSourceConfig.getJdbcUrl());
return new HikariDataSource(dataSourceConfig);
}
2018-04-18 19:44:18, 987 HikariDataSource [INFO] HikariPool-1 - Starting...
.
.
.Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: The TCP/IP connection to the host XXX, port YYY has failed. Error: "Connection timed out: no further information.. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
at com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:576)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562)
at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115)
at com.zaxxer.hikari.HikariDataSource.(HikariDataSource.java:81)
at com.travelport.ep.datastore.springdatajpa.config.SqlServerConfig.dataSource(SqlServerConfig.java:42)

Related

How to configure embeded mongodb to run in given port in spring boot

I want to use embedded mongoDB with Spring boot for my development and testing. When I try to configure its getting started but always run with dynamic port instead of port which I give in URL config. Idea is I want to use same kind of MongoConfig for both my test (Unit/Integration) and real environment.
My property file looks below.
spring:
profiles: local
data:
mongodb:
uri: mongodb://localhost:62309/local_db
#Configuration
public class MongoDBConfig {
private final Environment env;
public MongoDBConfig(Environment env) {
this.env = env;
}
#Bean
public MongoDbFactory getMongoFactory() {
return new SimpleMongoClientDbFactory(env.getProperty("spring.data.mongodb.uri"));
}
#Bean
public MongoTemplate getMongoTemplate() {
return new MongoTemplate(
> getMongoFactory
());
}
}
pom.xml
--------
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<!-- <scope>test</scope> -->
</dependency>
with this configuration app is getting started when I start it but with dynamic port every restart. Also seeing below exception trace in logs. From this seems like Spring is first try to connect given mongo instance from my local machine and its not finding any so its failing then its invoking emebeded mongodb.
Is there a way I can make spring to make use of configured port to run embedded mongoDB without that error being thrown.
Error Trace
[cluster-ClusterId{value='62141aecfb7ede3c51b3d064', description='null'}-localhost:62309] INFO org.mongodb.driver.cluster -
Exception in monitor thread while connecting to server localhost:62309
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)
at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
... 3 common frames omitted

JavaMail Spring boot properties does not recognize properties

I have a spring boot application with javamail, i configure spring.properties but it seems to not take properties to send email.
#mail properties
spring.mail.host = smtp.gmail.com
spring.mail.port = 587
spring.mail.username = eeee#gmail.com
spring.mail.password = eeee
spring.mail.protocol = smtp
spring.mail.defaultEncoding=UTF-8
spring.mail.smtp.starttls.enable=false
spring.mail.smtp.starttls.required=false
spring.mail.smtp.auth=true
spring.mail.smtp.connectiontimeout=5000
spring.mail.smtp.timeout=5000
spring.mail.smtp.writetimeout=5000
here the java code to send email
#Service
public class MailSenderServiceImpl implements IMailSenderService{
#Autowired
JavaMailSender mailSender;
#Override
public void sendEmailStatusNotification(Shipment shipment) throws IOException, MessagingException{
final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
message.setFrom(shipment.getSender().getSenderEmail());
message.setTo(new String[] {shipment.getRecipient().getRecipientEmail()});
message.setSubject("Shipment "+shipment.getTrackingNumber()+"status update");
message.setText("the shipment status is now :"+shipment.getStatus().getLabel());
this.mailSender.send(mimeMessage);
}
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
here we see this error
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect; message exceptions (1) are:
Failed message 1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect
Any idea ?
By default spring.properties is not a properties source, try putting them in application.properties.

Hikari connection pool issue with sybase

I have a java spring boot application which does bulk insert data to sybase using Spring JDBC driver . I am using Sybase JDBC driver and uses DriverManagerDataSource and HikariConnectionPool to do the bulk insert. The Datasource creation goes fine and but when i try to creat the HikariConnectionPool its giving error Connection Closed error. Below is the code .As you see i am doing an explicit call to see if connecton is closed and it returns false. I am not ble to understand what i am missing here. TIA for any suggestions.
SOURCE CODE
#Configuration
#Profile("local")
public class SpringJDBCLocalConfiguration {
Logger logger = LoggerFactory.getLogger(SpringJDBCLocalConfiguration.class);
#Bean(name = "dataSource")
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(){{
setDriverClassName("com.sybase.jdbc4.jdbc.SybDriver");
setUrl("url");
setUsername("username");
setPassword("passwd");
}};;
try {
Connection conn = dataSource.getConnection();
logger.info("SpringJDBCLocalConfiguration conn "+conn);
logger.info("SpringJDBCLocalConfiguration conn isClosed "+conn.isClosed());
}
catch(Exception exc){
logger.error("SpringJDBCLocalConfiguration error getting connection in SpringJDBCLocalConfiguration "+exc);
}
HikariConfig config = new HikariConfig() {{
setDataSource(dataSource);
setConnectionTestQuery("SELECT 1");
}};
HikariDataSource hikariDataSource = new HikariDataSource(config);
return hikariDataSource;
}
#Bean
public JdbcTemplate jdbcTemplate(#Qualifier("dataSource") DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource());
return jdbcTemplate;
}
}
ERROR STACK TRACE
[ main] c.j.a.w.e.d.SpringJDBCLocalConfiguration : inside SpringJDBCLocalConfiguration.dataSource method flushStrategy
[ main] com.zaxxer.hikari.HikariConfig : sybase-pool - idleTimeout is close to or more than maxLifetime, disabling it.
[ main] com.zaxxer.hikari.HikariDataSource : sybase-pool - Starting...
[ main] com.zaxxer.hikari.pool.PoolBase : sybase-pool - Driver does not support get/set network timeout for connections. (com.sybase.jdbc4.jdbc.SybConnection.getNetworkTimeout()I)
[ main] com.zaxxer.hikari.pool.HikariPool : sybase-pool - Exception during pool initialization.
java.sql.SQLException: JZ0C0: Connection is already closed.
at com.sybase.jdbc4.jdbc.ErrorMessage.raiseError(ErrorMessage.java:779) ~[jconn4-7.07-27307.jar!/:na]
at com.sybase.jdbc4.jdbc.SybConnection.checkConnection(SybConnection.java:4010) ~[jconn4-7.07-27307.jar!/:na]
at com.sybase.jdbc4.jdbc.SybStatement.close(SybStatement.java:744) ~[jconn4-7.07-27307.jar!/:na]
at com.sybase.jdbc4.jdbc.SybStatement.close(SybStatement.java:719) ~[jconn4-7.07-27307.jar!/:na]
at com.sybase.jdbc4.jdbc.MdaManager.loadMetaData(MdaManager.java:573) ~[jconn4-7.07-27307.jar!/:na]
at com.sybase.jdbc4.jdbc.MdaManager.<init>(MdaManager.java:188) ~[jconn4-7.07-27307.jar!/:na]
at com.sybase.jdbc4.jdbc.MdaManager.<init>(MdaManager.java:171) ~[jconn4-7.07-27307.jar!/:na]
at com.sybase.jdbc4.jdbc.SybConnection.checkMDA(SybConnection.java:4155) ~[jconn4-7.07-27307.jar!/:na]
at com.sybase.jdbc4.jdbc.SybConnection.getMDA(SybConnection.java:3685) ~[jconn4-7.07-27307.jar!/:na]
at com.sybase.jdbc4.tds.Tds.setOption(Tds.java:1829) ~[jconn4-7.07-27307.jar!/:na]
at com.sybase.jdbc4.jdbc.SybConnection.setReadOnly(SybConnection.java:2586) ~[jconn4-7.07-27307.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.setupConnection(PoolBase.java:409) ~[HikariCP-2.7.9.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:370) ~[HikariCP-2.7.9.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:194) ~[HikariCP-2.7.9.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:460) [HikariCP-2.7.9.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:534) [HikariCP-2.7.9.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) [HikariCP-2.7.9.jar!/:na]
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81) [HikariCP-2.7.9.jar!/:na]
The issue was application was running in cloud and able to establish the database connection but seems firewall killing the connection so at the time of connection pool creation no active connections were found causing this error. I tried explicitly whitelisting the ip address and port but still same issue,but the root cause is the firewall blocking connection.

Spring boot unable to connect redis client Jedis to pool: Connection refused

I'm new to Spring boot development and all I want is to enable a Session for an Admin user. I'm writing a REST stateless (API) and a stateful service and I'm following a tutorial which is using redis in-memory-database for storing user sessions. I'm already using MySQL/JDBC for storing other data. Using redis and jdbc doesn't conflict?
In order to enable user session, I made the following:
These are the dependencies that I have added lately:
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.session/spring-session -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
<version>1.3.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
Creating a Jedis Connection Factory:
#Configuration
#EnableRedisHttpSession
public class SessionConfig extends AbstractHttpSessionApplicationInitializer {
#Bean
public JedisConnectionFactory jedisConnectionFactory() {
return new JedisConnectionFactory();
}
}
And the secured http configuration:
#Configuration
#EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
#Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("admin").password("password").roles("ADMIN");
}
#Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic().and()
.authorizeRequests()
.antMatchers("/").hasRole("ADMIN")
.anyRequest().authenticated();
}
}
I have also added the redis connection hostname and port in the application.properties:
# ===============================
# = REDIS
# ===============================
spring.redis.host=localhost
spring.redis.port=6379
However, when I run the application, the following error is thrown:
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 35 common frames omitted
I have tried to change localhost to 192.168.1.2 (my PC's local IP), tried to change the port but the connection is still refused.
This is the stacktrace first line:
[restartedMain] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
I don't know what else I could do. I'm having an antivirus (Windows). Should I disable it? Should I disable the firewall? Should I scan the ports to see what ports are opened?
Edit:
I have already tried using redis standalone configuration to pass the hostname and the port, but still can't connect:
public class SessionConfig extends AbstractHttpSessionApplicationInitializer {
#Bean
public JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration("127.0.0.1", 6379);
return new JedisConnectionFactory(redisStandaloneConfiguration);
}
}
Configure the Jedis' connection pool:
spring:
redis:
client-type: jedis
jedis:
pool:
enabled: true
max-active: 4
max-idle: 4
max-wait: -10ms
min-idle: 0
If it is localhost. Try with 127.0.0.1:****
Sometimes using ip (192.168.x.x) can give errors ...
# ===============================
# = REDIS
# ===============================
spring.redis.host=127.0.0.1
spring.redis.port=6379

Failed to get driver instance for oracle

I’m trying to connect to my oracle database, I’m using a spring boot configuration together with YAML file, I’ve configured jdbc in pom and jpa, but it still fails to connect.
I’ve tried many different configuration for the url:
1) jdbcUrl=jdbc:oracle:thin://test.test.test:1521
2) jdbcUrl=jdbc:oracle:thin#test.test.test:1521
3) jdbcUrl=jdbc:oracle://test.test.test:1521
4) jdbcUrl=jdbc:oracle#test.test.test:1521
here my application.yml
spring:
profiles: test
datasource:
onlineterminierung:
url: jdbc:oracle: jdbc:oracle:thin://test.test.test:1521
database: test
username: test
password: test
driverClassName: oracle.jdbc.driver.OracleDriver
defaultSchema:
maxPoolSize: 20
hibernate:
hbm2ddl.method: update
show_sql: false
format_sql: true
dialect: org.hibernate.dialect.Oracle10gDialect
and here the DataSource bean:
/*
* Configure HikariCP pooled DataSource.
*/
#Bean
public DataSource dataSource() {
DataSourceProperties dataSourceProperties = dataSourceProperties();
HikariDataSource dataSource = (HikariDataSource) DataSourceBuilder.create(dataSourceProperties.getClassLoader())
.driverClassName(dataSourceProperties.getDriverClassName()).url(dataSourceProperties.getUrl()).username(dataSourceProperties.getUsername())
.password(dataSourceProperties.getPassword()).type(HikariDataSource.class).build();
dataSource.setMaximumPoolSize(maxPoolSize);
return dataSource;
}
here the pom:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
<scope>test</scope>
</dependency>
here the stack:
HHH000342: Could not obtain connection to query metadata : Failed to get driver instance for jdbcUrl=jdbc:oracle:thin://test.test.test:1521
Unable to build Hibernate SessionFactory
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
Caused by: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:oracle:thin://test.test.test:1521
Caused by: java.sql.SQLException: No suitable driver
Some idea?
Syntax:
jdbc:oracle:thin:#host:port:db","usname","pwd"
#Autowired
DataSource dataSource;
#Bean(name = "dataSource")
public DriverManagerDataSource dataSource() {
DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
driverManagerDataSource.setDriverClassName("oracle.jdbc.OracleDriver");
driverManagerDataSource.setUrl("jdbc:oracle:thin:#hostname:1521/dbname");
driverManagerDataSource.setUsername("uname");
driverManagerDataSource.setConnectionProperties(getadditionalJpaProperties());
driverManagerDataSource.setPassword("password");
return driverManagerDataSource;
}
Properties getadditionalJpaProperties() {
Properties properties = new Properties();
// properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
properties.setProperty("hibernate.show_sql", "true");
return properties;
}
Always use the long form of the connection URL that gives you the flexibility to pass various connection level parameters. A code sample DataSourceSample on GitHub has a sample URL for reference.
jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS=(HOST=myhost)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=myorcldbservicename)))";
I ran into this problem. and I was mistakenly ignoring a line of code
driverManagerDataSource.setDriverClassName("oracle.jdbc.OracleDriver");
or in bean config
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
I am using Oracle 11G and Jersey + Boot server running on Websphere

Resources