2014-01-16 22 views
3

我需要寫我自己的類告訴mule HTTPS連接到服務(wsdl)已驗證。我已經有了近乎完美的mule項目,但最後一塊遺失,發送文件在特定的網址。java類信任所有發送文件到https web服務

我想要什麼來實現的:

  1. 建立連接,併發送XML到目標URL

  2. 讀取響應,這也是在XML

服務器使用自安全簽署證書。我到目前爲止所做的是,我從該鏈接獲得了證書,並將其導入到.jks中。然後,我跟着可能所有的「教程」如何使用https連接器連接到mule服務器,但沒有任何工作在我的情況。

我認爲最好的事情是,如果有人可以幫助我創建java類來繞過鍵檢查並返回true(如已驗證)。例如:

URL url = new URL("https://www.google.com"); 
HttpsURLConnection conn= (HttpsURLConnection) url.openConnection(); 
conn.setHostnameVerifier(new HostnameVerifier() { 
    @Override 
    public boolean verify(String arg0, SSLSession arg1) { 
     return true; 
    } 
}); 

我該怎麼做騾子?我期望它會像this

我使用的是當前的mule版本(3.5.0)

謝謝!

編輯:

我的配置:

<https:connector name="HttpsConnector" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTP\HTTPS" dynamicNotification="true" > 
    <https:tls-server path="${keystore.path}" storePassword="${keystore.pass}" /> 
</https:connector> 

<sub-flow name="toSOAP" doc:name="toSOAP"> 
    <cxf:proxy-client payload="body" doc:name="SOAP" enableMuleSoapHeaders="false"> 
     <cxf:outInterceptors> 
      <spring:ref bean="WSS4JOutInterceptorBean"/> 
     </cxf:outInterceptors> 
    </cxf:proxy-client> 
    <https:outbound-endpoint exchange-pattern="one-way" host="${pref.host}" port="${pref.port}" path="${pref.path}" method="POST" connector-ref="HttpsConnector" doc:name="HTTP"/> 
</sub-flow> 
+2

「我認爲如果有人能夠幫助我創建java類來繞過密鑰檢查並返回true(經過驗證),那麼最好的辦法就是」。爲什麼?如果你不想要安全性,你爲什麼要使用SSL? – EJP

+0

僅僅因爲我無法使用其他地方提供的教程連接到服務。我嘗試將證書插入到keystore,然後在https連接器中設置該密鑰存儲區,但沒有任何工作。 – Matjaz

+1

這並沒有回答這個問題。如果您正在嘗試部署安全的解決方案,那麼'相信每個人'是毫無意義的。這個想法是解決問題,而不是破壞你的安全。 – EJP

回答

3

什麼工作對我來說是設置HTTPS連接器上的TrustManagerFactory。這是我做到的。

首先,創建一個包含要信任的SSL服務器證書的密鑰庫。您可以使用JDK附帶的工具(here's an example)創建密鑰庫。

然後,創建一個FactoryBean,在給定JKS密鑰庫和密碼的情況下爲您提供TrustManagerFactory。這裏有一個我做的是使用一個Spring的資源,這樣我可以提供從類路徑或文件系統的密鑰庫:

public class ExampleFactoryBean implements FactoryBean<TrustManagerFactory> { 

    private Resource keystore; 
    private String password; 

    @Override 
    public TrustManagerFactory getObject() throws Exception { 
      KeyStore truststore = KeyStore.getInstance("JKS"); 
      truststore.load(keystore.getInputStream(), password.toCharArray()); 
      TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); 
      tmf.init(truststore); 
      return tmf; 
    } 

    @Override 
    public Class<?> getObjectType() { 
     return TrustManagerFactory.class; 
    } 

    @Override 
    public boolean isSingleton() { 
     return true; 
    } 

    public void setKeystore(Resource keystore) { 
     this.keystore = keystore; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    } 
} 

最後,設置的TrustManagerFactory的HTTP連接器上,像這樣:

<https:connector name="myHttpsConnector"> 
    <spring:property name="trustManagerFactory"> 
     <spring:bean class="com.mycompany.ssl.ExampleFactoryBean"> 
      <spring:property name="keystore" value="classpath:mykeystore.keystore" /> 
      <spring:property name="password" value="mypassword" /> 
     </spring:bean> 
    </spring:property> 
</https:connector> 
相關問題