import java
.io
.FileOutputStream;
import java
.util
.GregorianCalendar;
//***********************************************************
public class TestServer implements JCO
.ServerExceptionListener
, JCO
.ServerStateChangedListener
{
//***********************************************************
public static GregorianCalendar cal = new GregorianCalendar();
static public class Repository extends JCO
.BasicRepository implements IRepository
&#
123;
public Repository(String name)
{
super(name);
}
}
protected static IRepository repository;
static {
repository = new Repository("TestRepository");
JCO.MetaData fmeta1 = new JCO.MetaData("FUNCTION_SM");
fmeta1.addInfo("REQUTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.IMPORT_PARAMETER, null);
fmeta1.addInfo("ECHOTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.EXPORT_PARAMETER, null);
fmeta1.addInfo("RESPTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.EXPORT_PARAMETER, null);
repository.addFunctionInterfaceToCache(fmeta1);
JCO.MetaData fmeta = new JCO.MetaData("STFC_CONNECTION");
fmeta.addInfo("REQUTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.IMPORT_PARAMETER, null);
fmeta.addInfo("ECHOTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.EXPORT_PARAMETER, null);
fmeta.addInfo("RESPTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.EXPORT_PARAMETER, null);
repository.addFunctionInterfaceToCache(fmeta);
fmeta = new JCO.MetaData("STFC_STRUCTURE");
fmeta.addInfo("IMPORTSTRUCT", JCO.TYPE_STRUCTURE, 144, 0, 0, JCO.IMPORT_PARAMETER, "RFCTEST");
fmeta.addInfo("ECHOSTRUCT", JCO.TYPE_STRUCTURE, 144, 0, 0, JCO.EXPORT_PARAMETER, "RFCTEST");
fmeta.addInfo("RESPTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.EXPORT_PARAMETER, null );
fmeta.addInfo("RFCTABLE", JCO.TYPE_TABLE, 144, 0, 0, 0, "RFCTEST");
repository.addFunctionInterfaceToCache(fmeta);
JCO.MetaData smeta = new JCO.MetaData("RFCTEST");
smeta.addInfo("RFCFLOAT", JCO.TYPE_FLOAT, 8, 0, 0);
smeta.addInfo("RFCCHAR1", JCO.TYPE_CHAR, 1, 8, 0);
smeta.addInfo("RFCINT2", JCO.TYPE_INT2, 2, 10, 0);
smeta.addInfo("RFCINT1", JCO.TYPE_INT1, 1, 12, 0);
smeta.addInfo("RFCICHAR4", JCO.TYPE_CHAR, 4, 13, 0);
smeta.addInfo("RFCINT4", JCO.TYPE_INT, 4, 20, 0);
smeta.addInfo("RFCHEX3", JCO.TYPE_BYTE, 3, 24, 0);
smeta.addInfo("RFCCHAR2", JCO.TYPE_CHAR, 2, 27, 0);
smeta.addInfo("RFCTIME", JCO.TYPE_TIME, 6, 29, 0);
smeta.addInfo("RFRDATE", JCO.TYPE_DATE, 8, 35, 0);
smeta.addInfo("RFCDATA1", JCO.TYPE_CHAR, 50,43, 0);
smeta.addInfo("RFCDATA2", JCO.TYPE_CHAR, 50,93, 0);
repository.addStructureDefinitionToCache(smeta);
}
static public class Server extends JCO
.Server
&#
123;
/**
* Create an instance of my own server
* @param gwhost the gateway host
* @param gwserv the gateway service number
* @param repository the repository used by the server to lookup the definitions of an inc
*/
public Server(String gwhost, String gwserv, String progid, IRepository repository)
{
super(gwhost,gwserv,progid,repository);
}
/**********************************************************
* handleRequest
***********************************************************/
protected void handleRequest
&#
40;JCO
.Function function
&#
41; throws Exception
{
JCO
.ParameterList
input = function.getImportParameterList
&#
40;
&#
41;;
JCO
.ParameterList
output = function.getExportParameterList
&#
40;
&#
41;;
System.out.println("getImportParameterList:" + input);
if &#
40;
function.getName
&#
40;
&#
41;
.equals
&#
40;
"FUNCTION_SM")) { writeFile("Hallo Test" + cal.getTime());
}
else if &#
40;
function.getName
&#
40;
&#
41;
.equals
&#
40;
"STFC_CONNECTION")) { output.setValue
&#
40;
input.getString
&#
40;
"REQUTEXT"),"ECHOTEXT"); output.setValue("This is a response from TestServer.java","RESPTEXT");
}
else if &#
40;
function.getName
&#
40;
&#
41;
.equals
&#
40;
"STFC_STRUCTURE")) { JCO
.Structure sin = input.getStructure
&#
40;
"IMPORTSTRUCT"); JCO.Structure sout = (JCO.Structure)sin.clone();
System.out.println(sin);
}
catch &#
40;Exception ex
&#
41;
&#
123;
System.out.println(ex);
}
output.setValue(sout,"ECHOSTRUCT");
output.setValue("This is a response from TestServer.java","RESPTEXT");
}
}
/** List of servers */
JCO.Server srv[] = new JCO.Server[1];
/**
* Constructor
*/
public TestServer()
{
// Yes, we're interested in server exceptions
JCO.addServerExceptionListener(this);
// And we also want to know when the server(s) change their states
JCO.addServerStateChangedListener(this);
}
/**
* Start the server
*/
public void startServers()
{
// hier bitte die entsprechenden Daten eintragen!!!
srv[0] = new Server("IP Server", "System",
"JAVARFC",repository);
for (int i = 0; i < srv.length; i++) {
try {
srv[i].setTrace(true);
srv[i].start();
}
catch (Exception ex) {
System.out.println("Could not start server " + srv[i].getProgID() + ":\n" + ex);
}//try
}//for
}
/**
* Simply prints the text of the exception and a stack trace
*/
public void serverExceptionOccurred(JCO.Server server, Exception ex)
{
System.out.println("Exception in server " + server.getProgID() + ":\n" + ex);
ex.printStackTrace();
}
/**
* Simply prints server state changes
*/
public void serverStateChangeOccurred(JCO.Server server, int old_state, int new_state)
{
}
public static void writeFile(String s)
{
byte buffer[] = new byte[80];
try
{
FileOutputStream fos = new FileOutputStream( "c:/_SM/text.txt" );
fos.write( s.getBytes() );
fos.close();
}
catch ( Exception e ) { System.out.println(e); }
}
public static void main(String[] argv)
{
TestServer obj = new TestServer();
obj.startServers();
}
}