当前位置: 首页 > 工具软件 > idoc > 使用案例 >

idoc java_java - 将iDOC从Java发送到SAP - 堆栈内存溢出

李经国
2023-12-01

我们有从系统生成的iDOC文件。 现在,我们尝试通过RFC连接将它们发送到SAP。 我已经作为客户端建立了RFC连接,但无法发送iDOC!

我试图创建一个样本iDOC进行测试,但是它不起作用!

Exception in thread "main" java.lang.NoSuchMethodError: com.sap.conn.idoc.jco.SAPRepository$ConnectionProvider.execute(Lcom/sap/conn/jco/JCoFunction;Lcom/sap/conn/jco/rt/AbapRepository;)V

at com.sap.conn.idoc.jco.SAPRepository.queryRootSegmentMetaData40(SAPRepository.java:1204)

at com.sap.conn.idoc.jco.SAPRepository.queryRootSegmentMetaData(SAPRepository.java:1110)

at com.sap.conn.idoc.jco.SAPRepository.getRootSegmentMetaData(SAPRepository.java:909)

at com.sap.conn.idoc.rt.DefaultIDocDocument.(DefaultIDocDocument.java:124)

at com.sap.conn.idoc.rt.DefaultIDocDocument.(DefaultIDocDocument.java:61)

at com.sap.conn.idoc.jco.JCoIDocDocument.(JCoIDocDocument.java:51)

at com.sap.conn.idoc.jco.JCoIDocRuntime.createIDocDocument(JCoIDocRuntime.java:133)

at com.sap.conn.idoc.jco.JCoIDocRuntime.createIDocDocument(JCoIDocRuntime.java:35)

at com.sap.conn.idoc.rt.DefaultIDocRuntime.createIDocDocument(DefaultIDocRuntime.java:175)

at com.sap.conn.idoc.rt.DefaultIDocRuntime.createIDocDocument(DefaultIDocRuntime.java:18)

at com.idoc.sender.IDocClientExample.main(IDocClientExample.java:49)

我什至尝试发送样本iDOC XML,但我也遇到了另一个错误,试图多次更改XML,但是我又一次遇到了同样的问题!

com.sap.conn.idoc.IDocParseException: (7) IDOC_ERROR_PARSE_FAILURE: Invalid character encountered in XML input data source:

state=READING_XMLDECLARATION, charPosition=14, lineNumber=1, columnNumber=15, invalidChar=U+003D,

sourceSnippet=...@<?xml version="1.0" encoding="UTF-8"?>20120114120000

^

at com.sap.conn.idoc.rt.xml.DefaultIDocXMLParser.throwIDocParseException(DefaultIDocXMLParser.java:2223)

at com.sap.conn.idoc.rt.xml.DefaultIDocXMLParser.parseProlog(DefaultIDocXMLParser.java:1635)

at com.sap.conn.idoc.rt.xml.DefaultIDocXMLParser.parse(DefaultIDocXMLParser.java:320)

at com.sap.conn.idoc.rt.xml.DefaultIDocXMLProcessor.parse(DefaultIDocXMLProcessor.java:112)

at com.sap.conn.idoc.rt.xml.DefaultIDocXMLProcessor.parse(DefaultIDocXMLProcessor.java:54)

at com.sap.conn.idoc.rt.xml.DefaultIDocXMLProcessor.parse(DefaultIDocXMLProcessor.java:31)

at com.idoc.sender.IDocClientExample.main(IDocClientExample.java:57)

这是我用来创建iDOC和发送iDOC XML的代码:

package com.idoc.sender;

import com.sap.conn.idoc.*;

import com.sap.conn.idoc.jco.JCoIDoc;

import com.sap.conn.jco.JCoDestination;

import com.sap.conn.jco.JCoDestinationManager;

import java.io.BufferedReader;

import java.io.FileReader;

public class IDocClientExample {

public static void main(String[] args) {

try {

String iDocXML = null;

FileReader fileReader;

try {

fileReader = new FileReader("TestSalesOrder.xml");

BufferedReader br = new BufferedReader(fileReader);

StringBuffer sb = new StringBuffer();

String line;

while ((line = br.readLine()) != null) {

sb.append(line);

}

iDocXML = sb.toString();

br.close();

fileReader.close();

} catch (Exception ex) {

ex.printStackTrace();

}

// see provided configuration file xxxx.jcoDestination

JCoDestination destination = JCoDestinationManager.getDestination("xxxx");

IDocRepository iDocRepository = JCoIDoc.getIDocRepository(destination);

String tid = destination.createTID();

IDocFactory iDocFactory = JCoIDoc.getIDocFactory();

System.out.println(destination.getAttributes());

// a) create sample new idoc

IDocDocument doc = iDocFactory.createIDocDocument(iDocRepository, "SYSTAT01");

IDocSegment segment = doc.getRootSegment();

segment.addChild("E1MARAM");

JCoIDoc.send(doc, IDocFactory.IDOC_VERSION_DEFAULT, destination, tid);

// b) use existent xml file

IDocXMLProcessor processor = iDocFactory.getIDocXMLProcessor();

IDocDocumentList iDocList = processor.parse(iDocRepository, iDocXML);

JCoIDoc.send(iDocList, IDocFactory.IDOC_VERSION_DEFAULT, destination, tid);

destination.confirmTID(tid);

} catch (Exception e) {

e.printStackTrace();

}

System.out.print("program end");

}

}

