ESB 客户端调用 处理类

esb

package com.isoftstone.synchronize.entrance;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

import org.apache.log4j.Logger;
import org.jdom.Document;

import com.isoftstone.core.common.tools.DWTransformTool;
import com.isoftstone.core.common.tools.XmlTool;
import com.isoftstone.core.dto.RequestBody;
import com.isoftstone.core.dto.RequestBusinessObject;
import com.isoftstone.core.dto.RequestHead;
import com.isoftstone.core.dto.ResponseBusinessObject;
import com.isoftstone.fwk.vo.BusinessVo;
import com.isoftstone.httpclient.ESBClient;
import com.isoftstone.iaeap.datawindow.metadata.DataWindowMetaDataMgr;
import com.isoftstone.synchronize.dao.TempBrmTaxpaymentCodeDAO;
import com.isoftstone.synchronize.dao.TempBrmUwClaimDAO;
import com.isoftstone.synchronize.domain.TempBrmTaxpaymentCode;
import com.isoftstone.synchronize.domain.TempBrmUwClaim;
import com.isoftstone.synchronize.domain.request.SynchronizeRequestBase;
import com.isoftstone.synchronize.domain.response.SynchronizeResponseBase;
import com.isoftstone.synchronize.domain.response.SynchronizeResponseClaim;
import com.isoftstone.synchronize.domain.response.SynchronizeResponseTaxpaymentCode;
import com.isoftstone.synchronize.tool.SpringBeanTool;
import com.isoftstone.synchronize.tool.TableOperation;

public class SynchronizeEntrance {
    Logger logger = Logger.getLogger(SynchronizeEntrance.class);

    public  void synchronizeTableTaxpaymentCodeWithCore(Date startDate) throws Exception{//与核心 同步 Taxpayment表
        ResponseBusinessObject responseObject = connectToCore( "3", "0", /*start_tm*/startDate) ;//约定该表固定传"3"
        TempBrmTaxpaymentCodeDAO tempBrmTaxpaymentCodeDAO= (TempBrmTaxpaymentCodeDAO) SpringBeanTool.getBean("TempBrmTaxpaymentCodeDAO");
//        ResponseBusinessObject responseObject = generateTestResponse("D:\\application\\eclipse64ee\\workspace\\ilogSynchronized\\src\\syncTaxpaymentCode.txt") ;
//        log.info("同步处理业务数据-开始initSynchronizeResult");
        Map<String, Object> returnBatchesMap = transferResponseBusinessObject2ReturnMap(responseObject);
        List<TempBrmTaxpaymentCode> tempTaxpaymentCodeList = (List<TempBrmTaxpaymentCode>) returnBatchesMap.get("tempTaxpaymentCodeList");
        TableOperation.deleteTable(TableOperation.TRUNCATE_TEMP_T_BRM_TAXPAYMENT_CODE);//删除临时表
        tempBrmTaxpaymentCodeDAO.addTempBrmTaxpaymentCodes(tempTaxpaymentCodeList); //插入临时表
        StringBuilder sb  = new StringBuilder();
        TableOperation.deleteTable(TableOperation.DELETE_T_BRM_TAXPAYMENT_CODE_WITH_TEMP);//根据临时表的主键删除真实表中的行
        int effectCount = TableOperation.insertTable(TableOperation.INSERT_INTO_T_BRM_TAXPAYMENT_CODE);//把临时表中数据插入到真实表中
        TableOperation.deleteTable(TableOperation.TRUNCATE_TEMP_T_BRM_TAXPAYMENT_CODE);//删除临时表
        logger.info("更新T_BRM_TAXPAYMENT_CODE表总行数: "+ effectCount+"\n");

    }

