001/* 002 * jPOS Project [http://jpos.org] 003 * Copyright (C) 2000-2026 jPOS Software SRL 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jpos.iso.channel; 020 021import org.jpos.core.Configuration; 022import org.jpos.core.ConfigurationException; 023import org.jpos.iso.FSDISOMsg; 024import org.jpos.iso.ISOException; 025import org.jpos.iso.ISOMsg; 026import org.jpos.util.FSDMsg; 027import org.jpos.util.LogEvent; 028import org.jpos.util.Logger; 029 030import java.io.IOException; 031import java.nio.charset.Charset; 032import org.jpos.iso.ISOUtil; 033 034public class FSDChannel extends NACChannel { 035 String schema; 036 Charset charset; 037 038 @Override 039 public ISOMsg createMsg() { 040 FSDMsg fsdmsg = new FSDMsg (schema); 041 fsdmsg.setCharset(charset); 042 return new FSDISOMsg (fsdmsg); 043 } 044 045 @Override 046 public void setConfiguration (Configuration cfg) 047 throws ConfigurationException 048 { 049 super.setConfiguration (cfg); 050 schema = cfg.get ("schema"); 051 charset = Charset.forName(cfg.get("charset", ISOUtil.CHARSET.displayName())); 052 } 053 054 @Override 055 public void send (ISOMsg m) 056 throws IOException, ISOException { 057 if(m instanceof FSDISOMsg) { 058 FSDMsg fsd = ((FSDISOMsg) m).getFSDMsg(); 059 fsd.setCharset(charset); 060 } 061 super.send(m); 062 } 063 064 @Override 065 protected int getMessageLength() throws IOException, ISOException { 066 int len = super.getMessageLength(); 067 LogEvent evt = new LogEvent (this, "fsd-channel-debug"); 068 evt.addMessage ("received message length: " + len); 069 Logger.log (evt); 070 return len; 071 } 072} 073