why ConnectException: Connection refused: connect is thrown from HttpURLConnection.getResponseCode()? [duplicate] - java

This question already has answers here:
java.net.ConnectException: Connection refused
(19 answers)
Closed 3 years ago.
Why is ConnectException: Connection refused: connect exception thrown from HttpURLConnection.getResponseCode()?
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.getResponseCode(); // this line
Exception is:
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at com.datasoft.cbsdit.CbsditApplication.main(CbsditApplication.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)

Remote machine URL is incorrect or remote server is down,
mentioned code works fine, if you try with valid url value (e.g: https://stackoverflow.com) :)

Related

Connection timeout with openstack4j compute query

I'm trying out openstack4j, and I've run into a problem I don't know what could be causing.
Authentication to the cloud went smoothly:
OSClient os = OSFactory.builder()
.endpoint("http://xxx.xxx.xxx.xxx:yyyyy/v2.0")
.credentials(username,password)
.tenantName("admin")
.perspective(Facing.PUBLIC)
.authenticate();
However, once os is instanciated, I try running the following line:
List<? extends Flavor> flavors = os.compute().flavors().list();
And I get an ConnectionException{message=java.net.ConnectException: Connection timed out: connect, status=0}
What could be causing this?
Thanks in advance.
Stack trace:
Exception in thread "main" ConnectionException{message=java.net.ConnectException: Connection timed out: connect, status=0}
at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.invoke(HttpExecutorServiceImpl.java:58)
at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.execute(HttpExecutorServiceImpl.java:33)
at org.openstack4j.core.transport.internal.HttpExecutor.execute(HttpExecutor.java:51)
at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:178)
at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:172)
at org.openstack4j.openstack.compute.internal.FlavorServiceImpl.list(FlavorServiceImpl.java:32)
at com.mycompany.app.my_app.OpenStackCom.authOpenStack(OpenStackCom.java:127)
at com.mycompany.app.my_app.App.main(App.java:18)
Caused by: javax.ws.rs.ProcessingException: java.net.ConnectException: Connection timed out: connect
at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:229)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:224)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:656)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:653)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:653)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:388)
at org.openstack4j.connectors.jersey2.HttpCommand.execute(HttpCommand.java:86)
at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.invokeRequest(HttpExecutorServiceImpl.java:65)
at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.invoke(HttpExecutorServiceImpl.java:56)
... 7 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:321)
at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227)

java.net.ConnectException: Connection timed out: connect when we download java client application from Java web Start

