37
37
import org .python .google .common .base .Throwables ;
38
38
import org .robotframework .javalib .annotation .Autowired ;
39
39
import org .robotframework .javalib .library .AnnotationLibrary ;
40
- import org .robotframework .remoteserver .RemoteServer ;
41
40
42
41
import javax .script .ScriptEngine ;
43
42
import javax .script .ScriptEngineManager ;
@@ -90,12 +89,81 @@ public static String loadRobotLibraryVersion() {
90
89
@ Autowired
91
90
protected RunOnFailure runOnFailure ;
92
91
92
+ @ Override
93
+ public Object runKeyword (String keywordName , List args , Map kwargs ) {
94
+
95
+ if (kwargs == null ) {
96
+ kwargs = new HashMap ();
97
+ }
98
+
99
+ List finalArgs ;
100
+ Map finalKwargs ;
101
+
102
+ // JavalibCore changes arguments of Call Method keywords to Strings after this check, so they need to handle their own objectMapping
103
+ if (!(keywordName .equals ("callObjectMethod" ) || keywordName .equals ("callObjectMethodInFxApplicationThread" ))) {
104
+ finalArgs = HelperFunctions .useMappedObjects (args );
105
+ finalKwargs = HelperFunctions .useMappedObjects (kwargs );
106
+ } else {
107
+ finalArgs = args ;
108
+ finalKwargs = kwargs ;
109
+ }
110
+
111
+
112
+ AtomicReference <Object > retval = new AtomicReference <>();
113
+ AtomicReference <RuntimeException > retExcep = new AtomicReference <>();
114
+
115
+ try {
116
+ RobotLog .ignoreDuplicates ();
117
+ // timeout + 500 ms so that underlying timeout has a chance to expire first
118
+ waitFor (getWaitUntilTimeout (TimeUnit .MILLISECONDS ) + 500 , TimeUnit .MILLISECONDS , () -> {
119
+
120
+ try {
121
+ retval .set (super .runKeyword (keywordName , finalArgs , finalKwargs ));
122
+ return true ;
123
+
124
+ } catch (JavaFXLibraryTimeoutException jfxte ){
125
+ // timeout already expired, catch exception and jump out
126
+ retExcep .set (jfxte );
127
+ throw jfxte ;
128
+
129
+ } catch (RuntimeException e ){
130
+ // catch exception and continue trying
131
+ retExcep .set (e );
132
+ return false ;
133
+ }
134
+ });
135
+ } catch (TimeoutException te ) {
136
+ RobotLog .reset ();
137
+ RuntimeException e = retExcep .get ();
138
+ runOnFailure .runOnFailure ();
139
+
140
+ if (e .getCause () instanceof JavaFXLibraryFatalException ) {
141
+ RobotLog .trace ("JavaFXLibrary: Caught JavaFXLibrary FATAL exception: \n " + Throwables .getStackTraceAsString (e ));
142
+ throw e ;
143
+ } else if (e .getCause () instanceof JavaFXLibraryNonFatalException ) {
144
+ RobotLog .trace ("JavaFXLibrary: Caught JavaFXLibrary NON-FATAL exception: \n " + Throwables .getStackTraceAsString (e ));
145
+ throw e ;
146
+ } else {
147
+ RobotLog .trace ("JavaFXLibrary: Caught JavaFXLibrary RUNTIME exception: \n " + Throwables .getStackTraceAsString (e ));
148
+ throw e ;
149
+ }
150
+ } catch (JavaFXLibraryTimeoutException jfxte ) {
151
+ RobotLog .reset ();
152
+ RobotLog .trace ("JavaFXLibrary: Caught JavaFXLibrary TIMEOUT exception: \n " + Throwables .getStackTraceAsString (jfxte ));
153
+ throw jfxte ;
154
+ }
155
+ RobotLog .reset ();
156
+ return retval .get ();
157
+ }
158
+
93
159
// overriding the run method to catch the control in case of failure, so that desired runOnFailureKeyword
94
160
// can be executed in controlled manner.
95
161
@ Override
96
- public Object runKeyword (String keywordName , Object [] args ) {
162
+ public Object runKeyword (String keywordName , List args ) {
163
+ // TODO: Check if this is ever called anymore
164
+ RobotLog .info ("runKeyword called with args ONLY" );
97
165
98
- Object [] finalArgs ;
166
+ List finalArgs ;
99
167
// JavalibCore changes arguments of Call Method keywords to Strings after this check, so they need to handle their own objectMapping
100
168
if (!(keywordName .equals ("callObjectMethod" ) || keywordName .equals ("callObjectMethodInFxApplicationThread" )))
101
169
finalArgs = HelperFunctions .useMappedObjects (args );
@@ -190,22 +258,23 @@ public static JavaFXLibrary getLibraryInstance() throws ScriptException {
190
258
}
191
259
192
260
public static void main (String [] args ) throws Exception {
193
- JavaFXLibraryRemoteServer .configureLogging ();
194
- System .out .println ("---------------------------= JavaFXLibrary =---------------------------- " );
195
- RemoteServer server = new JavaFXLibraryRemoteServer ();
196
- server .putLibrary ("/RPC2" , new JavaFXLibrary ());
197
261
int port = 8270 ;
198
262
InetAddress ipAddr = InetAddress .getLocalHost ();
199
263
200
264
try {
201
- if (args .length > 0 )
265
+ JavaFXLibraryRemoteServer .configureLogging ();
266
+ System .out .println ("----------------------------= JavaFXLibrary =-----------------------------" );
267
+ if (args .length > 0 ) {
202
268
port = Integer .parseInt (args [0 ]);
203
- else
269
+ }
270
+ else {
204
271
System .out .println ("RemoteServer for JavaFXLibrary will be started at default port of: " + port + ".\n " +
205
272
"If you wish to use another port, restart the library and give port number\n " +
206
273
"as an argument." );
274
+ }
207
275
208
- server .setPort (port );
276
+ JavaFXLibraryRemoteServer server = new JavaFXLibraryRemoteServer (port );
277
+ server .putLibrary ("/RPC2" , new JavaFXLibrary ());
209
278
server .start ();
210
279
System .out .println ("\n JavaFXLibrary " + ROBOT_LIBRARY_VERSION + " is now available at: " +
211
280
ipAddr .getHostAddress () + ":" + port + "\n " );
@@ -219,6 +288,9 @@ public static void main(String[] args) throws Exception {
219
288
} catch (BindException be ) {
220
289
System .out .println ("\n Error! " + be .getMessage () + ": " + ipAddr .getHostAddress () + ":" + port + "\n " );
221
290
System .exit (1 );
291
+ } catch (IOException ioe ) {
292
+ System .out .println ("\n Error! " + ioe .getMessage () + ": " + ipAddr .getHostAddress () + ":" + port + "\n " );
293
+ System .exit (1 );
222
294
}
223
295
}
224
296
}
0 commit comments