2015-11-29 83 views
0

我試圖找出移動下面的代碼位成彈簧的.xml配置文件的最好方法:(力異步和禁用chunkng所以NTLM作品)使用Spring的Apache CXF Async Conduit和NTLM?

final WSSoap port = new WS().getWSSoap(); 

final Client client = ClientProxy.getClient(port); 
final HTTPConduit httpConduit = (HTTPConduit) client.getConduit(); 

final HTTPClientPolicy httpClientPolicy = httpConduit.getClient(); 
httpClientPolicy.setAllowChunking(false); 
httpClientPolicy.setAutoRedirect(true); 

final BindingProvider bindingProvider = (BindingProvider) port; 
final Map<String, Object> requestContext = bindingProvider.getRequestContext(); 

final Credentials credentials = new NTCredentials("username", "password", "workstation", "domain"); 
requestContext.put(Credentials.class.getName(), credentials); 

requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://www.example.com/"); 
requestContext.put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE); 

我看過了的CXF配置頁面(這裏:http://cxf.apache.org/docs/configuration.html),但我沒有看到任何方式來做我需要的。

是否有一種乾淨的方式來處理使用spring的CXF的NTLM身份驗證?

更新:我已經想通了如何強制異步管道,使用以下:

<cxf:bus name="asyncBus"> 
    <cxf:properties> 
     <entry key="use.async.http.conduit" value="true"/> 
    </cxf:properties> 
</cxf:bus> 

<http-conf:conduit name="{http://www.webserviceX.NET}GlobalWeatherSoapPort.http-conduit"> 
    <http-conf:client AllowChunking="false" Connection="Keep-Alive"/> 
</http-conf:conduit> 

<jaxws:client id="weatherClient" bus="asyncBus" 
     address="http://www.webservicex.com/globalweather.asmx" 
     serviceClass="net.webservicex.GlobalWeatherSoap"/> 

但是我仍然無法正常訪問請求上下文,所以我可以加我的NTLM憑據。

回答

0

我想回答我自己的問題。在經過許多小時的調試並逐步完成Apache CXF代碼之後,我找到了一個解決方案。第二年春天配置將啓用NTLM身份驗證了一個異步管道:

<?xml version="1.0" encoding="UTF-8"?> 
<beans 
     xmlns="http://www.springframework.org/schema/beans" 
     xmlns:cxf="http://cxf.apache.org/core" 
     xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" 
     xmlns:jaxws="http://cxf.apache.org/jaxws" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation=" 
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
       http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd 
       http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
       http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd"> 

    <!-- 
     ~ 
     ~ create an asynchronous-only bus for NTLM requests 
     ~ 
    --> 

    <cxf:bus name="asyncBus"> 
     <cxf:properties> 
      <entry key="use.async.http.conduit" value="true"/> 
     </cxf:properties> 
    </cxf:bus> 

    <!-- 
     ~ 
     ~ configure conduit for NTLM request 
     ~ 
    --> 

    <http-conf:conduit name="{http://www.webserviceX.NET}GlobalWeatherSoapPort.http-conduit"> 
     <http-conf:client AllowChunking="false" AutoRedirect="true" Connection="Keep-Alive"/> 
    </http-conf:conduit> 

    <!-- 
     ~ 
     ~ create service stub 
     ~ 
    --> 

    <jaxws:client id="weatherClient" bus="asyncBus" 
      address="http://www.webservicex.com/globalweather.asmx" 
      serviceClass="net.webservicex.GlobalWeatherSoap"> 

     <jaxws:properties> 
      <entry key="org.apache.http.auth.Credentials"> 
       <bean class="org.apache.http.auth.NTCredentials"> 
        <constructor-arg value="DOMAIN/USER:PASSWORD"/> 
       </bean> 
      </entry> 
     </jaxws:properties> 

    </jaxws:client> 

</beans> 

也可以在NTCredentials構造函數,來指定用戶名,密碼,域和工作站,如果必要的。