JAX-WS 访问SSL 的WebService 老是HTTP transport error: Connection refused错误的解决办法。

最近用JAX-WS2.0开发一个WebService 客户端,访问普通http没有什么问题,但当访问 HTTPS时老是提示 HTTP transport error: Connection refused的错误,如下:

Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection refused: connect
 at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:119)
 at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:128)
 at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:74)
 at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:581)
 at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:540)
 at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:525)
 at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:422)
 at com.sun.xml.internal.ws.client.Stub.process(Stub.java:235)
 at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:120)
 at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:230)
 at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:210)
 at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:103)

我用Myeclipse10 带的“Test with Web Services Explorer”工具或SOAPUI工具测试,不管是HTTP还是HTTPS都可以得到正确的结果,就觉得奇怪了,到底哪里出了问题。

后来google 了一把,发现以下2篇文章,比较有用

https://www.java.net//node/666240

https://community.jboss.org/thread/204961?_sscc=t

文中都提到了要 覆盖 BindingProvider.ENDPOINT_ADDRESS_PROPERTY,

修改了代码,问题解决。

如:

String wnsaddr = "https://www.xxx.com/ws/"

One_Service service = new One_Service();

Wsport port = service.getPort(Wsport.class);

  ((BindingProvider) port).getRequestContext().put(
     BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wnsaddr);

port.dosomething();

 

 

 

posted @ 2013-05-22 22:19  finema  阅读(5398)  评论(0编辑  收藏  举报