Our Java Client Appllication(Java Swing Application) is downloaded by java web start.At that time its throw following exception.
I have following questions.
What is reason for this exception?
is this because of client code or Firewall(windows and internet)?
If I set java control panel->Network settings and check direct connection its working fine. if its "use browser setting" this exception fired.But some machines with "use browser setting" its working fine.
Does anyone have any idea?
Our Java Client Application (Java Swing Application) is downloaded by Java Web Start. At that time it's throw following exception.
java.net.ConnectException: Connection timed out: connect
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.access$200(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$9.run(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$9.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.sun.deploy.net.proxy.AbstractAutoProxyHandler.getJSFileFromURL(Unknown Source)
at com.sun.deploy.net.proxy.AbstractAutoProxyHandler.retrieveContentOfPACFile(Unknown Source)
at com.sun.deploy.net.proxy.AbstractAutoProxyHandler.contructLegacyPACScript_16(Unknown Source)
at com.sun.deploy.net.proxy.AbstractAutoProxyHandler.init(Unknown Source)
at com.sun.deploy.net.proxy.SunAutoProxyHandler.init(Unknown Source)
at com.sun.deploy.net.proxy.DynamicProxyManager.reset(Unknown Source)
at com.sun.deploy.net.proxy.DeployProxySelector.reset(Unknown Source)
at com.sun.javaws.Main.initializeExecutionEnvironment(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main.access$000(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.access$200(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$9.run(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$9.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown Source)
at java.net.URLConnection.getContentType(Unknown Source)
at com.sun.deploy.net.proxy.AbstractAutoProxyHandler.isSupportedINSFile(Unknown Source)
I have following questions.
1.What is reason for this exception?
2.is this because of client code or Firewall(windows and internet)?
3.If i set java control panel->Network settings and check direct connection its working fine. if its "use browser setting" this exception fired.But some machines with "use browser setting" its working fine.
Does anyone have any idea?

Not able to connect to MSSQL using Schemacrawler

I have installed Java 8 and I have the SchemaCrawler folder on E: on my machine. I run SQL Server 2012.
The cmd command used is below
sc.cmd -c graph -host=10.52.136.168 -user=sa -database=MyDBName schemacrawler.Main -infolevel=detailed -schemas=dbo -tabletypes=TABLE -outputformat=pdf -outputfile=database-diagram.pdf %*
I have checked the suggestions given here
but no luck . I still get the below error
schemacrawler.schemacrawler.SchemaCrawlerSQLException: Could not connect to jdbc
:hsqldb:hsql://10.52.136.168:9001/DeliveryIntelligence;readonly=true;hsqldb.lock
_file=false, with properties {user=sa}
at schemacrawler.schemacrawler.BaseDatabaseConnectionOptions.getConnecti
on(BaseDatabaseConnectionOptions.java:122)
at schemacrawler.schemacrawler.BaseDatabaseConnectionOptions.getConnecti
on(BaseDatabaseConnectionOptions.java:70)
at schemacrawler.tools.commandline.SchemaCrawlerCommandLine.execute(Sche
maCrawlerCommandLine.java:176)
at schemacrawler.tools.commandline.SchemaCrawlerMain.main(SchemaCrawlerM
ain.java:78)
at schemacrawler.tools.hsqldb.Main.main(Main.java:43)
Caused by: java.sql.SQLTransientConnectionException: java.net.ConnectException:
Connection refused: connect
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at schemacrawler.schemacrawler.BaseDatabaseConnectionOptions.getConnecti
on(BaseDatabaseConnectionOptions.java:115)
... 4 more
Caused by: org.hsqldb.HsqlException: java.net.ConnectException: Connection refus
ed: connect
at org.hsqldb.ClientConnection.openConnection(Unknown Source)
at org.hsqldb.ClientConnection.initConnection(Unknown Source)
at org.hsqldb.ClientConnection.<init>(Unknown Source)
... 10 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.hsqldb.server.HsqlSocketFactory.createSocket(Unknown Source)
... 13 more
You are using SchemaCrawler for HyperSQL. Please download and use SchemaCrawler for SQL Server instead.
Sualeh Fatehi, SchemaCrawler

exception: Connection refused: connect

I am trying to connect a client (which is behind the company's proxy) to a server (JBoss AS 5.0) which is hosting an application (JavaFX). And I am facing the following error.
exception: Connection refused: connect.
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.sun.deploy.net.HttpUtils.followRedirects(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doGetRequestEX(Unknown Source)
at com.sun.deploy.net.DownloadEngine.isUpdateAvailable(Unknown Source)
at com.sun.deploy.net.DownloadEngine.isUpdateAvailable(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.net.ConnectException: Connection refused: connect
However, if i am trying to access the application(JavaFX) locally, i have no problem loading the application. Do i need to configure any proxy for the client to access the server?
Any advice on solving this will be greatly appreciated.
Thanks in advance.
Kevin
It is a feature of JBoss check this document
start JBoss by
./run.sh -b 0.0.0.0
or
run.bat -b 0.0.0.0
Seems like Jboss server is not running.You need to start server.

Language Translation API

How can i convert language in my Java? Is there any API exist, which convert any language to any other language? I am using Google Translate API, but it giving me below exception.
java.lang.Exception: [google-api-translate-java] Error retrieving translation.
at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:123)
at com.google.api.translate.Translate.execute(Translate.java:69)
at com.nextenders.client.beans.ruleengine.RuleEngineTest.main(RuleEngineTest.java:27)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
null
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:107)
... 2 more
If anybody knows any API for translation, please tell me.
As suggested by the guy on JavaRanch, there is an issue with the connection to the API
Somewhere you will have specified a URL to connect to, something is blocking that, check you can access that address via ping

Categories

Resources