安否確認でのTIPS
2008-6-5
tanifuji
安否確認
ログフォーマットの統一
ログを残すことは、MPNの反省点からある程度残すようにしていましたが、logクラスとlogContentsクラスの、フォーマットが違う2つで残してしまっていた。アクション外でのログの書き出しのためのメソッドの追加が遅れたので、そこの回収に手間取ってしまった。
DTOのインターフェース、クラスの作成
今回のDTOでは、共通フィールドがあり、レコードの作成時など共用メソッドで処理ができたと思うので、そこについてもう少し考えたい。
stacktraceのログへの出力
例外の出力でstacktraceを出す方法がわからなかったが、次のようにすることでできた。
try{
role = rdao.findById(rid).get(0);
} catch (Exception e){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);//StringWriterにstacktraceを書き込む
pw.close();
log.error(sw.toString());//StringWriterからlogに書き込む
}
MailContent
メールの内容などを記述するためのクラスMailContentでの、メールテンプレートファイルの指定は、置換用のハッシュとのマージに使っているVelocityEngineUtils.mergeTemplateIntoStringが絶対パスが使用できないため、ウェブアプリケーション外での動作にエラーを起こしていた。
Velocity.evaluateを使用することで絶対パスも使用できたのでこれをMailContentにも追加したい。
ApplicationResources.propertiesの書き換え
ApplicationResources.propertiesの書き換えをする。reloadableなどあるようなので再読み込みを試してみたが、うまくいかなかった。
String config = "ApplicationResources.properties";
FileReader inFile;
try{
inFile = new FileReader(config);
} catch(FileNotFoundException e){
throw e;
}
String line;
//BufferedReaderオブジェクトinBufferを生成
BufferedReader inBuffer = new BufferedReader(inFile);
try{
if(form.getStatus() != null && !"".equals(form.getStatus())){
StringWriter out = new StringWriter();
//読み込みデータがなくなるまで、読み込み
while ((line = inBuffer.readLine()) != null) {
//データの書き込み処理
if(line.matches("^encoding=.+") ){
int index = line.indexOf("=");
StringBuffer value = new StringBuffer(line);
value = value.replace(index + 1,
value.length(), "EUC-JP");
}
out.write(line + "\r\n");
}
}
FileWriter outFile = new FileWriter(config);
outFile.write(out.toString());
outFile.close();
} catch(Exception e){
throw new ServletException(e);
} finally {
inFile.close();
inBuffer.close();
}
by tanifuji


