Jax-ws java.net.ConnectException:连接被拒绝

发布于 2024-11-07 04:43:26 字数 2209 浏览 4 评论 0原文

我在使用 JAX-WS (Metro) 从 Tomcat 上运行的 Java 客户端连接到 glassfish 上运行的 Web 服务时遇到奇怪的网络问题。这是场景...

  • 两台服务器都在我的本地计算机上运行。
  • 如果我将客户端配置为使用 127.0.0.1 连接到 WS 端点,则该请求可以正常工作。
  • 如果我将客户端配置为使用我的 IP 地址连接到 WS 端点,我会立即收到 java.net.ConnectException:连接被拒绝。如果我使用我的主机名,也会发生同样的事情。

奇怪的是,如果我从 SoapUI 访问端点,并且使用 127.0.0.1、我的 IP 地址或我的主机名,则请求可以正常工作。

这是我遇到的例外...

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)

任何想法或指示表示赞赏!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╰◇生如夏花灿烂 2024-11-14 04:43:26

在 Linux 机器上运行 JAX-WS Web 服务时,我也遇到过类似的问题,其中 /etc/hosts 中有一个条目将计算机的主机名指向 localhost。

这似乎会导致 JAX-WS Web 服务在 http://localhost:port/endpoint 上启动,因此只能从该计算机访问。

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.

千秋岁 2024-11-14 04:43:26

“连接被拒绝”意味着没有任何内容在侦听您指定的 IP:端口。其中之一或两者都是错误的。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文