    /**
     * 1    第一次取<核心数据>,得到需要传输的次数
     * 2    删除临时表
     * 3    循环次数,再取<核心数据>,插入到所有数据到临时表
     * 4    根据临时表的主键删除真实表中的行
     * 5    把临时表中数据插入到真实表中
     * 6    删除临时表
     * @throws Exception
     */
    public  void synchronizeTableClaimWithCore(Date startTime) throws Exception{//与核心 同步 Claim表

        ResponseBusinessObject responseObject = connectToCore( "1", " 0", /*start_tm*/ startTime ) ;
//        ResponseBusinessObject responseObject = generateTestResponse("D:\\application\\eclipse64ee\\workspace\\ilogSynchronized\\src\\syncClaim.txt") ;

//        log.info("同步处理业务数据-开始initSynchronizeResult");
        Map<String, Object> returnBatchesMap = transferResponseBusinessObject2ReturnMap(responseObject);
        SynchronizeResponseBase synchronizeResponseBase = (SynchronizeResponseBase) returnBatchesMap.get("synchronizeResponseBase");
        List<TempBrmUwClaim> tempClaimList = (List<TempBrmUwClaim>) returnBatchesMap.get("tempClaimList");

        TableOperation.deleteTable(TableOperation.TRUNCATE_TEMP_T_BRM_UW_CLAIM);//删除临时表
        StringBuilder sb  = new StringBuilder();
        TempBrmUwClaimDAO tempBrmUwClaimDAO= (TempBrmUwClaimDAO) SpringBeanTool.getBean("TempBrmUwClaimDAO");
        if(synchronizeResponseBase != null && synchronizeResponseBase.getBatches() != null ){
            int i = Integer.parseInt(synchronizeResponseBase.getBatches());//总批次号
            if(i >= 1){
                for(int j = 1 ; j <= i ; j++){
                    ResponseBusinessObject responseBatchesObject = connectToCore("2", ""+j, /*start_tm*/  startTime  ) ;
//                    ResponseBusinessObject responseBatchesObject =  generateTestResponse("D:\\application\\eclipse64ee\\workspace\\ilogSynchronized\\src\\syncClaim.txt") ;  // connectToCore("2", ""+j, /*start_tm*/DateUtil.stringToDate(("2012-12-29 12:00:00" == null ? "" :"2012-12-29 12:00:00"), DateUtil.FORMAT_0)) ;
                    Map<String, Object> claimsMap = transferResponseBusinessObject2ReturnMap(responseBatchesObject);
                    tempClaimList = (List<TempBrmUwClaim>) claimsMap.get("tempClaimList");
                    sb.append(String.format("第 %d 次传输 %d 行 ------ \n",j,tempClaimList.size()));
                    boolean flag = tempBrmUwClaimDAO.addTempBrmUwClaims(tempClaimList);
                    if( flag == false){
                        ResponseBusinessObject responseBatchesObjectAgain = // generateTestResponse("D:\\application\\eclipse64ee\\workspace\\ilogSynchronized\\src\\syncClaim.txt") ;
                         connectToCore("2", ""+j, /*start_tm*/ startTime/*,DateUtil.stringToDate(("2012-12-29 12:00:00" == null ? "" :"2012-12-29 12:00:00"), DateUtil.FORMAT_0)*/ ) ;
                        Map<String, Object> claimsMapAgain = transferResponseBusinessObject2ReturnMap(responseBatchesObject);
                        tempClaimList = (List<TempBrmUwClaim>) claimsMapAgain.get("tempClaimList");
                        sb.append(String.format("第 %d 次保存数据失败, 重新传输 , 传输 %d 行\n",j,tempClaimList.size()));
                        flag = tempBrmUwClaimDAO.addTempBrmUwClaims(tempClaimList);
                        if(flag == false) {
                            sb.append(String.format("第 %d 次保存数据失败, 不再重新传输了,直接退出\n",j));
                            break;
                        }
                    }
                }
            }
        }
        logger.info(sb.toString());
        TableOperation.deleteTable(TableOperation.DELETE_T_BRM_UW_CLAIM_WITH_TEMP);//根据临时表的主键删除真实表中的行
        int effectCount = TableOperation.insertTable(TableOperation.INSERT_INTO_T_BRM_UW_CLAIM);//把临时表中数据插入到真实表中
        TableOperation.deleteTable(TableOperation.TRUNCATE_TEMP_T_BRM_UW_CLAIM);//删除临时表
        logger.info("更新T_BRM_UW_CLAIM表总行数: "+ effectCount+"\n");
    }

