4

I have a simple MVC web application where javascript code sends ajax requests to the controller and the controller sends back responses.

I built the app 2 years ago and everything used to work fine. Now I tried to run the app again locally and met with the following problem: whenever an Ajax request is sent from the frontend to the controller (running on localhost), the localhost refuses to connect and I get an ERR_CONNECTION_REFUSED message in (chrome's) javascript-console. (In Safari's javascript-console I get the following error message: "Failed to load resource: Could not connect to the server.")

I'm running the app using NetBeans 11.2. My NetBeans IDE uses GlassFish as server:

enter image description here

I removed the Glassfish server from NetBeans IDE, deleted its folder in my home directory and then added the Glassfish server again in my NetBeans IDE (which also entailed downloading the the newest version of the Glassfish server).

Still, the server refuses to accept any requests from the frontend.

I also tried using Payara Server (version 5.193). That didn't make a difference either.

The frontend itself looks fine at first glance by the way. That is, going to http://localhost:8080/myapp loads the frontend of the app. However, any dynamic features of the app don't work because the server refuses to accept any Ajax requests coming from the frontend (and initiated through mouse clicks).

How can I fix this?


I think I found the reason for the problem:

In my javascript-file I have the following line of code:

var url = "http://localhost:8080/myapp/Controller";

The variable "url" is passed to all the AJAX requests sent to localhost. But here is the crazy thing: the AJAX requests are not sent to "http://localhost:8080/myapp/Controller" but to "http://localhost:8081/myapp/Controller" !!!!!

enter image description here

What the hell is going on here?!

steady_progress
  • 3,311
  • 10
  • 31
  • 62
  • 2
    [1] Update your question to state which browser you are using, and your NetBeans version. [2] If using a Chrome-based browser the article ["ERR_CONNECTION_REFUSED: The best solutions when dealing with this Chrome error"](https://www.ionos.com/digitalguide/hosting/technical-matters/err-connection-refused/) might be helpful. [3] Regardless, it's prudent to test using a variety of browsers to see if you get different results. [4] Another thing to try is to use a different app server such as Payara or Tomcat. [5] Verify that you can [connect to localhost](http://localhost:8080). – skomisa Feb 10 '20 at 22:02
  • 1
    @steady-progress, can you connect to the default web page (localhost:8080)? Can you connect to the admin console (localhost:4848)? Are there any suspicious log messages in the output window (ctr+4) when deploying your app? Have you changed any settings in the old version of glassfish either form domain.xml or from the admin console? – Dmitry.M Feb 12 '20 at 07:25
  • @skomisa I am able to connect to localhost ... I already know the link you provided ... I edited my question to give more details – steady_progress Feb 12 '20 at 22:25
  • @Dmitry.M I'm able to connect to localhost:8080 and to the admin console (localhost:4848) – steady_progress Feb 12 '20 at 22:25
  • I'm using Mac, ctr+4 didn't work ... what do you mean by "output window"? – steady_progress Feb 12 '20 at 22:33
  • As far as I can remember I have never made any changes to any version of the Glassfish-Server I have used (including the current - newest - one) – steady_progress Feb 12 '20 at 22:35
  • @steady_progress OK. [1] Can you show (a simplified version of) your code so we can try to reproduce the problem? [2] Update your question to show the NetBeans version. [3] Open the NetBeans log (**View > IDE Log**), then submit the request(s) to reproduce the error. If anything is added to the IDE log as a result of the request(s), show that content. [4] Try starting the Glassfish/Payara server from the command line using `asadmin start-domain --verbose` rather than through NetBeans. Does the server start without errors? Does your app still get the error? [5] Which JDK version are you using? – skomisa Feb 12 '20 at 23:49
  • @steady_progress, Could you debug your ajax calls as mentioned [here](https://stackoverflow.com/questions/48591173/how-to-debug-ajax-calls-with-safari) and see what's going at the network tab when the browser sends ajax requests? Do you have any AdBlock installed on your browser? By "output window" I mean NetBeans -> window > output > Glassfish logs. – Dmitry.M Feb 13 '20 at 07:06
  • Can you summary the http listeners port configured in your glassfish domain, and those you frontend use to make its request? – cghislai Feb 15 '20 at 01:12
  • ok, I think I found the problem: my app keeps trying to connect to port 8081 instead port 8080 ... see my updated post – steady_progress Feb 16 '20 at 22:34
  • Can you please check if certificate is using TLS 1.2 atleast? as old TLS versions are officially dead now – Atta H. Feb 19 '20 at 13:53

2 Answers2

2

Did you use port 8081 before and then changed the variable "url" to the new port 8080? In this case, maybe the variable is still set to the old value in the cache. Restart your computer and see whether this fixes the problem.

Thomas_SO
  • 1,883
  • 2
  • 10
  • 20
  • 1
    @steady_progress, also, in that case, consider clearing the browser cache.[see](https://apple.stackexchange.com/questions/12049/how-to-clear-the-cache-or-do-a-hard-refresh-in-safari) – Dmitry.M Feb 17 '20 at 14:56
1

If the value of the attribute http-listener is localhost, it will refuse the connection external connection.

You can verify using its value using the command

asadmin> get server-config.network-config.network-listeners.network-listener.http-listener-1.*

Information similar to the following should returned:

server.http-service.http-listener.http-listener-1.acceptor-threads = 1
server.http-service.http-listener.http-listener-1.address = 0.0.0.0
server.http-service.http-listener.http-listener-1.blocking-enabled = false
server.http-service.http-listener.http-listener-1.default-virtual-server = server
server.http-service.http-listener.http-listener-1.enabled = true
server.http-service.http-listener.http-listener-1.external-port =
server.http-service.http-listener.http-listener-1.family = inet
server.http-service.http-listener.http-listener-1.id = http-listener-1
server.http-service.http-listener.http-listener-1.port = 8080
server.http-service.http-listener.http-listener-1.redirect-port =
server.http-service.http-listener.http-listener-1.security-enabled = false
server.http-service.http-listener.http-listener-1.server-name =
server.http-service.http-listener.http-listener-1.xpowered-by = true

Modify an attribute by using the set subcommand.

This example sets the address attribute of http-listener-1 to 0.0.0.0:

asadmin> set server.http-service.http-listener.http-listener-1.address = 0.0.0.0

Reference:

https://docs.oracle.com/cd/E19798-01/821-1751/ablaq/index.html

Devesh mehta
  • 1,505
  • 8
  • 22