ERP stream in the form of the data transmitted JAVA peripheral system

1, ERP package database server to write the data into the XML file specified

    - Targeting File Information 
v_file_path:
= ' /u01/test/app/fs1/EBSapps/appl/cux/12.0.0/forms ' ; vfilepath: = ' TO_SSNC_PATH9 ' ; vfilename: = ' voucher.xml ' ; v_sender: = ' 001 ' ;
- encapsulating data 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=''' || '001' || '''><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> the SS </ pk_group> <Details> ' ; - write the file x_msg_data: = NULL ; the BEGIN v_create_file: = ' A ' ; - open a text file to read R, W write text, A additional text vmyfile: = utl_file.fopen (vfilepath, vfilename, ' W is ', 30000 ); v_create_file: = ' B ' ; - written to the specified file xml utl_file.put_line (vmyfile, Convert (vclobpz_result, ' ZHS16GBK ' )); - need to change the format, or may be garbled v_create_file: = ' C ' ; - Close text utl_file.fclose (vmyfile); the EXCEPTION the WHEN the OTHERSTHEN the IF (v_create_file = ' A ' ) THEN x_msg_data: = ' Open the XML file exception: ' || SQLERRM variables,; ELSIF (v_create_file = ' B ' ) THEN x_msg_data: = ' write data to an XML file exception: ' || SQLERRM variables,; ELSIF (v_create_file = ' C ' ) THEN x_msg_data: = ' off exception XML file: ' ||SQLERRM variables,; the END the IF ; the END ;
afferent peripheral system, returns the result acquiring
the SELECT cux_nc_ap_voucher_pkg.cux_java_sendfile (v addr, v_file_path, vfilename) the INTO V_RETURN the FROM Dual;

2, read the file, by java spread to the peripheral system

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("The Content-type", "text / XML" ); 
      connection.setRequestMethod ( "the POST" ); 
      System.out.println ( "connection made" + URL);
       return   Connection; 

    } the catch (a MalformedURLException E) { 
      the System.out. println ( "get connection error!" );
       return   null ;
    } 
  } 
  
  
  Public  static   String getConn_flag (String URL)
       throws IOException {
     // connected external NC internet address of 
  the try { 
    
      the URL realURL = new new  the URL (URL);
      the 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//, POST String, String POST1 
  ) throws Exception { 

          the try { 
             
             String POST = "" ; 
             System.out.println ( "================== the BEGIN ======= ============= " );
               // Get the output stream corresponding to the object URLConnection 
              
               connection.setRequestProperty ( " the Charset "," UTF-. 8 ");   // set. 8-encoded as UTF 
               the PrintWriter a PrintWriter = new new the PrintWriter (connection.getOutputStream ());
               // send a parameter request 
              
               BufferedInputStream INPUT = new new BufferedInputStream (
                  new new the FileInputStream (File));
               int length;
               int bufflength = 40960 *. 1 ;
               byte [] Buffer = new new  byte [bufflength];
               the while ! ((length = input.read (Buffer)) = -1 ) { 
               POST = new new String (buffer, 0 , length); 
               printWriter.write (POST); // POST parameters & YY = XX = XX YY 
               
               // System.out.println (POST); 
              }
               // the flush buffered output stream 
              printWriter.flush ();
               // start acquiring data
              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 parse returned XML result set" ); 
               the Document DOC = null ;   
               String return_msg = "" ; 
               String return_Suc = "" ;
                // get DOM parser from xml document ... 
               the DocumentBuilderFactory dbf DocumentBuilderFactory.newInstance = ();    // called here DOM factory ... 
               the try {    
               
                // Get the DOM DOM parser factory ... 
                the DocumentBuilder DB = dbf.newDocumentBuilder (); 
        
                the InputSource IS = new new the InputSource ();    // a defined xml document input source ..
                is.setCharacterStream ( new new the StringReader (bos.toString ( "UTF-. 8")));    // the input source character stream ... 
                DOC = db.parse (IS);      // contents of the specified input source parsed into a XML document, and returns a DOM object ... 
                System.out.println ( "DOC: =" + doc.getImplementation ()); 
                Element root = doc.getDocumentElement (); 
                return_Suc = root.getAttribute ( "successful" ); 
                System.out.println ( "resSuc: =" + return_Suc); 
      
               // get the document name node elements sendresult list 
                 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(A SAXException E) {    
                    e.getMessage (); 
                } the catch (IOException E) {    
                    e.getMessage ();   
                }    
                System.out.println ( "================== ==================== the END " ); 

                // System.out.println (" return_Suc1: "+ return_Suc);
                // System.out.println (" return_msg1 : "+ return_msg); 
                 return " returns the success flag: "+ return_Suc +", returns the message: "+ return_msg;          
             } the catch (IOException E) { 
                e.printStackTrace ();   
             } 
        return " return success ";

  }
  
  /**
  *
  **/
  /**
  *初始化一个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, call java program streamed to a file UF NC system specified address, return connection state
    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';

 

Guess you like

Origin www.cnblogs.com/wang-chen/p/11879101.html