    /**接收响应对象以转换Map
     * @param responseBusinessObject 响应对象
     * @return
     * @throws Exception
     */
    public Map<String, Object> transferResponseBusinessObject2ReturnMap(ResponseBusinessObject responseBusinessObject) throws Exception{
        Map<String, Object> returnMap = new HashMap<String, Object>();
        HashMap<String, BusinessVo> map = new HashMap<String, BusinessVo>();

        List<SynchronizeResponseBase> baseList = new ArrayList<SynchronizeResponseBase>();
        List<SynchronizeResponseClaim> claimList = new ArrayList<SynchronizeResponseClaim>();//刚取到的Claim列表
        List<SynchronizeResponseTaxpaymentCode> taxpaymentCodeList = new ArrayList<SynchronizeResponseTaxpaymentCode>();//刚取到的TaxpaymentCode列表

        List<TempBrmUwClaim> tempClaimList = new ArrayList<TempBrmUwClaim>();//转换完成后的用于临时表的Claim
        List<TempBrmTaxpaymentCode> tempTaxpaymentCodeList = new ArrayList<TempBrmTaxpaymentCode>();//转换完成后的用于临时表的TaxpaymentCode

//        DataWindowMetaDataMgr.getInstance().init(this.getClass().getResource("/").toString().split("WEB-INF")[0]+"template/");//不依整于容器   设置web-inf路径
        DataWindowMetaDataMgr.getInstance().init(this.getClass().getClassLoader().getResource("/").getPath().split("WEB-INF")[0]+"template/");//设置web-inf路径
//        logger.info("------------------------------"+this.getClass().getClassLoader().getResource("/").getPath());
//        logger.info("______________________________"+SynchronizeEntrance.class.getResource("/").toString());
//        DataWindowMetaDataMgr.getInstance().init(this.getClass().getClassLoader().getResource("/").getPath() + "core/conf/datawindow/");//取固定路径
//        DataWindowMetaDataMgr.getInstance().init("WebContent/template/");//取固定路径
        if(responseBusinessObject != null){//机构部门同步
            if(responseBusinessObject.getResponseHead().getErrorCode().equals("0000")){
                map = DWTransformTool.getBusinessVoMap(responseBusinessObject);
                baseList.addAll(DWTransformTool.getDataObjListWithBusinessVo("synchronize.response.BASE", new SynchronizeResponseBase(), map));
                claimList.addAll(DWTransformTool.getDataObjListWithBusinessVo("synchronize.response.CLAIM", new SynchronizeResponseClaim(), map));
                taxpaymentCodeList.addAll(DWTransformTool.getDataObjListWithBusinessVo("synchronize.response.TAXPAYMENTCODE", new SynchronizeResponseTaxpaymentCode(), map));
                Date createDate = new Date();
                for(int i = 0;i < baseList.size(); i++){
                    Object objTemp = baseList.get(i);
                    if (objTemp instanceof SynchronizeResponseBase){
                        returnMap.put("synchronizeResponseBase",(SynchronizeResponseBase)objTemp);
                    }
                }
                for(int i = 0;i < claimList.size(); i++){
                    Object objTemp = claimList.get(i);
                    if (objTemp instanceof SynchronizeResponseClaim){
                        SynchronizeResponseClaim syncResponseClaim = (SynchronizeResponseClaim)objTemp;//刚取到的Claim
                        syncResponseClaim.setRecCreateDate(createDate);
                        syncResponseClaim.setDptCode(syncResponseClaim.getDptCode().substring(0, 2));
                        TempBrmUwClaim tempBrmUwClaim = new TempBrmUwClaim(syncResponseClaim);//转换完成后的用于临时表的Claim
                        tempClaimList.add(tempBrmUwClaim);
                    }
                }

                for(int i = 0;i < taxpaymentCodeList.size(); i++){
                    Object objTemp = taxpaymentCodeList.get(i);
                    if (objTemp instanceof SynchronizeResponseTaxpaymentCode){
                        SynchronizeResponseTaxpaymentCode syncResponseTaxpaymentCode = (SynchronizeResponseTaxpaymentCode)objTemp;//刚取到的TaxpaymentCode
                        syncResponseTaxpaymentCode.setCrtTm(createDate);
                        TempBrmTaxpaymentCode tempBrmUwClaim = new TempBrmTaxpaymentCode(syncResponseTaxpaymentCode);//转换完成后的用于临时表的TaxpaymentCode
                        tempTaxpaymentCodeList.add(tempBrmUwClaim);
                    }
                }

                returnMap.put("tempClaimList",tempClaimList);
                returnMap.put("tempTaxpaymentCodeList",tempTaxpaymentCodeList);
            }
        }
        return returnMap;
    }