// a) create sample new idoc

IDocDocument doc = iDocFactory.createIDocDocument(iDocRepository, "SYSTAT01");

IDocSegment segment = doc.getRootSegment();

segment.addChild("E1MARAM");

JCoIDoc.send(doc, IDocFactory.IDOC_VERSION_DEFAULT, destination, tid);

// b) use existent xml file

IDocXMLProcessor processor = iDocFactory.getIDocXMLProcessor();

IDocDocumentList iDocList = processor.parse(iDocRepository, iDocXML);

JCoIDoc.send(iDocList, IDocFactory.IDOC_VERSION_DEFAULT, destination, tid);

destination.confirmTID(tid);

} catch (Exception e) {

e.printStackTrace();

}

System.out.print("program end");

}

}

这是我的连接文件:

jco.client.lang=EN

jco.client.client=100

jco.client.passwd=xxxx

jco.client.user=xxxx

jco.client.sysnr=01

jco.client.ashost=xxxx

这是我的xml文件:

20120114120000DEBMAS06

DEBMAS

HTTPDEMO

LS

HTTPDEMO

SAPxxx

LS

xxxCLNT100

47

Test Customer

0004

TEST

City

PL

A

L

Street

我正在使用sapjco3-x86-64bit-3.0.5和sapidoc-3.0.1!

测试iDOC的创建并发送IDOC XML仅用于测试,但在本例中,我们已经准备好了iDOC!

我的问题是,如何通过RFC将iDOC 从磁盘直接发送到SAP? 如果无法这样做,如何解决创建iDOC或发送iDOC XML的错误? 我的第二个问题,一旦我能够发送iDOC,是否必须建立一个新的SERVER RFC连接,以便可以从SAP接收iDOC?

** 编辑 **

现在,我可以正确发送和接收IDoc。 我的问题是如何将IDoc作为Flat IDoc获得 。

我可以使用以下代码将IDoc作为XML IDoc接收:

package com.idoc.actif;

import com.sap.conn.idoc.IDocDocumentList;

import com.sap.conn.idoc.IDocXMLProcessor;

import com.sap.conn.idoc.jco.*;

import com.sap.conn.jco.server.*;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStreamWriter;

public class IDocServerExample

{

public static void main(String[] a)

{

try

{

// see provided examples of configuration files xxxx.jcoServer and xxxx.jcoDestination

JCoIDocServer server = JCoIDoc.getServer("xxxx");

server.setIDocHandlerFactory(new MyIDocHandlerFactory());

server.setTIDHandler(new MyTidHandler());

MyThrowableListener listener = new MyThrowableListener();

server.addServerErrorListener(listener);

server.addServerExceptionListener(listener);

//server.setConnectionCount(1);

server.start();

}

catch (Exception e)

{

e.printStackTrace();

}

}

static class MyIDocHandler implements JCoIDocHandler

{

public void handleRequest(JCoServerContext serverCtx, IDocDocumentList idocList)

{

FileOutputStream fos=null;

OutputStreamWriter osw=null;

try

{

//receiving XML IDoc, how to get the IDoc as a Flat IDoc (SAP is sending the IDoc as Flat)???

IDocXMLProcessor xmlProcessor = JCoIDoc.getIDocFactory().getIDocXMLProcessor();

fos=new FileOutputStream(serverCtx.getTID());

osw=new OutputStreamWriter(fos, "UTF8");

xmlProcessor.render(idocList, osw, IDocXMLProcessor.RENDER_WITH_TABS_AND_CRLF);

osw.flush();

}

catch (Throwable thr)

{

thr.printStackTrace();

}

finally

{

try

{

if (osw!=null)

osw.close();

if (fos!=null)

fos.close();

}

catch (IOException e)

{

e.printStackTrace();

}

}

}

}

static class MyIDocHandlerFactory implements JCoIDocHandlerFactory

{

private JCoIDocHandler handler = new MyIDocHandler();

public JCoIDocHandler getIDocHandler(JCoIDocServerContext serverCtx)

{

return handler;

}

}

static class MyThrowableListener implements JCoServerErrorListener, JCoServerExceptionListener

{

public void serverErrorOccurred(JCoServer server, String connectionId, JCoServerContextInfo ctx, Error error)

{

System.out.println(">>> Error occured on " + server.getProgramID() + " connection " + connectionId);

error.printStackTrace();

}

public void serverExceptionOccurred(JCoServer server, String connectionId, JCoServerContextInfo ctx, Exception error)

{

System.out.println(">>> Error occured on " + server.getProgramID() + " connection " + connectionId);

error.printStackTrace();

}

}

static class MyTidHandler implements JCoServerTIDHandler

{

public boolean checkTID(JCoServerContext serverCtx, String tid)

{

System.out.println("checkTID called for TID="+tid);

return true;

}

public void confirmTID(JCoServerContext serverCtx, String tid)

{

System.out.println("confirmTID called for TID="+tid);

}

public void commit(JCoServerContext serverCtx, String tid)

{

System.out.println("commit called for TID="+tid);

}

public void rollback(JCoServerContext serverCtx, String tid)

{

System.out.print("rollback called for TID="+tid);

}

}

}

 类似资料: