1、ERP封装数据成XML写入数据库服务器指定文件

    --指定相关文件信息
v_file_path := '/u01/test/app/fs1/EBSapps/appl/cux/12.0.0/forms';
vfilepath := 'TO_SSNC_PATH9';
vfilename := 'voucher.xml';
v_sender := '';
--封装数据
vclobpz_result := '<?xml version=''' || '1.0' || ''' encoding=''' ||
'UTF-8' || '''?><ufinterface account=''' || 'SS' ||
''' billtype=''' || 'vouchergl' ||
''' businessunitcode=''' || 'develop' ||
''' filename=''' || 'voucher.xml' || ''' groupcode=''' || 'SS' ||
''' orgcode=''' || l_orgcode || ''' receiver=''' ||
'0001A5100000000005F3' || ''' sender=''' || '' ||
'''><voucher><voucher_head><pk_voucher></pk_voucher><pk_vouchertype>01</pk_vouchertype><year>' ||
l_year ||
'</year><pk_system>GL</pk_system><voucherkind>0</voucherkind><pk_accountingbook>' ||
l_orgcode ||
'-0001</pk_accountingbook><discardflag>N</discardflag><period>' ||
l_period ||
'</period><no></no><attachment>1</attachment><prepareddate>' ||
to_char(last_day(SYSDATE) - 6,
'YYYY-MM-DD') || '</prepareddate><pk_prepared>' ||
l_prepared ||
'</pk_prepared><pk_casher></pk_casher><signflag>Y</signflag><pk_checked></pk_checked><tallydate></tallydate><pk_manager></pk_manager><memo1></memo1><memo2></memo2><reserve1></reserve1><reserve2>N</reserve2><siscardflag /><pk_org>' ||
l_orgcode || '</pk_org><pk_org_v>' || l_orgcode ||
'</pk_org_v><pk_group>SS</pk_group><details>'; --写入文件
x_msg_data := NULL;
BEGIN
v_create_file := 'A';
--打开文件 R读文本,W写文本 ,A附加文本
vmyfile := utl_file.fopen(vfilepath,
vfilename,
'W',
30000);
v_create_file := 'B';
--写入xml到指定文件
utl_file.put_line(vmyfile,
convert(vclobpz_result,
'ZHS16GBK')); --需要转换格式,否则可能会出现乱码 v_create_file := 'C';
--关闭文本
utl_file.fclose(vmyfile);
EXCEPTION
WHEN OTHERS THEN
IF (v_create_file = 'A') THEN
x_msg_data := '打开XML文件异常:' || SQLERRM;
ELSIF (v_create_file = 'B') THEN
x_msg_data := '写入数据到XML文件异常:' || SQLERRM;
ELSIF (v_create_file = 'C') THEN
x_msg_data := '关闭XML文件异常:' || SQLERRM;
END IF;
END;

传入外围系统,获取返回结果
SELECT cux_nc_ap_voucher_pkg.cux_java_sendfile(v_addr,
v_file_path,
vfilename)
INTO v_return
FROM dual;

2、读取文件,通过java流传给外围系统

create or replace and compile java source named APPS.cux_java_sendfile as
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.traversal.NodeIterator;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*; public class cux_java_sendfile { public static String xzSendFile(String addr,String filepath,String filename)throws IOException
{
System.out.println("Test1");
File vfile= new File(filepath+File.separator+filename);
String conn_flag1=null;
cux_java_sendfile sc = new cux_java_sendfile();
//验证是否已连接NC
System.out.println("Test2");
String conn_flag= sc.getConn_flag(addr); if (conn_flag!="获取连接出错!")
{
System.out.println(filepath+File.separator+filename);
if (vfile.exists()){
//sc.sendMessage(vfile,false,sc.getConn(false,addr));
try{
conn_flag1= sc.receiveResponse(vfile,sc.getConn(addr));
} catch (Exception e) { }
}else{
return "文件不存在";
}
} return conn_flag1;
} private boolean ret = false; String message = ""; String fileMessage = "";
//String returnmsg =""; /**
* 取得NC外部平台连接
*
* @param bcompress
* 是否启用压缩
* @return
* @throws IOException
*/ public HttpURLConnection getConn(String url)
throws IOException {
// 连接NC外部平台地址
try {
URL realURL = new URL(url);
HttpURLConnection connection = (HttpURLConnection) realURL
.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "text/xml");
connection.setRequestMethod("POST");
System.out.println("取得连接" + url);
return connection; } catch (MalformedURLException e) {
System.out.println("获取连接出错!");
return null;
}
} public static String getConn_flag(String url)
throws IOException {
// 连接NC外部平台地址
try { URL realURL = new URL(url);
HttpURLConnection connection = (HttpURLConnection) realURL
.openConnection(); connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "text/xml");
return "取得连接" + url; } catch (MalformedURLException e) {
System.out.println("获取连接出错!");
//return NULL;
return "获取连接出错!";
}
} public String receiveResponse(File file,HttpURLConnection connection//,String post,String post1
) throws Exception { try{ String post = "";
System.out.println("==================BEGIN====================");
// 获取URLConnection对象对应的输出流 connection.setRequestProperty("Charset", "UTF-8"); //设置编码为utf-8
PrintWriter printWriter = new PrintWriter(connection.getOutputStream());
// 发送请求参数 BufferedInputStream input = new BufferedInputStream(
new FileInputStream(file));
int length;
int bufflength = 40960 * 1;
byte[] buffer = new byte[bufflength];
while ((length = input.read(buffer)) != -1) {
post = new String(buffer,0,length);
printWriter.write(post);//post的参数 xx=xx&yy=yy //System.out.println(post);
}
// flush输出流的缓冲
printWriter.flush();
//开始获取数据
BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int len;
byte[] arr = new byte[1024];
while((len=bis.read(arr))!= -1){
bos.write(arr,0,len);
bos.flush();
} bos.close();
System.out.println("=======bos======="+bos.toString("UTF-8")); //解析NC返回结果集的XML
System.out.println("解析NC返回结果集的XML");
Document doc = null;
String return_msg = "";
String return_Suc = "";
//从xml文档中获取DOM的解析器...
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); //这里调用DOM工厂...
try { //从DOM工厂中获取DOM解析器...
DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); //定义一个xml文档的输入源..
is.setCharacterStream(new StringReader(bos.toString("UTF-8"))); //设置输入源的字符流...
doc = db.parse(is); //指定输入源的内容解析成一个XML文档,并返回一个DOM对象...
System.out.println("doc:= "+ doc.getImplementation());
Element root =doc.getDocumentElement();
return_Suc = root.getAttribute("successful");
System.out.println("resSuc:="+return_Suc); //得到文档名称为sendresult的元素的节点列表
NodeList nList = doc.getElementsByTagName("sendresult");
for(int i = 0; i< nList.getLength() ; i ++){
Element node = (Element)nList.item(i);
return_msg = node.getElementsByTagName("resultdescription").item(0).getFirstChild().getNodeValue();
//System.out.println("return_msg:"+return_msg);
//System.out.println("resultdescription: "+ node.getElementsByTagName("resultdescription").item(0).getFirstChild().getNodeValue());
} } catch (ParserConfigurationException e) {
e.getMessage();
} catch (SAXException e) {
e.getMessage();
} catch (IOException e) {
e.getMessage();
}
System.out.println("==================END===================="); //System.out.println("return_Suc1:"+return_Suc);
// System.out.println("return_msg1:"+return_msg);
return "返回成功与否标记:"+return_Suc+",返回消息:"+return_msg;
}catch (IOException e) {
e.printStackTrace();
}
return "返回成功"; } /**
*
**/
/**
*初始化一个DocumentBuilder
*@return a DocumentBuilder
*@throws ParserConfigurationException
**/
public static DocumentBuilder newDocumentBuilder()
throws ParserConfigurationException{
return newDocumentBuilderFactory().newDocumentBuilder();
}
/**
*初始化一个DocumentBuilderFactory
*@return a DocumentBuilderFactory
**/
public static DocumentBuilderFactory newDocumentBuilderFactory(){
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
return dbf;
} }
3、调用java程序 以文件流方式传输至用友NC系统指定地址,返回连接状态
    FUNCTION cux_java_sendfile(p_addr     VARCHAR2,
p_filepath IN VARCHAR2,
p_filename IN VARCHAR2) RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'cux_java_sendfile.xzSendFile(java.lang.String,java.lang.String,java.lang.String) return java.lang.String';

ERP通过JAVA流的形式将数据传到外围系统的更多相关文章

  1. java 写 Excel(不生成实体文件,写为流的形式)

    java 写 Excel(不生成实体文件,写为流的形式) public String exportReportExcel(String mediaCode, List<SimpleMediaRe ...

  2. Java写Excel(不生成实体文件,写为流的形式)

    java 写 Excel(不生成实体文件,写为流的形式) public String exportReportExcel(String mediaCode, List<SimpleMediaRe ...

  3. Java下载文件(流的形式)

    @RequestMapping("download") @ResponseBody public void download(HttpServletResponse respons ...

  4. Java - 17 Java 流(Stream)、文件(File)和IO

    Java 流(Stream).文件(File)和IO Java.io包几乎包含了所有操作输入.输出需要的类.所有这些流类代表了输入源和输出目标. Java.io包中的流支持很多种格式,比如:基本类型. ...

  5. java 流 文件 IO

    Java 流(Stream).文件(File)和IO Java.io 包几乎包含了所有操作输入.输出需要的类.所有这些流类代表了输入源和输出目标. Java.io 包中的流支持很多种格式,比如:基本类 ...

  6. 使用Socket&反射&Java流操作进行方法的远程调用(模拟RPC远程调用)

    写在前面 阅读本文首先得具备基本的Socket.反射.Java流操作的基本API使用知识:否则本文你可能看不懂... 服务端的端口监听 进行远程调用,那就必须得有客户端和服务端.服务端负责提供服务,客 ...

  7. Java流

    流是一组有顺序的,有起点和终点的字节集合,是对传输数据的总称或抽象.即数据在两设备间的传输称为流,流的本质是传输数据,依据传输数据特性将流抽象为各种类,方便更直观的进行数据操作. 流的分类: 数据类型 ...

  8. java 流输出的一些问题

    一.java流的控制首先要先准备一个文件,例如:File f = new File(d:/lol.txt); 二.可以使用如下指令创建流,用于不同的用途 1.FileInputStream,FileO ...

  9. NPOI生成不规则Excel表格(并以流的形式下载,不将文件保存在服务器上,直接在客户端导出excel)

    //下载NPOI类库并添加引用 using NPOI.SS.UserModel; using NPOI.HSSF.UserModel; using NPOI.SS.Util; public stati ...

随机推荐

  1. git工具免密拉取、推送

    很苦恼每次都要配置明文密码才能正常工作 其实也可以配置成非明文 打开控制面板 →用户账号 管理 Windows凭证 对应修改响应网址即可  

  2. Java 用Jackson进行json和object之间的转换(并解决json中存在新增多余字段的问题)

    1.添加jackson库 如果是maven工程,需要在pom.xml中添加jackson的依赖: <dependency>      <groupId>com.fasterxm ...

  3. Oracle 对比insert和delete操作产生的undo

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/wangqingxun/article/de ...

  4. 【洛谷P2664】 树上游戏 点分治

    code: #include <bits/stdc++.h> #define N 200009 #define ll long long #define setIO(s) freopen( ...

  5. WinDbg常用命令系列---.effmach

    .effmach (Effective Machine) .effmach命令显示或更改调试器使用的处理器模式. .effmach [MachineType] 参数: MachineType指定调试器 ...

  6. java web项目改装exe安装版

    https://blog.csdn.net/rico_zhou/article/details/79868129java简单程序打包成exe https://blog.csdn.net/rico_zh ...

  7. 无人机一体化3DGIS服务平台

    随着无人机技术的发展,无人机携带多种设备为GIS应用提供多元化海量基础数据.无人机航测更是以快速.灵活.高效的数据获取方式,迅速扩大了现有的GIS市场,同时GIS行业的广泛应用也推动了无人机技术的发展 ...

  8. python unittest套件加载用例时,出现No tests were found,Empty test suite

    错误信息: 之前运行好好的脚本,突然报No tests were found,Empty test suite,详情错误信息如下所示: Launching pytest with arguments ...

  9. intellij ide 集成cmder

    1.环境变量配置: https://github.com/cmderdev/cmder/wiki/Setting-up-Environment-Variables 2.intellijide的配置:h ...

  10. 开启Nginx监控 with-http_stub_status_module

    1.开启监控with-http_stub_status_module ./configure  --with-openssl=/usr/local/ssl  --with-http_stub_stat ...