WebService(二)发送数据+接收数据并进行处理操作

(一)使用WebService发送数据

1.定义webService接口
import java.util.List;
import javax.jws.WebParam;
import javax.jws.WebService;
import com.mxz.fvp.dto.ADto;
 
@WebService
public interface MxzReceiveService {
    public boolean addExpressBarRecord(@WebParam(name = "record") ADto record) throws Exception;// 方法1
    public boolean batchAddExpressBarRecord(@WebParam(name = "listRecord") List listRecord) throws Exception; // 方法2
}

2.工具类的创建

public class AUtil {
    private final static Logger logger = Logger.getLogger(AUtil.class);
    private static ApplicationContext factory = null;
    private static MxzReceiveService mxzReceiveService ;
    private static BService bService;
    static {
        factory = new ClassPathXmlApplicationContext("classpath:application-*.xml");
        bService = (BService) factory.getBean("bService");
    }
 
    private static synchronized MxzReceiveService getMxzReceiveService () {
      try {
            if (mxzReceiveService  == null) {
              JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
              factory.setServiceClass(MxzReceiveService class); // 1设置请求接口
              String linkUrl = CommonDataUtil.getConfigValue(ServiceConstants.MXZ_WEBSERVICE_URL);// 2查询数据库获取链接地址
              factory.setAddress(linkUrl + "services/MxzReceiveService "); //3设置地址
              mxzReceiveService = (MxzReceiveService ) factory.create(); // 4创建客户端对象
           }
      } catch (Exception e) {
          logger.error("mxzReceiveService Webservice initial error!");
          mxzReceiveService = null;
     }
      return mxzReceiveService ;
   }

3.具体使用

    public static void batchAddExpressBarRecord(List listRecord) {
        try {
                if(getFvpReceiveService() == null) // 3.1初始化链接对象
                       return;           
 
            //3.2数据其他处理操作
            if(!validateCode(listRecord))
                 return;   
       
           // 3.3调用接口
            boolean isSendSuccess = mxzReceiveService .batchAddExpressBarRecord(listRecord);
            if(!isSendSuccess) {
                //....其他操作
                return;
            }
            triggerCsdOorderBackState(listRecord); //3.3其他操作
        } catch (Exception e) {    //3.3其他操作
            saveSendFvp(listRecord, "m"); //....其他操作
            logger.error("Sent to mxzReceiveService.batchAddExpressBarRecord fail!" + e.getMessage());
        }
   }

 

(一)使用WebService接收数据并处理
1.创建webService接口
xml配置	

<!--CXF配置 -->
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
	
	<!-- 自定义endPoint -->
	<jaxws:endpoint id="AService" address="/waybilllog"
		implementor="#aService" />

	<bean id="aService"
		class="com.xx.service.webService.AServerImpl">
	<property name="bService" ref="bServiceImpl" />
	<property name="cDao" ref="cDao" />	
	</bean>

  

import javax.jws.WebParam;
import javax.jws.WebService;
 
@WebService(targetNamespace = "http://rece/")
public interface AServer {
public void receiveLog(@WebParam(name = "wayNo") String wayNo,
        @WebParam(name = "inputTypeCode") String inputTypeCode,
        @WebParam(name = "isSuccess") boolean isSuccess,
        @WebParam(name = "failreason") String failreason);   
}

2.定义接口实现类,并实现其他操作

@WebService(targetNamespace = "http://waybilllog/", endpointInterface = "com.mxz.service.webService.AServer ")
public class AServerImpl implements AServer{
      private Logger logger=Logger.getLogger(this.getClass()); // this:AServerImpl 
      private BService bService; //提供gettter/setter方法
      private CDaoImpl cDao; //提供gettter/setter方法
 
@Override
public void receiveLog(String waybillNo, String inputTypeCode, boolean isSuccess, String failreason) {
            logger.info("接收返回结果:单号"+wayNo+",类型:"+inputTypeCode+",状态:"+isSuccess+",描述:"+failreason);
           
            try{ //其他操作
                 .........................
           }catch(Exception ex){
                logger.error("接收返回结果失败:"+wayNo+","+inputTypeCode+","+isSuccess+","+failreason,ex);
          }
   }
}

 

 
 
 

转载于:https://www.cnblogs.com/mxzer/p/6411632.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值