@return A Properties object that contains a path-value-pair for each dataelement of
the received message. */
public HBCIMsgStatus rawDoIt(HBCIPassportList passports,boolean signit,boolean cryptit,boolean needSig,boolean needCrypt)
{
HBCIMsgStatus ret=new HBCIMsgStatus();
MSG msg=null;
try {
HBCIPassportInternal mainPassport=passports.getMainPassport();
HBCIUtils.log("generating raw message "+currentMsgName,HBCIUtils.LOG_DEBUG);
HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_MSG_CREATE,currentMsgName);
// plaintextnachricht erzeugen
msg=gen.generate(currentMsgName);
// alle daten f�r den rewriter setzen
Rewrite.setData("passports",passports);
Rewrite.setData("msgStatus",ret);
Rewrite.setData("msgName",currentMsgName);
Rewrite.setData("signIt",Boolean.valueOf(signit));
Rewrite.setData("cryptIt",Boolean.valueOf(cryptit));
Rewrite.setData("needSig",Boolean.valueOf(needSig));
Rewrite.setData("needCrypt",Boolean.valueOf(needCrypt));
// liste der rewriter erzeugen
String rewriters_st=HBCIUtils.getParam("kernel.rewriter");
ArrayList<Rewrite> al=new ArrayList<Rewrite>();
StringTokenizer tok=new StringTokenizer(rewriters_st,",");
while (tok.hasMoreTokens()) {
String rewriterName=tok.nextToken().trim();
if (rewriterName.length()!=0) {
Class cl=this.getClass().getClassLoader().loadClass("org.kapott.hbci.rewrite.R"+
rewriterName);
Constructor con=cl.getConstructor((Class[])null);
Rewrite rewriter=(Rewrite)(con.newInstance((Object[])null));
al.add(rewriter);
}
}
Rewrite[] rewriters=al.toArray(new Rewrite[al.size()]);
// alle rewriter durchlaufen und plaintextnachricht patchen
for (int i=0;i<rewriters.length;i++) {
MSG old=msg;
msg=rewriters[i].outgoingClearText(old,gen);
if (msg!=old) {
MSGFactory.getInstance().unuseObject(old);
}
}
// HBCIUtils.log("sending msg: "+msg.toString(0));
// wenn nachricht signiert werden soll
if (signit) {
HBCIUtils.log("trying to insert signature",HBCIUtils.LOG_DEBUG);
HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_MSG_SIGN,null);
// signatur erzeugen und an nachricht anh�ngen
Sig sig=SigFactory.getInstance().createSig(getParentHandlerData(),msg,passports);
try {
if (!sig.signIt()) {
String errmsg=HBCIUtilsInternal.getLocMsg("EXCMSG_CANTSIGN");
if (!HBCIUtilsInternal.ignoreError(null,"client.errors.ignoreSignErrors",errmsg)) {
throw new HBCI_Exception(errmsg);
}
}
} finally {
SigFactory.getInstance().unuseObject(sig);
}
// alle rewrites erledigen, die *nach* dem hinzuf�gen der signatur stattfinden m�ssen
for (int i=0;i<rewriters.length;i++) {
MSG old=msg;
msg=rewriters[i].outgoingSigned(old,gen);
if (msg!=old) {
MSGFactory.getInstance().unuseObject(old);
}
}
}
/* zu jeder SyntaxElement-Referenz (2:3,1)==(SEG:DEG,DE) den Pfad
des jeweiligen Elementes speichern */
Properties paths=new Properties();
msg.getElementPaths(paths,null,null,null);
ret.addData(paths);
/* f�r alle Elemente (Pfadnamen) die aktuellen Werte speichern,
wie sie bei der ausgehenden Nachricht versandt werden */
Hashtable<String,String> current=new Hashtable<String,String>();
msg.extractValues(current);
Properties origs=new Properties();
for (Enumeration<String> e=current.keys();e.hasMoreElements();) {
String key= e.nextElement();
String value= current.get(key);
origs.setProperty("orig_"+key,value);
}
ret.addData(origs);
// zu versendene nachricht loggen
String outstring=msg.toString(0);
HBCIUtils.log("sending message: "+outstring,HBCIUtils.LOG_DEBUG2);
// max. nachrichtengr��e aus BPD �berpr�fen
int maxmsgsize=mainPassport.getMaxMsgSizeKB();
if (maxmsgsize!=0 && (outstring.length()>>10)>maxmsgsize) {
String errmsg=HBCIUtilsInternal.getLocMsg("EXCMSG_MSGTOOLARGE",
new Object[] {Integer.toString(outstring.length()>>10),Integer.toString(maxmsgsize)});
if (!HBCIUtilsInternal.ignoreError(null,"client.errors.ignoreMsgSizeErrors",errmsg))
throw new HBCI_Exception(errmsg);
}
// soll nachricht verschl�sselt werden?
if (cryptit) {
HBCIUtils.log("trying to encrypt message",HBCIUtils.LOG_DEBUG);
HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_MSG_CRYPT,null);
// nachricht verschl�sseln
MSG old=msg;
Crypt crypt=CryptFactory.getInstance().createCrypt(getParentHandlerData(),old);
try {
msg=crypt.cryptIt("Crypted");
} finally {
CryptFactory.getInstance().unuseObject(crypt);
if (msg!=old) {
MSGFactory.getInstance().unuseObject(old);
}
}
if (!msg.getName().equals("Crypted")) {
String errmsg=HBCIUtilsInternal.getLocMsg("EXCMSG_CANTCRYPT");
if (!HBCIUtilsInternal.ignoreError(null,"client.errors.ignoreCryptErrors",errmsg))
throw new HBCI_Exception(errmsg);
}
// verschl�sselte nachricht patchen
for (int i=0;i<rewriters.length;i++) {
MSG oldMsg=msg;
msg=rewriters[i].outgoingCrypted(oldMsg,gen);
if (msg!=oldMsg) {
MSGFactory.getInstance().unuseObject(oldMsg);
}
}
HBCIUtils.log("encrypted message to be sent: "+msg.toString(0),HBCIUtils.LOG_DEBUG2);
}
// basic-values der ausgehenden nachricht merken
String msgPath=msg.getPath();
String msgnum=msg.getValueOfDE(msgPath+".MsgHead.msgnum");
String dialogid=msg.getValueOfDE(msgPath+".MsgHead.dialogid");
String hbciversion=msg.getValueOfDE(msgPath+".MsgHead.hbciversion");
// nachricht versenden und antwortnachricht empfangen
HBCIUtils.log("communicating dialogid/msgnum "+dialogid+"/"+msgnum,HBCIUtils.LOG_DEBUG);
MSG old=msg;
msg=mainPassport.getComm().pingpong(currentMsgName,old);
if (msg!=old) {
MSGFactory.getInstance().unuseObject(old);
}
// ist antwortnachricht verschl�sselt?
boolean crypted=msg.getName().equals("CryptedRes");
if (crypted) {
HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_MSG_DECRYPT,null);
// wenn ja, dann nachricht entschl�sseln
Crypt crypt=CryptFactory.getInstance().createCrypt(getParentHandlerData(),msg);
String newmsgstring;
try {
newmsgstring=crypt.decryptIt();
} finally {
CryptFactory.getInstance().unuseObject(crypt);
}
gen.set("_origSignedMsg",newmsgstring);
// alle patches f�r die unverschl�sselte nachricht durchlaufen
for (int i=0;i<rewriters.length;i++) {
newmsgstring=rewriters[i].incomingClearText(newmsgstring,gen);
}
HBCIUtils.log("decrypted message after rewriting: "+newmsgstring,HBCIUtils.LOG_DEBUG2);
// nachricht als plaintextnachricht parsen
try {
HBCIUtilsInternal.getCallback().status(mainPassport,HBCICallback.STATUS_MSG_PARSE,currentMsgName+"Res");
HBCIUtils.log("message to pe parsed: "+msg.toString(0),HBCIUtils.LOG_DEBUG2);
MSG oldMsg=msg;
msg=MSGFactory.getInstance().createMSG(currentMsgName+"Res",newmsgstring,newmsgstring.length(),gen);
if (msg!=oldMsg) {
MSGFactory.getInstance().unuseObject(oldMsg);
}
} catch (Exception ex) {
throw new CanNotParseMessageException(HBCIUtilsInternal.getLocMsg("EXCMSG_CANTPARSE"),newmsgstring,ex);
}
}
HBCIUtils.log("received message after decryption: "+msg.toString(0),HBCIUtils.LOG_DEBUG2);
// alle patches f�r die plaintextnachricht durchlaufen
for (int i=0;i<rewriters.length;i++) {
MSG oldMsg=msg;
msg=rewriters[i].incomingData(oldMsg,gen);
if (msg!=oldMsg) {
MSGFactory.getInstance().unuseObject(oldMsg);
}
}