帆软帮助文档代码合集。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.8 KiB

package com.fr.data;
import com.fr.general.data.TableDataException;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ParameterProvider;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;
/**
* WebService程序数据集
*
* @author Roger
* @since 11.0
* Created on 2024/1/8
*/
public class WebServiceTableData extends SimpleTableData {
private static final int COLUMN_COUNT = 10;
/**
* 初始化列名数组
*
* @return {col1,col2,col3...}
* @throws TableDataException
*/
@Override
public String[] initColumnNames() {
String[] columnNames = new String[COLUMN_COUNT];
for (int i = 0; i < COLUMN_COUNT; i++) {
columnNames[i] = "column#" + i;
}
return columnNames;
}
/**
* 加载数据
*
* @return 行列数据
*/
@Override
public List<Object[]> loadData() {
String tableName = ((ParameterProvider) (parameters.get().toArray())[0]).getValue().toString();
FineLoggerFactory.getLogger().info("Query SQL of ParamTableDataDemo: {}", tableName);
// 保存得到的结果集
ArrayList<Object[]> valueList = new ArrayList();
try {
// 调用 Web 服务获取数据
String[][] data = createData();
// 如果数据为空,直接返回空列表
if (data == null || data.length == 0) {
return valueList;
}
// 获得总列数
int colNum = data[0].length;
// 用对象保存数据
Object[] objArray = null;
for (int rowIndex = 1; rowIndex < data.length; rowIndex++) {
objArray = new Object[colNum];
for (int i = 0; i < colNum; i++) {
objArray[i] = data[rowIndex][i];
}
// 在valueList中加入这一行数据
valueList.add(objArray);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return valueList;
}
/**
* 调用 Web 服务获取数据
*
* @return
*/
public String[][] createData() {
try {
String endpoint = "http://localhost:8080/axis/TestWS2TDClient.jws";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("http://localhost:8080/axis/TestWS2TDClient.jws",
"getTD"));
String[][] ret = (String[][])call.invoke(new Object[] {});
return ret;
} catch (Exception e) {
e.printStackTrace();
}
return new String[][] {};
}
}