首页 > 编程语言 >FR11 webservice程序数据集

FR11 webservice程序数据集

时间:2022-11-23 14:14:34浏览次数:48  
标签:String FR11 ZHJD 程序 element import ZSN iterator webservice

package com.fr.data;

import cn.hutool.core.lang.Console;
import cn.hutool.http.webservice.SoapClient;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ParameterProvider;
import org.apache.avro.generic.GenericData;

import javax.xml.soap.*;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class OaFLow extends SimpleTableData {
    /**
     * 定义程序数据集的列名与数据保存位置
     */

    public static String ret = "";


    @Override
    public String[] initColumnNames() {
        String[] columnNames = {"ZSN_ZHJD_OPINION", "ZSN_ZHJD_CREATEDATE", "ZSN_ZHJD_STATUS", "ZSN_ZHJD_NODE", "ZSN_ZHJD_DEPARTMENT", "ZSN_ZHJD_USERNAME"};
        return columnNames;
    }

    /**
     * 实现构建函数,在构建函数中准备数据
     */
    @Override
    public List<Object[]> loadData() {
        String[] columnNames;
        Object[][] rowData;
        String flowId = ((ParameterProvider) (parameters.get().toArray())[0]).getValue().toString();
        List<Object[]> list = new ArrayList<>();
        try {
            // 新建客户端
            SoapClient client = SoapClient.create("http://IP/services/ConfirmFlowService")
                    // 设置要请求的方法,此接口方法前缀为web,传入对应的命名空间
                    .setMethod("con:ConfirmFlowService", "http://schemas.xmlsoap.org/soap/envelope/")
                    // 设置参数,此处自动添加方法的前缀:web
                    .setParam("in0", flowId);

            // 发送请求,参数true表示返回一个格式化后的XML内容
            // 返回内容为XML字符串,可以配合XmlUtil解析这个响应
            SOAPMessage msg = formatSoapString(client.sendForResponse().body());
            SOAPBody body = msg.getSOAPBody();
            Iterator<SOAPElement> iterator = body.getChildElements();
            PrintBody(iterator, null);
            JSONArray arr = JSONUtil.parseArray(JSONUtil.parse(JSONUtil.parse(ret).getByPath("confirmFlow")).getByPath(flowId));

            for(int i=0;i<arr.size();i++){
                list.add(new Object[6]);
                list.get(i)[0] = JSONUtil.parseObj(arr.get(i)).get("ZSN_ZHJD_OPINION");
                list.get(i)[1] = JSONUtil.parseObj(arr.get(i)).get("ZSN_ZHJD_CREATEDATE");
                list.get(i)[2] = JSONUtil.parseObj(arr.get(i)).get("ZSN_ZHJD_STATUS");
                list.get(i)[3] = JSONUtil.parseObj(arr.get(i)).get("ZSN_ZHJD_NODE");
                list.get(i)[4] = JSONUtil.parseObj(arr.get(i)).get("ZSN_ZHJD_DEPARTMENT");
                list.get(i)[5] = JSONUtil.parseObj(arr.get(i)).get("ZSN_ZHJD_USERNAME");
            }
        } catch (Exception e) {
            FineLoggerFactory.getLogger().error(e.getMessage(), e);
        }
       return list;

    }
    //实现ArrayTableData的其他四个方法,因为AbstractTableData已经实现了hasRow方法


    /**
     * 把soap字符串格式化为SOAPMessage
     *
     * @param soapString
     * @return
     * @see [类、类#方法、类#成员]
     */
    public static SOAPMessage formatSoapString(String soapString) {
        MessageFactory msgFactory;
        try {
            msgFactory = MessageFactory.newInstance();
            SOAPMessage reqMsg = msgFactory.createMessage(new MimeHeaders(),
                    new ByteArrayInputStream(soapString.getBytes("UTF-8")));
            reqMsg.saveChanges();
            return reqMsg;
        } catch (Exception e) {
            FineLoggerFactory.getLogger().error(e.getMessage(), e);
            return null;
        }
    }

    private static void PrintBody(Iterator<SOAPElement> iterator, String side) {
        while (iterator.hasNext()) {
            Object o=iterator.next();
            if(o!=null)  {
                SOAPElement element=null;
                try{
                    element = (SOAPElement) o;
                    System.out.println("Node Name:" + element.getNodeName());
                    System.out.println("Value:" + element.getValue());
                    if(element.getNodeName().equals("ns1:out")){
                        ret = element.getValue() + "";
                    }
                }catch(Exception e){}
                if ( element !=null ) {
                    PrintBody(element.getChildElements(), side + "-----");
                }
            }
        }
    }


    public static void main(String[] args){
            new OaFLow().loadData();
    }
}

 

标签:String,FR11,ZHJD,程序,element,import,ZSN,iterator,webservice
From: https://www.cnblogs.com/shuaihan/p/16918091.html

相关文章