@@ -53,7 +53,8 @@ public static VmService connect(final String url) throws IOException {
53
53
URI uri ;
54
54
try {
55
55
uri = new URI (url );
56
- } catch (URISyntaxException e ) {
56
+ }
57
+ catch (URISyntaxException e ) {
57
58
throw new IOException ("Invalid URL: " + url , e );
58
59
}
59
60
String wsScheme = uri .getScheme ();
@@ -65,7 +66,8 @@ public static VmService connect(final String url) throws IOException {
65
66
WebSocket webSocket ;
66
67
try {
67
68
webSocket = new WebSocket (uri );
68
- } catch (WebSocketException e ) {
69
+ }
70
+ catch (WebSocketException e ) {
69
71
throw new IOException ("Failed to create websocket: " + url , e );
70
72
}
71
73
final VmService vmService = new VmService ();
@@ -84,7 +86,8 @@ public void onMessage(WebSocketMessage message) {
84
86
Logging .getLogger ().logInformation ("VM message: " + message .getText ());
85
87
try {
86
88
vmService .processMessage (message .getText ());
87
- } catch (Exception e ) {
89
+ }
90
+ catch (Exception e ) {
88
91
Logging .getLogger ().logError (e .getMessage (), e );
89
92
}
90
93
}
@@ -106,12 +109,13 @@ public void onPong() {
106
109
});
107
110
108
111
// Establish WebSocket Connection
109
- //noinspection TryWithIdenticalCatches
110
112
try {
111
113
webSocket .connect ();
112
- } catch (WebSocketException e ) {
114
+ }
115
+ catch (WebSocketException e ) {
113
116
throw new IOException ("Failed to connect: " + url , e );
114
- } catch (ArrayIndexOutOfBoundsException e ) {
117
+ }
118
+ catch (ArrayIndexOutOfBoundsException e ) {
115
119
// The weberknecht can occasionally throw an array index exception if a connect terminates on initial connect
116
120
// (de.roderick.weberknecht.WebSocket.connect, WebSocket.java:126).
117
121
throw new IOException ("Failed to connect: " + url , e );
@@ -125,7 +129,7 @@ public void onPong() {
125
129
@ Override
126
130
public void onError (RPCError error ) {
127
131
String msg = "Failed to determine protocol version: " + error .getCode () + "\n message: "
128
- + error .getMessage () + "\n details: " + error .getDetails ();
132
+ + error .getMessage () + "\n details: " + error .getDetails ();
129
133
Logging .getLogger ().logInformation (msg );
130
134
errMsg [0 ] = msg ;
131
135
}
@@ -145,7 +149,8 @@ public void received(Version version) {
145
149
if (errMsg [0 ] != null ) {
146
150
throw new IOException (errMsg [0 ]);
147
151
}
148
- } catch (InterruptedException e ) {
152
+ }
153
+ catch (InterruptedException e ) {
149
154
throw new RuntimeException ("Interrupted while waiting for response" , e );
150
155
}
151
156
@@ -156,7 +161,6 @@ public void received(Version version) {
156
161
* Connect to the VM observatory service on the given local port.
157
162
*
158
163
* @return an API object for interacting with the VM service (not {@code null}).
159
- *
160
164
* @deprecated prefer the Url based constructor {@link VmServiceBase#connect}
161
165
*/
162
166
@ Deprecated
@@ -253,8 +257,9 @@ public void onError(RPCError error) {
253
257
@ Override
254
258
public void received (Obj response ) {
255
259
if (response instanceof Instance ) {
256
- consumer .received ((Instance ) response );
257
- } else {
260
+ consumer .received ((Instance )response );
261
+ }
262
+ else {
258
263
onError (RPCError .unexpected ("Instance" , response ));
259
264
}
260
265
}
@@ -280,8 +285,9 @@ public void onError(RPCError error) {
280
285
@ Override
281
286
public void received (Obj response ) {
282
287
if (response instanceof Library ) {
283
- consumer .received ((Library ) response );
284
- } else {
288
+ consumer .received ((Library )response );
289
+ }
290
+ else {
285
291
onError (RPCError .unexpected ("Library" , response ));
286
292
}
287
293
}
@@ -343,7 +349,8 @@ public void connectionOpened() {
343
349
for (VmServiceListener listener : new ArrayList <>(vmListeners )) {
344
350
try {
345
351
listener .connectionOpened ();
346
- } catch (Exception e ) {
352
+ }
353
+ catch (Exception e ) {
347
354
Logging .getLogger ().logError ("Exception notifying listener" , e );
348
355
}
349
356
}
@@ -353,7 +360,8 @@ private void forwardEvent(String streamId, Event event) {
353
360
for (VmServiceListener listener : new ArrayList <>(vmListeners )) {
354
361
try {
355
362
listener .received (streamId , event );
356
- } catch (Exception e ) {
363
+ }
364
+ catch (Exception e ) {
357
365
Logging .getLogger ().logError ("Exception processing event: " + streamId + ", " + event .getJson (), e );
358
366
}
359
367
}
@@ -363,7 +371,8 @@ public void connectionClosed() {
363
371
for (VmServiceListener listener : new ArrayList <>(vmListeners )) {
364
372
try {
365
373
listener .connectionClosed ();
366
- } catch (Exception e ) {
374
+ }
375
+ catch (Exception e ) {
367
376
Logging .getLogger ().logError ("Exception notifying listener" , e );
368
377
}
369
378
}
@@ -394,8 +403,9 @@ void processMessage(String jsonText) {
394
403
// Decode the JSON
395
404
JsonObject json ;
396
405
try {
397
- json = (JsonObject ) JsonParser .parseString (jsonText );
398
- } catch (Exception e ) {
406
+ json = (JsonObject )JsonParser .parseString (jsonText );
407
+ }
408
+ catch (Exception e ) {
399
409
Logging .getLogger ().logError ("Parse message failed: " + jsonText , e );
400
410
return ;
401
411
}
@@ -415,12 +425,15 @@ void processMessage(String jsonText) {
415
425
}
416
426
if (json .has ("id" )) {
417
427
processRequest (json );
418
- } else {
428
+ }
429
+ else {
419
430
processNotification (json );
420
431
}
421
- } else if (json .has ("result" ) || json .has ("error" )) {
432
+ }
433
+ else if (json .has ("result" ) || json .has ("error" )) {
422
434
processResponse (json );
423
- } else {
435
+ }
436
+ else {
424
437
Logging .getLogger ().logError ("Malformed message" );
425
438
}
426
439
}
@@ -433,7 +446,8 @@ void processRequest(JsonObject json) {
433
446
String id ;
434
447
try {
435
448
id = json .get (ID ).getAsString ();
436
- } catch (Exception e ) {
449
+ }
450
+ catch (Exception e ) {
437
451
final String message = "Request malformed " + ID ;
438
452
Logging .getLogger ().logError (message , e );
439
453
final JsonObject error = new JsonObject ();
@@ -449,7 +463,8 @@ void processRequest(JsonObject json) {
449
463
String method ;
450
464
try {
451
465
method = json .get (METHOD ).getAsString ();
452
- } catch (Exception e ) {
466
+ }
467
+ catch (Exception e ) {
453
468
final String message = "Request malformed " + METHOD ;
454
469
Logging .getLogger ().logError (message , e );
455
470
final JsonObject error = new JsonObject ();
@@ -463,7 +478,8 @@ void processRequest(JsonObject json) {
463
478
JsonObject params ;
464
479
try {
465
480
params = json .get (PARAMS ).getAsJsonObject ();
466
- } catch (Exception e ) {
481
+ }
482
+ catch (Exception e ) {
467
483
final String message = "Request malformed " + METHOD ;
468
484
Logging .getLogger ().logError (message , e );
469
485
final JsonObject error = new JsonObject ();
@@ -504,7 +520,8 @@ public void error(int code, String message, JsonObject data) {
504
520
requestSink .add (response );
505
521
}
506
522
});
507
- } catch (Exception e ) {
523
+ }
524
+ catch (Exception e ) {
508
525
final String message = "Internal Server Error" ;
509
526
Logging .getLogger ().logError (message , e );
510
527
final JsonObject error = new JsonObject ();
@@ -516,48 +533,53 @@ public void error(int code, String message, JsonObject data) {
516
533
}
517
534
518
535
private static final RemoteServiceCompleter ignoreCallback =
519
- new RemoteServiceCompleter () {
520
- public void result (JsonObject result ) {
521
- // ignore
522
- }
536
+ new RemoteServiceCompleter () {
537
+ public void result (JsonObject result ) {
538
+ // ignore
539
+ }
523
540
524
- public void error (int code , String message , JsonObject data ) {
525
- // ignore
526
- }
527
- };
541
+ public void error (int code , String message , JsonObject data ) {
542
+ // ignore
543
+ }
544
+ };
528
545
529
546
void processNotification (JsonObject json ) {
530
547
String method ;
531
548
try {
532
549
method = json .get (METHOD ).getAsString ();
533
- } catch (Exception e ) {
550
+ }
551
+ catch (Exception e ) {
534
552
Logging .getLogger ().logError ("Request malformed " + METHOD , e );
535
553
return ;
536
554
}
537
555
JsonObject params ;
538
556
try {
539
557
params = json .get (PARAMS ).getAsJsonObject ();
540
- } catch (Exception e ) {
558
+ }
559
+ catch (Exception e ) {
541
560
Logging .getLogger ().logError ("Event missing " + PARAMS , e );
542
561
return ;
543
562
}
544
563
if ("streamNotify" .equals (method )) {
545
564
String streamId ;
546
565
try {
547
566
streamId = params .get (STREAM_ID ).getAsString ();
548
- } catch (Exception e ) {
567
+ }
568
+ catch (Exception e ) {
549
569
Logging .getLogger ().logError ("Event missing " + STREAM_ID , e );
550
570
return ;
551
571
}
552
572
Event event ;
553
573
try {
554
574
event = new Event (params .get (EVENT ).getAsJsonObject ());
555
- } catch (Exception e ) {
575
+ }
576
+ catch (Exception e ) {
556
577
Logging .getLogger ().logError ("Event missing " + EVENT , e );
557
578
return ;
558
579
}
559
580
forwardEvent (streamId , event );
560
- } else {
581
+ }
582
+ else {
561
583
if (!remoteServiceRunners .containsKey (method )) {
562
584
Logging .getLogger ().logError ("Unknown service " + method );
563
585
return ;
@@ -566,7 +588,8 @@ void processNotification(JsonObject json) {
566
588
final RemoteServiceRunner runner = remoteServiceRunners .get (method );
567
589
try {
568
590
runner .run (params , ignoreCallback );
569
- } catch (Exception e ) {
591
+ }
592
+ catch (Exception e ) {
570
593
Logging .getLogger ().logError ("Internal Server Error" , e );
571
594
}
572
595
}
@@ -587,7 +610,8 @@ void processResponse(JsonObject json) {
587
610
String id ;
588
611
try {
589
612
id = idElem .getAsString ();
590
- } catch (Exception e ) {
613
+ }
614
+ catch (Exception e ) {
591
615
Logging .getLogger ().logError ("Response missing " + ID , e );
592
616
return ;
593
617
}
@@ -603,7 +627,8 @@ void processResponse(JsonObject json) {
603
627
JsonObject result ;
604
628
try {
605
629
result = resultElem .getAsJsonObject ();
606
- } catch (Exception e ) {
630
+ }
631
+ catch (Exception e ) {
607
632
Logging .getLogger ().logError ("Response has invalid " + RESULT , e );
608
633
return ;
609
634
}
@@ -626,7 +651,8 @@ else if (!(consumer instanceof ServiceExtensionConsumer)) {
626
651
JsonObject error ;
627
652
try {
628
653
error = resultElem .getAsJsonObject ();
629
- } catch (Exception e ) {
654
+ }
655
+ catch (Exception e ) {
630
656
Logging .getLogger ().logError ("Response has invalid " + RESULT , e );
631
657
return ;
632
658
}
0 commit comments