    /**从核心提取当前批次的信息
     * @param updateType 更新方式,1、获取总批次数据,2、分批更新
     * @param batches 批次号
     * @param startTime 起时
     * @return
     * @throws Exception
     */
    public ResponseBusinessObject connectToCore(String updateType, String batches,Date startTime ) throws Exception{
//        log.info("同步初始业务数据-开始initSynchronizePara");
        RequestBusinessObject requestObject = new RequestBusinessObject();
        RequestHead head = new RequestHead();
        head.setRequestType("0000-36");
        head.setSysName("ILOG");//外围系统名
        head.setSysCode("04");//外围系统代码
        head.setUserCde("100009999");//操作用户代码 核心用到,识别用户
        head.setDptCde("00");//
        head.setServiceNo("0101030205");//
        head.setServiceName("synchronized");//request response文件夹上一层目录名
        head.setUserId("50000005"); //esb 分配的用户ID,仅限于esb用来区分不同的接入系统

        requestObject.setRequestHead(head);
        HashMap<String, BusinessVo> map = new HashMap<String, BusinessVo>();
        DataWindowMetaDataMgr.getInstance().init(this.getClass().getClassLoader().getResource("/").getPath().split("WEB-INF")[0]+"template/");
//        DataWindowMetaDataMgr.getInstance().init("WebContent/template/");//取固定路径
//        DataWindowMetaDataMgr.getInstance().init(this.getClass().getClassLoader().getResource("/").getPath() + "core/conf/datawindow/");
        RequestBody body = new RequestBody();
        SynchronizeRequestBase baseVo = new SynchronizeRequestBase();
        baseVo.setUpdate_type(updateType);//更新方式,1、获取总批次数据,2、分批更新
        baseVo.setBatches(batches);
        baseVo.setStart_tm(startTime);
//        baseVo.setStart_tm(DateUtil.stringToDate(("2012-12-29 12:00:00" == null ? "" :"2012-12-29 12:00:00"), DateUtil.FORMAT_0));//传固定值uwclaim
//        baseVo.setStart_tm(DateUtil.stringToDate(("2013-09-18 00:00:00" == null ? "" :"2013-09-18 00:00:00"), DateUtil.FORMAT_0));//传固定值taxpayment
        DWTransformTool.addToMap(map, "synchronize.request.BASE", baseVo);
        DWTransformTool.addToBusinessVoMap(map, body);
        requestObject.setRequestBody(body);
        ESBClient client = new ESBClient(100000,100000,100000);
//        String xml1 = XmlTool.convertToXml(requestObject);
        ResponseBusinessObject responseObject = client.invoke(requestObject);//该方法会致使程序执行完后不关闭
//        String xml2 = XmlTool.convertToXml(responseObject);
        return responseObject;
    }

    public ResponseBusinessObject  generateTestResponse(String fileNameInSrc) throws Exception{
//        log.info("同步初始业务数据-开始initSynchronizePara");
        RequestBusinessObject requestObject = new RequestBusinessObject();
        RequestHead head = new RequestHead();
        head.setRequestType("0000-36");
        head.setSysName("ILOG");//外围系统名
        head.setSysCode("04");//外围系统代码
        head.setUserCde("100009999");//操作用户代码 核心用到,识别用户
        head.setDptCde("00");//
        head.setServiceNo("0101030205");//
        head.setServiceName("synchronized");//request response文件夹上一层目录名
        head.setUserId("50000005"); //esb 分配的用户ID,仅限于esb用来区分不同的接入系统

        requestObject.setRequestHead(head);

        File file = new File(fileNameInSrc);
//        File file = new File("src/"+fileNameInSrc);
        logger.info(file.getAbsolutePath());
        Scanner s = new Scanner(file);
        StringBuilder sb = new StringBuilder();
        while(s.hasNext()){
            sb.append(s.nextLine());
        }
        Document document = XmlTool.getDocument(sb.toString(), "GBK");
        ResponseBusinessObject response = XmlTool.getFromResponseXml(document, requestObject);
        return response;
    }

}
时间: 2024-10-17 15:30:12

