1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package openr66.context.task;
22
23 import goldengate.common.logging.GgInternalLogger;
24 import goldengate.common.logging.GgInternalLoggerFactory;
25
26 import java.io.File;
27 import java.io.FileNotFoundException;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30
31 import openr66.context.ErrorCode;
32 import openr66.context.R66Session;
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class LogTask extends AbstractTask {
47
48
49
50 private static final GgInternalLogger logger = GgInternalLoggerFactory
51 .getLogger(LogTask.class);
52
53
54
55
56
57
58
59 public LogTask(String argRule, int delay, String argTransfer,
60 R66Session session) {
61 super(TaskType.LOG, delay, argRule, argTransfer, session);
62 }
63
64
65
66
67
68
69 @Override
70 public void run() {
71 String finalValue = argRule;
72 finalValue = getReplacedValue(finalValue, argTransfer.split(" "));
73 switch (delay) {
74 case 0:
75 break;
76 case 1:
77 logger.warn(finalValue+"\n " + session.toString());
78 break;
79 case 3:
80 logger.warn(finalValue+"\n " + session.toString());
81 case 2:
82 String []args = finalValue.split(" ");
83 String filename = args[args.length-1];
84 File file = new File(filename);
85 if (file.getParentFile() == null ||
86 (!file.canWrite())) {
87
88 session.getRunner().setErrorExecutionStatus(ErrorCode.Warning);
89 logger.warn(finalValue+"\n " + session.toString());
90 futureCompletion.setSuccess();
91 return;
92 }
93 FileOutputStream outputStream = null;
94 try {
95 outputStream = new FileOutputStream(file);
96 } catch (FileNotFoundException e) {
97
98 session.getRunner().setErrorExecutionStatus(ErrorCode.Warning);
99 logger.warn(finalValue+"\n " + session.toString());
100 futureCompletion.setSuccess();
101 return;
102 }
103 try {
104 outputStream.write(finalValue.getBytes());
105 } catch (IOException e) {
106
107 try {
108 outputStream.close();
109 } catch (IOException e1) {
110 }
111 file.delete();
112 session.getRunner().setErrorExecutionStatus(ErrorCode.Warning);
113 logger.warn(finalValue+"\n " + session.toString());
114 futureCompletion.setSuccess();
115 return;
116 }
117 try {
118 outputStream.close();
119 } catch (IOException e) {
120 }
121 break;
122 default:
123 }
124 futureCompletion.setSuccess();
125 }
126
127 }