2012-12-18 191 views
7

我一個外部Web服務,它的作品通過HTTPS,我可以生成Java類的wsimport但是當我invnoke服務我recive後續例外:web服務與HTTPS

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(); 
    } 
} 

我tryed使用了SoapUI調用web服務,但它顯示了另一種情況例外:

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)... 

編輯:

此WebService是我的,但它是在一個外部服務器上,我看到了我的課ColleagueService(那不是我誰做的),它與annoted:

@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重定向所有requestes與路徑/服務/到JBoss服務器(JBoss服務器是主機ECM01 ),無論如何,wsdl是錯誤的,因爲se rvices是https和wsdl我已經http

任何人都可以幫忙嗎?謝謝。的java.net.UnknownHostException:

+0

PS:我可以在瀏覽器中訪問https://my.webservice.url.com/ColleagueService?wsdl。 –

+0

你是否有機會獲得代理? –

+0

@ AndersR.Bystrup是的,在我的Intranet中有一個代理。 –

回答

8

所致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不反映真正的服務端點是完全正常的。在我工作的任何地方,都使用了已知的錯誤URI(例如,本地主機,其中所有內容都分佈在不同的主機上)。客戶端可以通過配置機制顯式設置端點(請參閱上述JAX-WS客戶端代碼)。在開發過程中防止在從開發到生產的階段中使用錯誤的主機。

也就是說,當使用自動生成的WSDL時,我認爲認爲 SOAP地址元素是如何生成的,它是JAX-WS實現的實現細節。我不確定,因爲我從來沒有依賴過它。我會參考你的容器實現的文檔。

+0

謝謝@McDowller,我想你發現我的問題,我認爲我的wsdl是錯的,你能幫我嗎?查看我在帖子上編輯過的內容。 –