|
21 | 21 | package org.zaproxy.zap.extension.zest;
|
22 | 22 |
|
23 | 23 | import java.io.IOException;
|
| 24 | +import java.lang.reflect.Field; |
24 | 25 | import java.util.ArrayList;
|
25 | 26 | import java.util.List;
|
26 | 27 | import java.util.Map;
|
@@ -69,6 +70,8 @@ public class ZestZapRunner extends ZestBasicRunner implements ScannerListener {
|
69 | 70 |
|
70 | 71 | private static final int ZEST_HISTORY_REFERENCE_TYPE = HistoryReference.TYPE_ZEST_SCRIPT;
|
71 | 72 | private static final int FAIL_ACTION_PLUGIN_ID = 50004;
|
| 73 | + |
| 74 | + private static Field fieldOutputWriter; |
72 | 75 |
|
73 | 76 | private ExtensionZest extension;
|
74 | 77 | private ZestScriptWrapper wrapper = null;
|
@@ -126,24 +129,36 @@ public String run(ZestScript script, Map<String, String> params) throws ZestAsse
|
126 | 129 | this.target = null;
|
127 | 130 | if (wrapper.getWriter() != null) {
|
128 | 131 | super.setOutputWriter(wrapper.getWriter());
|
129 |
| - } else if (extension.getExtScript().getScriptUI() != null) { |
130 |
| - super.setOutputWriter(extension.getExtScript().getScriptUI().getOutputWriter()); |
| 132 | + } else if (scriptUI != null && !hasOutputWriter()) { |
| 133 | + super.setOutputWriter(scriptUI.getOutputWriter()); |
131 | 134 | }
|
132 | 135 | this.setDebug(this.wrapper.isDebug());
|
133 | 136 |
|
134 | 137 | return super.run(script, params);
|
135 | 138 | }
|
136 | 139 | }
|
137 | 140 |
|
| 141 | + private boolean hasOutputWriter() { |
| 142 | + try { |
| 143 | + if (fieldOutputWriter == null) { |
| 144 | + fieldOutputWriter = ZestBasicRunner.class.getDeclaredField("outputWriter"); |
| 145 | + fieldOutputWriter.setAccessible(true); |
| 146 | + } |
| 147 | + return fieldOutputWriter.get(this) != null; |
| 148 | + } catch (IllegalAccessException | NoSuchFieldException e) { |
| 149 | + return false; |
| 150 | + } |
| 151 | + } |
| 152 | + |
138 | 153 | @Override
|
139 | 154 | public String run (ZestScript script, ZestRequest target, Map<String, String> params)
|
140 | 155 | throws ZestAssertFailException, ZestActionFailException, IOException,
|
141 | 156 | ZestInvalidCommonTestException, ZestAssignFailException, ZestClientFailException {
|
142 | 157 | log.debug("Run script " + script.getTitle());
|
143 | 158 | if (wrapper.getWriter() != null) {
|
144 | 159 | super.setOutputWriter(wrapper.getWriter());
|
145 |
| - } else if (extension.getExtScript().getScriptUI() != null) { |
146 |
| - super.setOutputWriter(extension.getExtScript().getScriptUI().getOutputWriter()); |
| 160 | + } else if (scriptUI != null && !hasOutputWriter()) { |
| 161 | + super.setOutputWriter(scriptUI.getOutputWriter()); |
147 | 162 | }
|
148 | 163 | this.setDebug(this.wrapper.isDebug());
|
149 | 164 | String result = super.run(script, target, params);
|
|
0 commit comments