spring集成httpclient调用远端接口


一:spring httpClient配置文件

<beans xmlns="http://www.springframework.org/schema/beans"
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/jaxws   
        http://cxf.apache.org/schemas/jaxws.xsd"
        default-lazy-init="true" default-autowire="byName">

<description>Spring Http管理 </description>
<!-- httpclient线程池 -->
<bean id="connectionManagerParams"
class="org.apache.commons.httpclient.params.HttpConnectionManagerParams">
<property name="connectionTimeout" value="120000" />
<property name="soTimeout" value="120000" />
<property name="maxTotalConnections" value="30" />
<property name="defaultMaxConnectionsPerHost" value="20" />
</bean>

<bean id="connectionManager"
class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager">
<property name="params" ref="connectionManagerParams" />
</bean>

<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">
<constructor-arg>
<ref bean="connectionManager" />
</constructor-arg>
</bean>
<!-- HTTP动态代理类 -->
<bean id="requestHandler" class="com.onepiece.requestproxy.requestproxy.RequestProxyHandler">
<property name="httpClient" ref="httpClient"></property>
</bean>
<!-- 注册 HTTP请求动态代理接口 -->
<bean class="com.onepiece.requestproxy.factory.RequestBeanFactory">
<property name="packagesToScan">
<list>
<value>com.uytong.thirdbus.mutual.ofpay.request.*</value>
<value>com.uytong.thirdbus.mutual.lottery.request.*</value>
</list>
</property>
</bean>
</beans>

二:目录格式


三:配置本地接口
@IRequest("ofPayCommonRequest")
public interface IOfPayCommonRequest {
/**
* 查询账户余额
* @param userid
* @param userpws
* @param version
*/
@IRequestMethod(url = "http://api2.ofpay.com/queryuserinfo.do", type = RequestTypeEnum.GET, encode = RequestEncodeEnum.GB2312, result = RequestResultEnum.XML)
public OfPayUserInfoEntity queryuserinfo(
@RequestParams("userid") String userid,
@RequestParams("userpws") String userpws,
@RequestParams("version") String version);



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值