Socket and postgreSQL connection problem while connecting spring boot application to postgreSQL in eclipse - postgresql

I am running a maven spring boot application which fetches data from postgreSQL. But I am getting such type of error when I run the project using the command
mvn spring-boot:run
->
2019-05-29 14:37:03.750 WARN 18368 --- [ main] unknown.jul.logger : IOException occurred while connecting to mc:19745
java.net.SocketTimeoutException: connect timed out
2019-05-29 14:36:52.241 ERROR 18368 --- [ main] org.postgresql.Driver : Connection error:
org.postgresql.util.PSQLException: The connection attempt failed.
Caused by: java.net.SocketTimeoutException: connect timed out
2019-05-29 14:36:53.245 ERROR 18368 --- [ main]
com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: The connection attempt failed.
I have mentioned only the main errors.
The application.properties file is:
spring.main.banner.mode=/offlinekyc
# Oracle settings
spring.datasource.url=jdbc:postgresql://mc:19745/post
spring.datasource.username=postgre
spring.datasource.password=123
spring.jpa.properties.hibernate.default_schema=oms_owner
spring.thymeleaf.cache=false
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect
http.mappers.json-pretty-print=true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
hibernate.discriminator.ignore_explicit_for_joined=false
# create and drop tables and sequences, loads import.sql
spring.jpa.hibernate.ddl-auto= update
spring.datasource.driverClassName=org.postgresql.Driver
# HikariCP settings
# spring.datasource.hikari.*
spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.maximum-pool-size=5
#hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect
#hibernate.default_schema=oms_owner
#hibernate.show_sql=true
#hibernate.format_sql=true
#hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
# Because detection is disabled you have to set correct dialect by hand.
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
Hibernate.properties file also have the same matter.
Here my post database is in mc:19745 server. I am little confused regarding localhost and server address.
Can anyone help in this matter?

Related

Talend error to connect to PostgreSQL Database

I have created a job which is writing data into a table in PostgreSQL DB, this is the staging job. After the staging job is completed, another job writes the staging data into the final table which is in the same database. However, the staging job works fine but the final job fails with the below error. I have worked with Talend and Database team and everything works fine at the server level. Not sure why the final job is failing when there is no issue with the staging job. Could anyone please help with this issue.
Talend version : 7.3
PostgreSQL version : 14.2
[INFO ]: aws_dev_engagebh.job_stg_view_to_ods_orders_view_0_3.Job_STG_VIEW_TO_ODS_ORDERS_VIEW - TalendJob: 'Job_STG_VIEW_TO_ODS_ORDERS_VIEW' - Start.
[statistics] connecting to socket on port 10633
[statistics] connected
[FATAL]: aws_dev_engagebh.job_stg_view_to_ods_orders_view_0_3.Job_STG_VIEW_TO_ODS_ORDERS_VIEW - tDBOutput_2 SSL error: java.net.SocketException: Connection reset
org.postgresql.util.PSQLException: SSL error: java.net.SocketException: Connection reset
at org.postgresql.ssl.MakeSSL.convert(MakeSSL.java:43)
at org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(ConnectionFactoryImpl.java:446)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:140)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:217)
at org.postgresql.Driver.makeConnection(Driver.java:458)
at org.postgresql.Driver.connect(Driver.java:260)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at aws_dev_engagebh.job_stg_view_to_ods_orders_view_0_3.Job_STG_VIEW_TO_ODS_ORDERS_VIEW.tDBInput_1Process(Job_STG_VIEW_TO_ODS_ORDERS_VIEW.java:5543)
at aws_dev_engagebh.job_stg_view_to_ods_orders_view_0_3.Job_STG_VIEW_TO_ODS_ORDERS_VIEW.runJobInTOS(Job_STG_VIEW_TO_ODS_ORDERS_VIEW.java:7971)
at aws_dev_engagebh.job_stg_view_to_ods_orders_view_0_3.Job_STG_VIEW_TO_ODS_ORDERS_VIEW.main(Job_STG_VIEW_TO_ODS_ORDERS_VIEW.java:7316)
Caused by: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
at sun.security.ssl.Alert.createSSLException(Alert.java:127)
at sun.security.ssl.TransportContext.fatal(TransportContext.java:370)
at sun.security.ssl.TransportContext.fatal(TransportContext.java:313)
at sun.security.ssl.TransportContext.fatal(TransportContext.java:308)
at sun.security.ssl.SSLTransport.decode(SSLTransport.java:141)
at sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1290)
at sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1199)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:401)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:373)
at org.postgresql.ssl.MakeSSL.convert(MakeSSL.java:41)

Spring boot app does not run when putting Amazon RDS endpoint to the datasource URL

My app is running fine locally when testing with Postgres. But I am trying to connect to my RDS database which has Status:'Available' and Publicly acessible: 'Yes'.
RDS environment image
When updating the properties file with Amazon RDS endpoint in the datasource URL I get an error when running the application. The username and password are also correct in the properties file.
Application.properties file image
The error on Intellij console is:
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:313) ~[postgresql-42.3.1.jar:42.3.1]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.3.1.jar:42.3.1]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:225) ~[postgresql-42.3.1.jar:42.3.1]
at org.postgresql.Driver.makeConnection(Driver.java:466) ~[postgresql-42.3.1.jar:42.3.1]
at org.postgresql.Driver.connect(Driver.java:265) ~[postgresql-42.3.1.jar:42.3.1]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar:na]
at
... 55 common frames omitted
2022-01-18 23:26:55.667 WARN 18380 --- [ restartedMain] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:313) ~[postgresql-42.3.1.jar:42.3.1]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.3.1.jar:42.3.1]
2022-01-18 23:26:55.667 INFO 18380 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
Hibernate:
drop table if exists employee cascade
2022-01-18 23:26:56.026 INFO 18380 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-01-18 23:27:07.043 ERROR 18380 --- [ restartedMain] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: The connection attempt failed.
at
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-01-18 23:27:07.074 ERROR 18380 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
at
Process finished with exit code 0
Any suggestions would be greatly appreciated.
Note that spring is not complaining about wrong username/password. It cannot even connect to the database to check if the username/password is correct.
That indicates a network issue (i.e. there is no network connectivity from your machine to the RDS instance).
Please check if your security group allows access to the given port (5432) from your IP

