📄 rfctest.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: RfcTest.java
package com.sap.mw.jco.support;
import com.sap.mw.jco.JCO;
import com.sap.mw.jco.util.Codecs;
import java.io.*;
import java.util.*;
public class RfcTest
{
protected static class Codec
{
protected static String encode(String in)
{
if(in == null)
return "null";
try
{
byte bytes[] = in.getBytes("UTF8");
char chars[] = com.sap.mw.jco.util.Codecs.Base64.encode(bytes);
return new String(chars);
}
catch(UnsupportedEncodingException ex)
{
return null;
}
}
protected static String decode(String in)
{
if(in.equals("null"))
return null;
try
{
byte bytes[] = com.sap.mw.jco.util.Codecs.Base64.decode(in);
return new String(bytes, "UTF8");
}
catch(UnsupportedEncodingException ex)
{
return null;
}
}
protected Codec()
{
}
}
static class TidEntry
{
byte[] getBytes()
{
try
{
byte result[] = new byte[60];
Arrays.fill(result, (byte)32);
System.arraycopy(TID.getBytes("UTF8"), 0, result, 0, TID.length());
System.arraycopy(state.getBytes("UTF8"), 0, result, 34, state.length());
result[59] = 10;
return result;
}
catch(UnsupportedEncodingException ex)
{
ex.printStackTrace();
}
return null;
}
static TidEntry parse(byte line[])
{
if(line[0] == 42)
return null;
TidEntry entry = new TidEntry((new String(line, 0, 32)).trim(), (new String(line, 34, 25)).trim());
if(entry.TID.length() > 0 && entry.state.length() > 0)
return entry;
else
return null;
}
String TID;
String state;
private static final int tid_offset = 0;
private static final int tid_length = 32;
private static final int state_offset = 34;
private static final int state_length = 25;
TidEntry(String tid, String state)
{
TID = tid;
this.state = state;
}
}
static class TidManager
{
void update_TID(String tid, String tid_state)
{
int idx = 0;
byte line[] = new byte[60];
RandomAccessFile ras = null;
try
{
boolean eof = false;
boolean found = false;
ras = new RandomAccessFile(file, "rw");
long file_offset = ras.getFilePointer();
while(!eof)
{
Arrays.fill(line, (byte)32);
idx = 0;
try
{
file_offset = ras.getFilePointer();
byte byte0;
while((byte0 = ras.readByte()) != 10)
if(idx < line.length)
line[idx++] = byte0;
}
catch(EOFException ex)
{
eof = true;
}
TidEntry entry = TidEntry.parse(line);
if(entry != null && entry.TID.equals(tid))
{
found = true;
entry.state = tid_state;
ras.seek(file_offset);
ras.write((new TidEntry(tid, tid_state)).getBytes());
}
}
if(!found)
ras.write((new TidEntry(tid, tid_state)).getBytes());
}
catch(IOException ex)
{
System.out.println("Error during file operation: " + ex.toString());
}
finally
{
try
{
if(ras != null)
ras.close();
}
catch(IOException ex)
{
System.out.println("Error during file closing: " + ex.toString());
}
}
}
private String fileName;
private File file;
public static final String CHECKED = "CHECKED";
public static final String CONFIRMED = "CONFIRMED";
public static final String COMMITED = "COMMITED";
public static final String ROLLBACKED = "ROLLBACKED";
public static final String CREATED = "CREATED";
TidManager(String fileName)
{
this.fileName = null;
this.fileName = fileName;
file = new File(fileName);
RandomAccessFile ras = null;
try
{
if(!file.exists())
try
{
ras = new RandomAccessFile(file, "rw");
ras.write("*** TID-MANAGEMENT FOR TRANSACTIONAL RFC (Server Program) ***\n".getBytes("UTF8"));
}
catch(IOException ex)
{
System.out.println("Error during file operation: " + ex.toString());
}
}
finally
{
try
{
if(ras != null)
ras.close();
}
catch(IOException ex)
{
System.out.println("Error during file operation: " + ex.toString());
}
}
}
}
public RfcTest()
{
}
protected static Properties loadProperties(String file_name)
{
Properties props = new Properties();
try
{
FileInputStream fis = null;
try
{
props.load(fis = new FileInputStream(file_name));
}
finally
{
fis.close();
}
}
catch(Exception ex) { }
if(props.containsKey("jco.client.passwd"))
{
String passwd = props.getProperty("jco.client.passwd");
props.setProperty("jco.client.passwd", Codec.decode(passwd));
}
if(props.containsKey("jco.client.ipasswd"))
{
String ipasswd = props.getProperty("jco.client.ipasswd");
props.setProperty("jco.client.ipasswd", Codec.decode(ipasswd));
}
return props;
}
protected static void storeProperties(Properties props, String file_name, String description)
{
String passwd = null;
String ipasswd = null;
if(props.containsKey("jco.client.passwd"))
{
passwd = props.getProperty("jco.client.passwd");
props.setProperty("jco.client.passwd", Codec.encode(passwd));
}
if(props.containsKey("jco.client.ipasswd"))
{
ipasswd = props.getProperty("jco.client.ipasswd");
props.setProperty("jco.client.ipasswd", Codec.encode(ipasswd));
}
try
{
FileOutputStream fos = null;
try
{
props.store(fos = new FileOutputStream(file_name), description);
}
finally
{
fos.close();
}
}
catch(Exception ex) { }
if(props.containsKey("jco.client.passwd"))
props.setProperty("jco.client.passwd", passwd);
if(props.containsKey("jco.client.ipasswd"))
props.setProperty("jco.client.ipasswd", ipasswd);
}
protected static String ask(String question, String def_answer)
{
if(def_answer != null && def_answer.trim().length() > 0)
out.print(question + " [" + def_answer + "] :");
else
out.print(question + " :");
String answer;
try
{
answer = in.readLine().trim();
}
catch(IOException ex)
{
answer = "";
}
if(answer.length() == 0)
return def_answer;
else
return answer;
}
protected static String askSecure(String question, String def_answer)
{
String maskedAnswer = "?";
if(def_answer != null && def_answer.trim().length() > 0)
{
char maskedChars[] = new char[def_answer.trim().length()];
Arrays.fill(maskedChars, '*');
maskedAnswer = new String(maskedChars);
out.print(question + " [" + maskedAnswer + "] :");
} else
{
out.print(question + " :");
}
String answer;
try
{
answer = in.readLine().trim();
}
catch(IOException ex)
{
answer = "";
}
if(answer.length() == 0)
return def_answer;
else
return answer;
}
protected static void displayProperties(Properties props)
{
for(Enumeration e = props.keys(); e.hasMoreElements();)
{
String key = (String)e.nextElement();
if(!key.equals("jco.client.passwd"))
out.println(" " + key + " : " + props.getProperty(key));
else
out.println(" " + key + " : " + "XXXXXX");
}
}
protected static void displayException(Throwable ex)
{
if(ex instanceof com.sap.mw.jco.JCO.Exception)
{
out.println("JCO.Exception occured:");
out.println(" Group:" + ((com.sap.mw.jco.JCO.Exception)ex).getGroup());
out.println(" Key:" + ((com.sap.mw.jco.JCO.Exception)ex).getKey());
out.println(" Message:" + ((com.sap.mw.jco.JCO.Exception)ex).getMessage());
} else
{
out.println(ex.getClass().getName() + " occured:");
out.println(" Message:" + ex.getMessage());
}
}
protected static String stateToString(int state)
{
StringBuffer sb = new StringBuffer();
if((state & 1) != 0)
sb.append(" STOPPED ");
if((state & 2) != 0)
sb.append(" STARTED ");
if((state & 8) != 0)
sb.append(" LISTENING ");
if((state & 0x20) != 0)
sb.append(" TRANSACTION ");
if((state & 4) != 0)
sb.append(" BUSY ");
return sb.toString();
}
protected static PrintStream out;
protected static BufferedReader in;
static
{
out = System.out;
in = new BufferedReader(new InputStreamReader(System.in));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -