<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    我是FE,也是Fe

    前端來源于不斷的點滴積累。我一直在努力。

    統計

    留言簿(15)

    閱讀排行榜

    評論排行榜

    Spring+CXF配置HTTP代理訪問Internet

    一個典型的CXF Webservice項目部署到正式環境后,服務器不能訪問外網,只能通過代理訪問外網,找了很多資料,剛開始想法是不用Spring的配置文件,直接用java編程訪問webservice。在java的Http請求中使用代理的方法如下:

    String authentication="username:password";//用戶+”:”+密碼
            String encodedLogin= new BASE64Encoder().encode(authentication.getBytes());
            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("IP", PORT));
            
            HttpsURLConnection conn = (HttpsURLConnection) console.openConnection(proxy );
            conn.setRequestProperty("Proxy-Authorization", " Basic " + encodedLogin);

    使用JaxWsProxyFactoryBean創建client

    System.setProperty("http.proxySet", "true");
            System.setProperty("http.proxyHost", "IP");
            System.setProperty("http.proxyPort", "PORT");
            
            JaxWsProxyFactoryBean f = new JaxWsProxyFactoryBean();
            f.setAddress("THE URL OF WEBSERVICE");
            f.setServiceClass(IService.class);
            IService client = (IService) f.create();

    可以使用代理,但是用戶名密碼是不能像第一種方法中那樣設置到HttpConnection里面去的。

    又在網上找了很多資料,終于找到了一個配置的方法。

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:cxf="http://cxf.apache.org/core" 
            xmlns:sec="http://cxf.apache.org/configuration/security" 
            xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" 
            xsi:schemaLocation=" 
                    http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                    http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
                    http://cxf.apache.org/configuration/security
                    http://cxf.apache.org/schemas/configuration/security.xsd
                    http://cxf.apache.org/transports/http/configuration
                    http://cxf.apache.org/schemas/configuration/http-conf.xsd"> 
            <http-conf:conduit name="*.http-conduit"> 
                <http-conf:proxyAuthorization>
                
                        <!-- 用戶名 -->
                        <sec:UserName>***</sec:UserName>
                        <!-- 密碼 -->
                        <sec:Password>***</sec:Password>
                        
                 </http-conf:proxyAuthorization>
                <!--
                    ProxyServer IP                ProxyServerPort PORT
                    ProxyServerType: HTTP or SOCKS
                 -->
                <http-conf:client
                        ProxyServer="192.168.1.4" 
                        ProxyServerPort="808"
                        ProxyServerType="HTTP"
                        Connection="Keep-Alive" 
                        AllowChunking="false"
                        ConnectionTimeout="50000" 
                        ReceiveTimeout="120000"
                        /> 
        </http-conf:conduit> 
    
        <!-- Client   -->
        </beans>

    <http-conf:conduit name="*.http-conduit"> 這里的name為”*.http-conduit”時,將會對所有的client類啟用這個代理,如果要配置某個client類使用代理,可以這么寫

    <http-conf:conduit name="{http://widgets/widgetvendor.net}widgetSOAPPort.http-conduit>
        ...
      </http-conf:conduit>

    {}里面的內容是webservice的wsdl的<wsdl:definitions name="serviceName" targetNamespace="{}之后.之前的內容是

    <wsdl:port name="BasicHttpBinding_IService" binding="i0:BasicHttpBinding_IService">

    <soap:address location="the address" />

    </wsdl:port>

    的name屬性。

    上述wsdl對應的配置是

    <http-conf:conduit name="{http://hafeyang.blogjava.net}BasicHttpBinding_IService.http-conduit> ... </http-conf:conduit>

    參考資料

    http://fusesource.com/docs/framework/2.2/bind_trans/HTTPConsumerConfig.html

    http://topic.csdn.net/u/20090331/09/f3ce02e0-29be-40cc-a534-9f2e5ac23f9e.html

    http://old.nabble.com/http:conduit-Proxy-td20462360.html

    http://mail-archives.apache.org/mod_mbox/servicemix-users/200807.mbox/<4885FCBB.5070506@gmail.com>

    posted on 2010-01-12 17:10 衡鋒 閱讀(2861) 評論(1)  編輯  收藏

    評論

    # re: Spring+CXF配置HTTP代理訪問Internet 2011-01-30 11:15 張見

    好  回復  更多評論   


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲性猛交xx乱| 亚洲av日韩av高潮潮喷无码 | 日本免费污片中国特一级| 亚洲第一页日韩专区| 午夜亚洲乱码伦小说区69堂| 夭天干天天做天天免费看| 亚洲国产AV无码一区二区三区 | GOGOGO高清免费看韩国| 中文字幕精品亚洲无线码一区应用| h视频在线免费观看| 亚洲爆乳精品无码一区二区三区| 大地影院MV在线观看视频免费| 亚洲AV无码一区东京热久久| 2015日韩永久免费视频播放| 亚洲最大中文字幕| 国产成人免费高清激情视频| 国产亚洲欧美在线观看| 亚洲无码黄色网址| 免费视频成人片在线观看| 亚洲国产综合自在线另类| 天天摸天天碰成人免费视频| 免费看一级毛片在线观看精品视频| 亚洲精品无码激情AV| 久久国产乱子免费精品| 亚洲伊人久久大香线蕉在观 | 久久WWW免费人成人片| 男女猛烈xx00免费视频试看| 亚洲人成在线播放网站| 69影院毛片免费观看视频在线| 亚洲国产精品无码第一区二区三区 | 永久黄网站色视频免费| 国产精品高清免费网站| 精品亚洲成AV人在线观看| 日韩在线视频免费看| a级成人毛片免费图片| 亚洲香蕉在线观看| 国产国拍亚洲精品福利 | 中文字幕 亚洲 有码 在线| 伊人久久亚洲综合影院| 最近最新的免费中文字幕| 狼人大香伊蕉国产WWW亚洲 |