Hikari Connection Pool - org.postgresql.util.PSQLException: This ResultSet is closed

I am trying to create Hikari connection pool with Postgres database.
Hikari version is 3.4.1 and postgres driver version is 42.2.5
My connection properties are as follows.
mdb.hcp.driverClassName=org.postgresql.Driver
mdb.hcp.username=user1
mdb.hcp.jdbcUrl=jdbc:postgresql://localhost:2001/db1?ssl=false
mdb.hcp.password=pass
mdb.hcp.maximumPoolSize=1
mdb.contractSchema=schema1
I am getting below exception.
06-12-2019 17:40:08.181 [main] INFO com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Driver does not support get/set network timeout for connections. (Method org.postgresql.jdbc4.Jdbc4Connection.getNetworkTimeout() is not yet implemented.)
06-12-2019 17:40:08.649 [main] WARN com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Default transaction isolation level detection failed (This ResultSet is closed.).
06-12-2019 17:40:08.656 [main] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Error thrown while acquiring connection from data source
org.postgresql.util.PSQLException: This ResultSet is closed.
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkClosed(AbstractJdbc2ResultSet.java:2852)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.setFetchSize(AbstractJdbc2ResultSet.java:1875)
at org.postgresql.jdbc4.Jdbc4Statement.createResultSet(Jdbc4Statement.java:37)
at org.postgresql.jdbc2.AbstractJdbc2Statement$StatementResultHandler.handleResultRows(AbstractJdbc2Statement.java:221)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1853)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:405)
at org.postgresql.jdbc2.AbstractJdbc2Connection.execSQLUpdate(AbstractJdbc2Connection.java:382)
at org.postgresql.jdbc2.AbstractJdbc2Connection.getTransactionIsolation(AbstractJdbc2Connection.java:904)
at com.zaxxer.hikari.pool.PoolBase.checkDefaultIsolation(PoolBase.java:471)
at com.zaxxer.hikari.pool.PoolBase.checkDriverSupport(PoolBase.java:434)
at com.zaxxer.hikari.pool.PoolBase.setupConnection(PoolBase.java:402)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:355)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473)
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)
Please help!
Try to switch to a newer postgres driver version https://mvnrepository.com/artifact/org.postgresql/postgresql

Connect Timeout Exception on Url - http://localhost:8888 & Could not locate PropertySource: I/O error on GET request

When the Spring Cloud Dataflow Http-Source app Pod starts on kubernetes notice following two messages in console.
Connect Timeout Exception on Url - http://localhost:8888.
Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/http-source/default": Connection refused (Connection refused); nested exception is java.net.ConnectException
How to get this resolved?
subscriber to the 'errorChannel' channel
2019-09-15 05:17:26.773 INFO 1 --- [ main] o.s.i.channel.PublishSubscribeChannel : Channel 'application-1.errorChannel' has 1 subscriber(s).
2019-09-15 05:17:26.774 INFO 1 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started _org.springframework.integration.errorLogger
2019-09-15 05:17:27.065 INFO 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2019-09-15 05:17:27.137 INFO 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2019-09-15 05:17:27.141 WARN 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/http-source/default": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
If you look carefully, the following message will be logged as a WARN in the logs.
Connect Timeout Exception on Url - http://localhost:8888.
Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/http-source/default": Connection refused (Connection refused); nested exception is java.net.ConnectException
You'd see this WARN message for all the apps that we ship, SCDF, and Skipper servers that runs on K8s. This means that the apps, SCDF or Skipper don't have a config-server configured, so it defaults to the default http://localhost:8888.
Background: we provide the config-server dependency in all the apps that we ship to help you get started with it quickly.
If you don't use the config-server, that's fine; it will not cause any harm - nothing to worry, however.

JBoss EAP on Eclipse does not have jndi service

I was trying to follow some EJB tutorial, most of them started talking about JNDI, and I am having trouble to get the service running on the JBOSS AS.
I have tried both the community and EAP version of JBoss in Eclipse, but both fails.
So now whenever I run lines like BeanRemote beanRemote = (BeanRemote) context.lookup("somecontext"); it throws these error.
javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]]
Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]
Caused by: java.net.ConnectException: Connection refused: connect
well of course it is caused by the port not opened, but I think its because the Jboss server is not providing the service, although its web port and admin port 8080 and 9990 is working fine.
I am using eclipse Oxygen 4.7.0, I have downloaded the Red Hat JBoss developer Studio. I added the server via the "New Server" wizard, then downloaded the server runtimes within the wizard. However there just seems no way to configure jndi, nor can I find any file that is related to jndi or jnp in the downloaded path. The XML configuration showed that only Management 9990 and Web 8080 port is open.
I don't understand why is this not enabled by default, and I don't know what to do. Is JNDI configurable somewhere in the management console? please help
Turns out method of linking to jndi changed in EAP 7 from EAP 5
this articles shows the correct method.
jndi.properties has been changed to jboss-ejb-client.properties, and the standard config now becomes
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=yourhostaddress
remote.connection.default.port = 8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
and context lookup string has been changed to
ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>