postgres server refuses to connect to heroku - java

I've set up a remote postgresql database for a gradle app that I'd like to deploy on Heroku. When running my app on my machine it works fine. However, I had a hard time connecting to the database that I've set up on Heroku, so I thought I'd just try to connect to my remote database. This is the error that showed up in my app log:
2016-08-18T13:28:12.606715+00:00 app[web.1]: [JarClassLoader] INFO: findResource(): unable to locate "org/postgresql/translation/messages_en.properties"
2016-08-18T13:28:12.609362+00:00 app[web.1]: Exception in thread "main" java.lang.reflect.InvocationTargetException
2016-08-18T13:28:12.609487+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2016-08-18T13:28:12.609542+00:00 app[web.1]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2016-08-18T13:28:12.609642+00:00 app[web.1]: at java.lang.reflect.Method.invoke(Method.java:498)
2016-08-18T13:28:12.609715+00:00 app[web.1]: at com.simontuffs.onejar.Boot.main(Boot.java:161)
2016-08-18T13:28:12.609970+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
2016-08-18T13:28:12.610011+00:00 app[web.1]: at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:239)
2016-08-18T13:28:12.610060+00:00 app[web.1]: at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
2016-08-18T13:28:12.610112+00:00 app[web.1]: at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:127)
2016-08-18T13:28:12.610162+00:00 app[web.1]: at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)
2016-08-18T13:28:12.610440+00:00 app[web.1]: at org.postgresql.Driver.connect(Driver.java:282)
2016-08-18T13:28:12.610602+00:00 app[web.1]: at net.bethydiakabana.mbta.MbtaApplication.run(MbtaApplication.java:79)
2016-08-18T13:28:12.611050+00:00 app[web.1]: Caused by: java.net.ConnectException: Connection refused
2016-08-18T13:28:12.611072+00:00 app[web.1]: at java.net.PlainSocketImpl.socketConnect(Native Method)
2016-08-18T13:28:12.611122+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
2016-08-18T13:28:12.611146+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
2016-08-18T13:28:12.611170+00:00 app[web.1]: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
2016-08-18T13:28:12.611286+00:00 app[web.1]: at org.postgresql.core.PGStream.<init>(PGStream.java:61)
2016-08-18T13:28:12.611331+00:00 app[web.1]: ... 23 more
2016-08-18T13:28:12.688094+00:00 heroku[web.1]: Process exited with status 1
2016-08-18T13:28:12.703273+00:00 heroku[web.1]: State changed from starting to crashed
I've read that I needed to change the permissions in the postgres configuration files yet I kept getting the same errors. What would be the best way to fix this on a windows machine?
EDIT:
I've set up a heroku postgres database to see if that would help. I'm not sure if it's still having connection issues as well as locating the main class. Would it still be worth connecting to my original database? This is the error that I'm getting now:
Starting process with command `java -Ddw.server.connector.port=37275 -Ddw.database.user=mmcyajlpsbacac -Ddw.database.password=C6nrfQzuoS2ZEMDaTqVEssPDxa -Ddw.database.url=jdbc:postgresql://ec2-54-235-254-199.compute-1.amazonaws.com:5 432/d8hvhhr0h3hr8d?user=mmcyajlpsbacac&password=C6nrfQzuoS2ZEMDaTqVEssPDxa&sslmo de=require $JAVA_OPTS -jar build/libs/mbta-tweets.jar server config.yaml`
2016-08-18T17:25:22.842387+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2016-08-18T17:25:22.846667+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx350m -Xss512k -Dfile.encoding=UTF-8
2016-08-18T17:25:23.220849+00:00 app[web.1]: Error: Could not find or load main class 432.d8hvhhr0h3hr8d?user=mmcyajlpsbacac&password=C6nrfQzuoS2ZEMDaTqVEssPDxa&sslmo
2016-08-18T17:25:23.317758+00:00 heroku[web.1]: Process exited with status 1
2016-08-18T17:25:23.331809+00:00 heroku[web.1]: State changed from starting to crashed
Here is a snippet of my yaml configuration that's read by the configuration class:
server:
type: simple
applicationContextPath: /application
adminContextPath: /admin
connector:
type: http
port: 8080
database:
# the name of your JDBC driver
driverClass: org.postgresql.Driver
# the username
user: someusername
# the password
password: somepassword
# the JDBC URL
url: jdbc:postgresql://host:port/dbname?user=username&password=password
Here is my procfile:
web: java $JAVA_OPTS -Ddw.server.connector.port=$PORT -Ddw.database.user=$JDBC_DATABASE_USERNAME -Ddw.database.password=$JDBC_DATABASE_PASSWORD -Ddw.database.url=$JDBC_DATABASE_URL $JAVA_OPTS -jar build/libs/mbta-tweets.jar server config.yaml

