Jax-ws java.net.ConnectException: Connection refused - networking

I'm experiencing an odd networking problem connecting to a web service running on glassfish from a java client running on tomcat using JAX-WS (Metro). Here's the scenario...
Both servers are running on my local machine.
If I configure the client to connect to the WS endpoint using 127.0.0.1, the request works fine.
If I configure the client to connect to the WS endpoint using my IP address, I immediately get java.net.ConnectException: Connection refused. The same thing happens if I use my hostname.
The odd thing is that if I hit the endpoint from SoapUI, the request works fine if use 127.0.0.1, my IP address or my hostname.
Here's the exception I'm getting...
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:529)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:120)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:256)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:184)
at com.sun.xml.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:137)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:641)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:600)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:585)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:482)
at com.sun.xml.ws.client.Stub.process(Stub.java:323)
at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:161)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:113)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:144)
at $Proxy51.listAttributeTypes(Unknown Source)
at com.myapp.store.service.client.JaxWsProductAdminServiceClient.listAttributeTypes(JaxWsProductAdminServiceClient.java:71)
at com.myapp.admintool.ProductAttributeController$_closure1.doCall(ProductAttributeController.groovy:26)
at com.myapp.admintool.ProductAttributeController$_closure1.doCall(ProductAttributeController.groovy)
at java.lang.Thread.run(Thread.java:680)
Any thoughts or pointers appreciated!

I have seen a similar problem when running the JAX-WS webservice on a linux box with an entry in /etc/hosts that points the computer's hostname to localhost.
This seems to cause the JAX-WS webservice to be started on http://localhost:port/endpoint and therefore only be accessible from that machine.

'Connection refused' means that there is nothing listening at the IP:port you specified. One or both of them is wrong.

Related

Ngrok errors '502 bad gateway' - How to point web server to point 5000

I'm new to Web App so I'm sorry if this is a simple question.
I enter: ngrok http 5000
Then when I go to the correct https address I get the message below.
The connection to https://e71eb98330fe.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address 127.0.0.1:5000.
Make sure that a web service is running on 127.0.0.1:5000 and that it is a valid address.
The error encountered was: dial tcp 127.0.0.1:5000: connect: connection refused
According to this answer:
I need to set up a web server and point it to local host 5000.
But my error is slightly different and even when I try going to: localhost:5000
It doesn't work.
Is the problem just that I need to point a web server to 5000? How do I do that?

ngrok not connecting to local server

So, I am running ngrok (current version) on my Mac OSx. But I am getting the following error:
Failed to complete tunnel connection
The connection to http://35504712.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:3746.
Make sure that a web service is running on localhost:3746 and that it is a valid address.
The error encountered was: dial tcp xx.xx.xx.xx:3746: getsockopt: connection refused
I know my server is running properly, as I can actually click the link to my localserver in the error message and get a response from my server.
Any ideas on how to diagnose?
Have you made sure you're running ngrok inside your project directory, also can you still access localhost:3746?
Also what command are you using to start hosting the ngrok sever?

H2 Database (Server) TCP connection timeout & connection pooling

I started the server and then application on a certain IP and Port from scratch (no dulpicate servers or port already used). The application was crashing due to java-lang-OutOfMemory error, saying that no new thread can be created. I allocated JVM 4G memory, and now that error is silent. But, now afterwards starting the client is crashing again. It runs for about 10-15 seconds and crash with SocketTimeoutException. Here is the trace
org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.SocketTimeoutException: connect timed out: MYIPADDRESS" [90067-172]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:158)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:407)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:295)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:105)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:90)
at org.h2.Driver.connect(Driver.java:73)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at com.org.tseries.simulator.IPEmailSeriesTestDriver.shootH2(IPEmailSeriesTestDriver.java:201)
at com.org.tseries.simulator.IPEmailSeriesTestDriver.processSimulator(IPEmailSeriesTestDriver.java:160)
at com.org.tseries.simulator.IPEmailSeriesTestDriver.main(IPEmailSeriesTestDriver.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at org.h2.util.NetUtils.createSocket(NetUtils.java:119)
at org.h2.util.NetUtils.createSocket(NetUtils.java:100)
at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:95)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:403)
... 14 more
It is crashing when I run the client from terminal but when I ran the same client from STS (eclipse based IDE), it didnt crashed. Any setting or flag I need to add while running the client?
UPDATED: It is solved with appending AUTORECONNECT=TRUE in connection string. More details here, h2database.com/html/features.html#auto_reconnect
But now, I am interested in making a connection pool at Server end that allows different TCP clients to connect. The server shall serve the clients from the connection pool instead of clients reconnecting again. How can it be achieved?
Try open C:\Users\Superuser\db.lock.db. If this database already running you will see IP and port. Then in console type command netstat -ano. It will display all processes. Find PID of proccess that holds IP and port you found in .db file. Than you may kill this proccess using Task Manager or with help of command in console.
Another way: check all configs. You may use different IP in different configs. Synchronize this

Connection refused - not consistent

I have an application that is used to make hotel bookings. The application takes an XML message, transforms the XML into another XML message and sends this new XML to another application. I am able to book hotels successfully.
When I try to amend this booking (different XML request, same application, same URL) I get a 'Connection refused' error.
I would have thought that there'd be consistency (all work or none) but there's not.
Anyone any idea why?
"Connection refused" means that no application is accepting connections on the port and host that you try to connect to. It can be caused by
The application is actually running on a different host or a different port
The application crashed and hasn't been restarted
The application is buggy: it closes the listening server socket from time to time, so that it is not listening for connection attempts all the time
Firewall is configured to respond to new connections with a "connection refused" even if the application was able to accept a connection

Asp.net - Microsoft SQL Server outgoing connections

I was wondering if there is a way to see if a server blocks outgoing connections. I am trying to connect to an external database from a client's server.
This is the error I get:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
Edit:
I forgot to say I only have access to the plesk control panel. That's why I was asking if there is a way with asp.net.
When you say "server", do you mean the asp.net server, or the SQL server? And are both machines on the same network? Is this hosted?
Sql Server:
They can remove the OPENROWSET functionality, so you can't connect to remote servers, regardless
I doubt they are giving you access to linked servers in a hosted env
ASP.Net
You can try to connect to the other server via a regular connection, and see if that works.
Download a tracert component, and use that to try to trace from your server to the remote one.
If it dies somewhere inside your network, then that is your answer (it is blocked)
If it works, the outbound is open. Doesn't mean 1433 is open though.
If it dies after, not blocked, but maybe the remote is blocking icmp echo
Remember to try to tracert to somewhere else that you know works
It will be hard to tell what is killing the connection on 1433, if you can get to the server using other means. Could be the firewall, their fw, etc.
The trusty telnet method:
telnet theserver 1433
If this times out, the server is not listening. If the screen blanks and you can type something, the server is listening and no firewall is blocking the connection.
In Vista and Windows 7, you have to install telnet as a Windows component from Control Panel -> Programs and Features.

Resources