gpt4 book ai didi

java - 使用 HTTPS 的网络服务

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:18:14 25 4
gpt4 key购买 nike

我有一个外部网络服务,它通过 https 运行,我可以使用 wsimport 生成 java 类,但是当我调用该服务时,我收到以下异常:

Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.UnknownHostException: ECM01
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(Unknown Source)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(Unknown Source)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(Unknown Source)...
Caused by: java.net.UnknownHostException: ECM01
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)

我调用服务的类是这样的:

public static void main(String[] args) {
ColleagueServiceService cs = new ColleagueServiceService();
ColleagueService service = cs.getColleagueServicePort();

try {
service.getColleagues("user", "password", 1);
} catch (Exception_Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

我尝试使用 SoapUI 调用网络服务,但它显示另一个异常:

Tue Dec 18 09:40:06 BRST 2012:ERROR:org.apache.http.conn.HttpHostConnectException: Connection to https://my.webservice.url.com refused
org.apache.http.conn.HttpHostConnectException: Connection to https://my.webservice.url.com refused
at com.eviware.soapui.impl.wsdl.support.http.SoapUIMultiThreadedHttpConnectionManager$SoapUIClientConnectionOperator.openConnection(SoapUIMultiThreadedHttpConnectionManager.java:321)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:561)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport$Helper.execute(HttpClientSupport.java:236)
at com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport.execute(HttpClientSupport.java:345)
at com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.sendRequest(HttpClientRequestTransport.java:241)
at com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:123)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)...

Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)...

编辑:

这个 web 服务是我的,但它在外部服务器上,我看到了我的 ColleagueService 类(不是我做的)它被注释为:

@WebService(serviceName="ColleagueServiceService")
@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class ColleagueService {

生成的 wsdl 我有这个:

<port binding="tns:ColleagueServiceBinding" name="ColleagueServicePort">
<soap:address location="http://ECM01:80/services/ColleagueService"/>
</port>

外部服务器(客户端)有一个jboss服务器和一个apache http服务器,http服务器通过ProxyPass使用路径/services/将所有请求重定向到jboss服务器(jboss服务器是主机ECM01),无论如何wsdl是错误的因为服务是 https 并且在 wsdl 中我有 http

有人可以帮忙吗?谢谢。

最佳答案

Caused by: java.net.UnknownHostException: ECM01

这是 WSDL 中指定的主机吗?寻找这样的部分:

<wsdl:port binding="tns:FooBinding" name="FooPort">
<soap:address location="https://ECM01/FooService"/>
</wsdl:port>

如果是这样,您将不得不 set the endpoint在港口:

BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);

这将是另外的其他任务,例如提供 proxy configuration作为Anders R. Bystrup提到和(也许)configuring SSL client certificates .


WSDL 不能反射(reflect)真正的服务端点是完全正常的。在我工作过的任何地方,都会使用一个已知的错误 URI(例如 localhost,其中所有内容都分布在不同的主机上。)客户端可以通过配置机制显式设置端点(请参阅上面的 JAX-WS 客户端代码。)这允许灵 active 在开发期间防止在从开发到生产的过渡期间使用错误的主机。

也就是说,当使用自动生成的 WSDL 时,我认为 SOAP 地址元素的生成方式是您的 JAX-WS 实现的实现细节。我不确定,因为我从来没有依赖过它。我会引用您的容器实现的文档。

关于java - 使用 HTTPS 的网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13933048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com