转:http://www.blogjava.net/Hafeyang/archive/2010/01/12/309178.html
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="http://hafeyang.blogjava.net"的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>
分享到:
相关推荐
Spring+cxf配置接口+mybatis配置
idea+maven+spring+cxf
Spring+CXF+MyBatis整合代码,运行即可使用。
Spring + cxf = webservice 完整实例源码免费下载 完全免费。此资源仅为文档提供。 版权为百度文档 "Spring + cxf = webservice 完整实例源码免费下载" 所有。
最新cxfWebservice服务整合,其中整合的框架有mybatis+srping3+cxf2.6.3大家可以参考一下,绝对可用信不信只有下载,瞧了才知道!
Spring+CXF+tomcat开发webservice,包含服务端和客户端,导入myeclipse就可以用。帮助大家搭建webservice框架,实现webservice功能。
Web项目中基于Maven与Spring整合的WebService之cxf的实现⬇️ 详情请参考如下链接: https://locqi.github.io/locqi.com/2018/09/05/Eclipse+Maven+Spring+CXF-create-WebService/
spring+cxf 完整的整合jar包,下载下来就能用,很全面
spring + cxf + mybatis整合
spring+cxf_demo
CXF+spring+struts实现WebService
Spring+CXF+MyBatis整合客户端代码
spring+cxf 入门demo 包括spring配置,web配置,代码实现,简单易懂
本java工程实现了spring+cxf快速开发webservice jar包齐全导入myeclipse可直接二次开发
使用idea创建maven项目组建spring+cxf 客户端使用idea创建java Enterprise 中的WebServices Client进行创建
最近开发了一个基于ssm(Spring+SpringMVC+Mybatis)的项目,整合了CXF发布webservice。现在来分享项目源码,希望能帮助到有需要的朋友。
maven+spring+cxf+mybatis 搭建的webservice项目
spring与cxf的资料,整合spring与cxf的资料
ibatis+spring+cxf+mysql搭建webservice的客户端,文章地址在http://blog.csdn.net/cenyi2013/article/details/17315755. 服务端源码的下载地址在http://download.csdn.net/detail/cenyi2012/6712729
Spring+CXF 发布WebService服务