Spring+webservice的整合

首先在一个logicContext.xml中进行如下配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 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-2.5.xsd"
 default-autowire="byName" default-lazy-init="false">
 
 <!--2010-06-22 lj添加WebService配置-->
 <import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>
 
 <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  <property name="urlMap">
   <map>
    <entry key="/StarInforDealService">
     <ref bean="starInforDealServiceBean" />
    </entry>
   </map>
  </property>
 </bean>
  
 <bean id="starInforDealServiceBean" class="org.codehaus.xfire.spring.remoting.XFireExporter">
  <property name="serviceFactory" ref="xfire.serviceFactory" />
  <property name="xfire" ref="xfire" />
  <property name="serviceBean" ref="starInforDealServiceImpl" />
  <property name="serviceClass" value="com.ncs.bureausec.webservice.service.StarInforDealService" />
 </bean>

</beans>

接下来是写一个client端

import java.net.URL;
import java.util.List;

import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.transport.http.CommonsHttpMessageSender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ncs.bureausec.common.PropertiesReader;
import com.ncs.bureausec.icp.po.AutoStarAccess;

public class StarInforClient {

 private static Logger log = LoggerFactory.getLogger(WebsitePropertyCategoryClient.class);

 public static boolean sendInfor(String jsonarray){
  String url = PropertiesReader.getInstance().getProperty("SendInfor_URL");
  Client client = null;
  Object[] results = null;
  
  try {
   client = new Client(new URL(url));
   client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "0"); 
   results = client.invoke("insertStarInfor", new Object[] { jsonarray });
  } catch (Exception e) {
   log.error("下发失败");
   e.printStackTrace();
   return false;
  }
  
  return true;
 }
}

接下来是SendInfor_URL的在一个property中配置
SendInfor_URL=http://127.0.0.1:8080/icpproject_state_star/services/StarInforDealService?wsdl

 

最后是服务器端,首先写个接口

import java.util.List;

import com.ncs.bureausec.icp.po.AutoStarAccess;

public interface StarInforDealService {
 
 public boolean insertStarInfor(String jsonarray);

}

接口的实现

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ncs.bureausec.icp.dao.AutoStarAccessDao;
import com.ncs.bureausec.icp.po.AutoStarAccess;
import com.ncs.bureausec.webservice.service.StarInforDealService;

@Service("starInforDealServiceImpl")
public class StarInforDealServiceImpl implements StarInforDealService {
 
 @Autowired
 private AutoStarAccessDao autoStarAccessDao;
 
 @Override
 public boolean insertStarInfor(String jsonarray) {
  // TODO Auto-generated method stub
  
  JSONArray jarray = JSONArray.fromObject(jsonarray);
  
  List<AutoStarAccess> list = (List<AutoStarAccess>) JSONArray.toList(jarray,AutoStarAccess.class);  


  for(int i=0;i<list.size();i++){
   AutoStarAccess autoStarAccess = list.get(i);
   autoStarAccess.setDataTime(new Date());
   System.out.println(autoStarAccess.getIspName());
//   this.autoStarAccessDao.insertAutoStarAccess(autoStarAccess);
  }
  return true;
 }

}

 

注意webservice在client端到service传参时,只能是一些简单的类型,如int ,String等

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值