我是JAX-WS的新手。我正在尝试访问公司内远程计算机上的Web服务。
我使用wsimport工具从我们内部网上的WSDL资源生成JAVA类。已成功创建Java文件。
我尝试通过SOAPUI发送请求,我收到了有效的回复。但是当我尝试运行我的代码时,它会抛出Connection拒绝。
这是我的代码。
URL url = new URL("https://xmattersqa.com/api/services/xmatters-4.1.7?wsdl");
QName qname = new QName("http://www.xmatters.com/webservices/schema#4.1.7", "xmatters- 4.1.7");
FindWhoIsOnDuty f = new FindWhoIsOnDuty();
Xmatters417 cdoubleprime = new Xmatters417(url,qname);
Xmatters417PortType port = cdoubleprime.getXmatters417SOAP11PortHttp();
FindWhoIsOnDutyReturn fresponse = port.findWhoIsOnDuty("fmsopsqa","fmsopsqa", "", "", "", "Default Company", "Test Grp 1","23/02/2013 0:00:00 AM", "24/02/2013 0:00:00 AM", false);
后来我尝试添加这段代码,但它仍然无效。
Authenticator.setDefault(new ProxyAuthenticator("fmsopsqa","fmsopsqa"));
System.setProperty("http.proxHost","sprdxmaws401.corp.net");
System.setProperty("http.proxyPort", "8081");
这就是我得到的
com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection refused
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:121)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:142)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:211)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:124)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
at $Proxy32.findWhoIsOnDuty(Unknown Source)
at FindDuty.main(FindDuty.java:76)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:523)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:227)
at sun.net.www.http.HttpClient.New(HttpClient.java:300)
at sun.net.www.http.HttpClient.New(HttpClient.java:317)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:970)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:949)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:836)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1014)
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:109)
服务端点链接似乎设置正确。
@WebServiceClient(name = "xmatters-4.1.7", targetNamespace = "http://www.xmatters.com/webservices/schema#4.1.7", wsdlLocation = "https://xmattersqa.com/api/services/xmatters-4.1.7?wsdl")
答案 0 :(得分:7)
我想这太晚了,但也许这个解决方案可以帮助其他人面对同样的问题。 我遇到了同样的问题,发现我的proxy-stub-object正在调用另一个URL,而不是我给服务对象。
java.net.URL wsdlURL = new URL("http://myServiceHost.com/online/myService?wsdl");
Service serviceWebClient = new ServiceWebClient(wsdlURL, new QName("my/namespace", "MyServiceName"));
我的调试器告诉我,我的服务没有尝试访问给定的URL,而是在服务标签下的此URL上的预计wsdl内部的内部IP地址。
<service name="MyServiceName">
<port name="MyServicePort" binding="tns:MyServiceBindingBinding">
<soap:address location="http://192.168.3.20:9443/online/myService/"/>
</port>
</service>
所以存根指向端点192.168.3.20,但我的服务不在同一台机器上,因此可能无法到达。为了解决这个问题,你必须像这样更正存根上的URL
MyService myService = serviceWebClient.getPort(MyService.class);
BindingProvider bindingProvider = (BindingProvider) myService;
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlURL.toString());
这为我解决了这个问题
答案 1 :(得分:0)
除了可能将防火墙列入白名单之外,如果您收到“ HTTP状态码404:已处理”,甚至可能没有该服务方法。
答案 2 :(得分:0)
这可能是愚蠢的,在我遇到的情况下,我在get和update操作上定义了两个端口出价,因此,它们的意思是相同的。删除重复项后,问题已修复。万一它可能对任何人都有帮助。
答案 3 :(得分:0)
由于这是搜索此错误消息时的顶级搜索结果。 如果您指定了错误的端口号,您还会收到“连接被拒绝”错误消息。对我来说,就是这么简单。仔细检查以确保。