ESB 客户端调用 处理类的相关文章

CXF soup webservice 动态客户端调用工具类

在尝试了多种webservice客户端调用方法之后,还是觉得这种方法靠谱点儿,此方法用到了Apache的CXF框架,工具类源码如下: import java.lang.reflect.Method; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; public class WsReq{     private String wsUrl;     private Class<?> interfaceClz;          pulbic W

Axis实现 web service接口开发 + 客户端调用

看到网上挺多人找webservice axis开发案例,但是网上较多的都是有点乱,初学者不太容易看得懂,所以最近看到自己终于有了点空闲时间,就上传了一份比较简单的webservice axis的完整案例. 只适用于初学者. 一.新建一个web项目 导入lib包. 2.配置 web.xml <!-- axis 配置 -->   <servlet>         <display-name>Apache-Axis Servlet</display-name>

Axis2实现 web service接口开发 + 客户端调用

一. 新建一个web项目, 1.打开axis2.war包,将conf,lib,modules三个文件夹复制到项目的WEB-INF文件夹下,再在WEB-INF目录下新建一个services文件夹,然后在services文件下新建一个文件夹(任意取名): 再新建META-INF文件夹,最后再新增services.xml,接口信息就写在这里面. 具体路径:WEB-INF/services/myservice/META-INF/services.xml 2.配置 web.xml .加载axis2 和 a

EJB对象的部署及客户端调用简单示例

一,EJB对象的写法及部署 1,新建一个EJB Project,在包里加入接口及实现类: 实现类通常以Bean结尾,并且通过注解方式指定EJB类型: 之后,部署到JBoss服务器上. 二,客户端调用 1,将EJB项目中的接口类打包,并把这个jar包加入到client项目中. 2,将JBOSS安装目录下的client目录里面的所有jar包加到客户端项目中 3,加入jndi.properties文件,将地址配置为EJB项目的发布地址 注意:这个properties文件最好反正根目录下,不然可能会产生

客户端调用 CMD 命令并回显结果。

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; using Syste

Java与WCF交互(一):Java客户端调用WCF服务

最近开始了解WCF,写了个最简单的Helloworld,想通过java客户端实现通信.没想到以我的基础,居然花了整整两天(当然是工作以外的时间,呵呵),整个过程大费周折,特写下此文,以供有需要的朋友参考: 第一步:生成WCF服务 新建WCF解决方案,分别添加三个项目,HelloTimeService(类库),HelloTimehost(控制台程序),HelloTimeClient(控制台程序),项目结构如图:各个项目的主要代码:service: Host: Client: 编译通过后,测试Hos

kettle中调用java类

有时需要在kettle调用java类,如:验证.查询或自定义加密等.有时甚至连基本的数据访问都不那么简单,如获取一个存储文件或使用一个数据库连接,某些数据源可能封装在应用程序中,手工使用自定义的java客户端访问是唯一的方法.本文介绍如何在kettle中调用java类.示例代码在这里下载. 注:如果你使用kettle4.0及以上版本,也你也可以使用user defined java class 步骤实现.   Modified Java ScriptValue 步骤 关键要在kettle中使用M

Web Service学习之服务端搭建与客户端调用

?工作中用到了Web Service,但是对这块不是很熟悉,决定花时间学习一下,现在记录一下最基本的入门知识点. 使用Java搭建Web Service服务端,使用Python脚本调用接口. 一.Web Service服务端 1.在Eclipse中新建一个Java工程,新建test.TestWebService类 package test; import javax.jws.WebService; import javax.xml.ws.Endpoint; @WebService public 

http请求POST和GET调用接口以及反射动态调用Webservices类

此代码是API.WebSrvices动态调用的类,做接口调用时很实用. Webservices动态调用使用反射的方式很大的缺点是效率低,若有更好的动态调用webservices方法,望各位仁兄不吝贴上代码. using System; using System.IO; using System.Net; using System.Text; using System.Web; using System.Collections.Generic; using System.CodeDom.Compi