This message:
Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused
Suggests that you are trying to connect to a database on localhost on Heroku, which is certainly not correct. Can you show how you've configured your database connection in the Java code?

Related

How to access MySQL database on docker from Spring application on Docker?

I have a Spring Boot + MySQL application which cannot start in docker environment (manually it runs with no errors, but I have to change the application.properties)
So first I launch the MySQL in docker with these command:
docker run -p 3307:3306 --name mysqldb -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=exp mysql
And here it is the docker containers list:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0cc5c690fb7e mysql "docker-entrypoint.s…" 30 seconds ago Up 30 seconds 33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp mysqldb
This is screenshot of server connection settings for the database
When the database is running, I launch the Spring app with following commands in terminal:
docker run -p 9090:8080 --name exp --net spring-net -e MYSQL_HOST=mysqldb -e MYSQL_USER=root -e MYSQL_PASSWORD=root -e MYSQL_PORT=3306 exp
As you can see, I used the docker network which is connected to mysqldb with following command docker network connect spring-net mysqldb
Here are the application.properies settings:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.show-sql=true
spring.datasource.url=jdbc:mysql://mysqldb:3307/exp?verifyServerCertificate=true&useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.initialization-mode=always
spring.datasource.validationQuery=SELECT 1
spring.datasource.testWhileIdle=true
spring.server.port=8080
spring.server.compression.enabled=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql=true
When I try to start this, the application cannot find the mysqldb, here is the error from console:
Caused by: java.net.UnknownHostException: mysqldb
at java.net.InetAddress.getAllByName0(InetAddress.java:1281) ~[na:1.8.0_191]
at java.net.InetAddress.getAllByName(InetAddress.java:1193) ~[na:1.8.0_191]
at java.net.InetAddress.getAllByName(InetAddress.java:1127) ~[na:1.8.0_191]
at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:132) ~[mysql-connector-java-8.0.22.jar!/:8.0.22]
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:63) ~[mysql-connector-java-8.0.22.jar!/:8.0.22]
... 170 common frames omitted
However, when I change the spring.datasource.url inside application.properties to this:
spring.datasource.url=jdbc:mysql://localhost:3307/exp?verifyServerCertificate=true&useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
and build it it runs following exception:
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.22.jar!/:8.0.22]
And
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_191]
And
Caused by: 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 org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:403) ~[spring-orm-5.2.10.RELEASE.jar!/:5.2.10.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378) ~[spring-orm-5.2.10.RELEASE.jar!/:5.2.10.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.2.10.RELEASE.jar!/:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) ~[spring-beans-5.2.10.RELEASE.jar!/:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) ~[spring-beans-5.2.10.RELEASE.jar!/:5.2.10.RELEASE]
... 135 common frames omitted
Caused by: org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
I think it is too late to connect the mysql container to the same network as your spring container, so I would suggest you first create the network and use that in both of your containers.
$ docker network create my-network
Then you have to use the mysqldb container name and the inside port in your application.properties (because you are trying to connect from a container) like this:
spring.datasource.url=jdbc:mysql://mysqldb:3306/exp?verifyServerCertificate=true&useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false

Access denied in flyway on deploy to the heroku

When attempting to deploy, even with certain password and user, flyway is not allowed to migrate. Can someone help me? follows log error below.
2018-12-10 02:07:55.578 ERROR 4 --- [ main]
o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial
connections of pool. 2018-12-10T02:07:55.579896+00:00 app[web.1]:
2018-12-10T02:07:55.579898+00:00 app[web.1]: java.sql.SQLException:
Access denied for user ''#'ec2-54-91-197-4.compute-1.amazonaws.com'
(using password: YES) 2018-12-10T02:07:55.579899+00:00 app[web.1]: at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
~[mysql-connector-java-8.0.13.jar!/:8.0.13]
2018-12-10T02:07:55.579901+00:00 app[web.1]: at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
~[mysql-connector-java-8.0.13.jar!/:8.0.13]
2018-12-10T02:07:55.579903+00:00 app[web.1]: at
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
~[mysql-connector-java-8.0.13.jar!/:8.0.13]
Invocation of init method failed; nested exception is
org.flywaydb.core.internal.exception.FlywaySqlException:
2018-12-10T02:07:55.611900+00:00 app[web.1]: Unable to obtain
connection from database: Access denied for user
''#'ec2-54-91-197-4.compute-1.amazonaws.com' (using password: YES)
2018-12-10T02:07:55.611902+00:00 app[web.1]:
2018-12-10T02:07:55.611904+00:00 app[web.1]: SQL State : 28000
2018-12-10T02:07:55.611906+00:00 app[web.1]: Error Code : 1045
2018-12-10T02:07:55.611908+00:00 app[web.1]: Message : Access
denied for user ''#'ec2-54-91-197-4.compute-1.amazonaws.com' (using
password: YES) 2018-12-10T02:07:55.611909+00:00 app[web.1]:

Apache flink (Stable version 1.6.2) does not work

Recently, the stable version (1.6.2) of apache flink was released. I read this instruction. But when I run the following command:
./bin/flink run examples/streaming/SocketWindowWordCount.jar --port 9000
I get the following error:
The program finished with the following exception:
org.apache.flink.client.program.ProgramInvocationException: Job failed. (JobID: 264564a337d4c6705bde681b34010d28)
at org.apache.flink.client.program.rest.RestClusterClient.submitJob(RestClusterClient.java:268)
at org.apache.flink.client.program.ClusterClient.run(ClusterClient.java:486)
at org.apache.flink.streaming.api.environment.StreamContextEnvironment.execute(StreamContextEnvironment.java:66)
at org.apache.flink.streaming.examples.socket.SocketWindowWordCount.main(SocketWindowWordCount.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:529)
at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:421)
at org.apache.flink.client.program.ClusterClient.run(ClusterClient.java:426)
at org.apache.flink.client.cli.CliFrontend.executeProgram(CliFrontend.java:816)
at org.apache.flink.client.cli.CliFrontend.runProgram(CliFrontend.java:290)
at org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:216)
at org.apache.flink.client.cli.CliFrontend.parseParameters(CliFrontend.java:1053)
at org.apache.flink.client.cli.CliFrontend.lambda$main$11(CliFrontend.java:1129)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1836)
at org.apache.flink.runtime.security.HadoopSecurityContext.runSecured(HadoopSecurityContext.java:41)
at org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1129)
Caused by: org.apache.flink.runtime.client.JobExecutionException: Job execution failed.
at org.apache.flink.runtime.jobmaster.JobResult.toJobExecutionResult(JobResult.java:146)
at org.apache.flink.client.program.rest.RestClusterClient.submitJob(RestClusterClient.java:265)
... 20 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
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.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.flink.streaming.api.functions.source.SocketTextStreamFunction.run(SocketTextStreamFunction.java:96)
at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:94)
at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:58)
at org.apache.flink.streaming.runtime.tasks.SourceStreamTask.run(SourceStreamTask.java:99)
at org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:300)
at org.apache.flink.runtime.taskmanager.Task.run(Task.java:711)
at java.lang.Thread.run(Thread.java:748)
I found this link:Flink program cannot submit when i follow flink-1.4's quickstart and use "./bin/flink run examples/streaming/SocketWindowWordCount.jar --port 9000". However, it didn't help. I tried with Flink 1.6.2 with Hadoop® 2.8 as well as Flink 1.5.5 with Hadoop® 2.8 on mac os and ubuntu. But I just got the same error.
Works fine for me. Only difference I can see is that I'm using the version of Flink without hadoop, but I doubt that's the issue.
java.net.ConnectException: Connection refused usually means that there is no service listening on port 9000. You should have netcat running on this port via
$ nc -l 9000
(see https://ci.apache.org/projects/flink/flink-docs-stable/quickstart/setup_quickstart.html#run-the-example). If netcat is running, and it's not working, maybe try another port? It might also help to check all the log files for additional clues.
I solved the annoying problem by reading the nc -h (in Linux):
connect to somewhere: nc [-options] hostname port[s] [ports] ...
listen for inbound: nc -l -p port [-options] [hostname] [port]
So for listening a port, -p is mandatory, and I tried the following command:
nc -l -p 9000
and It worked.

Heroku App Crashing with NoClassDefFoundError: org/eclipse/jetty/server/Handler

I am trying to run an app on Heroku. I am doing CI on Travis and deploying from it. My code is at https://github.com/santoshkt/cdetsd123
When I went through the logs in heroku, I see following
2014-03-10T03:14:08.180220+00:00 heroku[web.1]: Starting process with command `j
ava $JAVA_OPTS -cp target/classes:target/dependency/* mytest.Main`
2014-03-10T03:14:10.692378+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Djav
a.rmi.server.useCodebaseOnly=true -Djava.rmi.server.useCodebaseOnly=true
2014-03-10T03:14:11.217814+00:00 app[web.1]: Exception in thread "main" java.lan
g.NoClassDefFoundError: org/eclipse/jetty/server/Handler
2014-03-10T03:14:11.286992+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundE
xception: org.eclipse.jetty.server.Handler
2014-03-10T03:14:11.287150+00:00 app[web.1]: at java.net.URLClassLoader$1.run
(URLClassLoader.java:217)
2014-03-10T03:14:11.287380+00:00 app[web.1]: at java.net.URLClassLoader.findC
lass(URLClassLoader.java:205)
2014-03-10T03:14:11.287271+00:00 app[web.1]: at java.security.AccessControlle
r.doPrivileged(Native Method)
2014-03-10T03:14:11.287380+00:00 app[web.1]: at java.lang.ClassLoader.loadCla
ss(ClassLoader.java:321)
2014-03-10T03:14:11.287380+00:00 app[web.1]: at sun.misc.Launcher$AppClassLoa
der.loadClass(Launcher.java:294)
2014-03-10T03:14:11.287645+00:00 app[web.1]: at java.lang.ClassLoader.loadCla
ss(ClassLoader.java:266)
2014-03-10T03:14:11.296871+00:00 app[web.1]: Could not find the main class: myte
st.Main. Program will exit.
To run this software locally, I use mvn jetty:run command and everything works fine. BTW I'm using maven + jetty in this application. I'm trying to debug this for last 6 hours with no clues. Any help is appreciated.
Instead of using a Main method to start the server, I solved this by changing the Procfile of Heroku using below.
web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war
Hope this helps anyone facing same issue.

Why am I getting the error "connection refused" with JMX

I am unable to connect to JMX object. Here is how I create a JMX object:
public static void main(String... args) {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
ObjectName name = new ObjectName("org.javasimon.jmx.example:type=Simon");
if (mbs.isRegistered(name)) {
mbs.unregisterMBean(name);
}
SimonManagerMXBean simonManagerMXBean = new SimonManagerMXBeanImpl(SimonManager.manager());
mbs.registerMBean(simonManagerMXBean, name);
System.out.println("SimonManagerMXBean registerd under name: "+name);
} catch (JMException e) {
System.out.println("SimonManagerMXBean registration failed!\n"+e);
}
while (true) {
// waiting for connections
}
}
This is a code for connecting to the remote JMX object:
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://127.0.0.1:9999/jndi/rmi://127.0.0.1:1099/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
SimonManagerMXBean simonManagerMXBean = JMX.newMXBeanProxy(mbsc, new ObjectName("org.javasimon.jmx.example:type=Simon"), SimonManagerMXBean.class);
return simonManagerMXBean;
Unfortunatelly I receive the following error:
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect]
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:338)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at my.code.RemoteSimonManagerFactoryImpl.createSimonManager(RemoteSimonManagerFactoryImpl.java:24)
at my.code.Demo.main(DemoAggregation.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect]
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1886)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:255)
... 9 more
Caused by: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:97)
... 14 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
... 19 more
If I try to connect to my JMX server (as to local process) using "jconsole" utility, I first get "ConnectionFailedSSL1" error, but when I click "Insecure" button in the error form, I connect successfully.
Both server and client are on the same computer.
I am using Windows 7 x64. Windows firewall is disabled.
Caused by: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
Most likely you are not running your server with the right JVM parameters. Jconsole uses a different mechanism to find and to connect to local processes. Your client code is trying to use TCP/IP to connect to your server. To turn this on you'll need to add something like the following to your Java command line on your server:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
See: How to activate JMX on my JVM for access with jconsole?
As an aside, you might want to consider using my SimpleJMX library which does all this code for you. It includes a JMX client code as well.
I've manage run Tomcat with JMX (Tomcat 8, Windows) by:
add
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
run with admin permissions
I received the same error. In my case I was using a #PostConstruct annotation and that method was attempting to use the RMI connection before Spring had a chance to configure the connection.
It didn't end up being anything wrong with the configuration of the connection, just that I accidentally tried to use it before it was ready. Hope this might help someone.
check your tomcat's bin folder for catalina.sh file. open it up and find java server parameters. add thoose followings to $JAVA_OPTS on any line you want.
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
you are done!

Categories

Resources