@@ -80,13 +80,13 @@ private void handleSocketData(SockJSSocket sock, Buffer data, Map<String, Messag
80
80
try {
81
81
msg = new JsonObject (data .toString ());
82
82
} catch (DecodeException e ) {
83
- replyError (sock , "invalid_json " );
83
+ replyError (sock , "INVALID_JSON" , "Malformed JSON " );
84
84
return ;
85
85
}
86
86
87
87
String type = msg .getString ("type" );
88
88
if (type == null ) {
89
- replyError (sock , "missing_type " );
89
+ replyError (sock , "MISSING_TYPE" , "Message type is missing " );
90
90
return ;
91
91
}
92
92
@@ -95,7 +95,7 @@ private void handleSocketData(SockJSSocket sock, Buffer data, Map<String, Messag
95
95
} else {
96
96
String address = msg .getString ("address" );
97
97
if (address == null ) {
98
- replyError (sock , "missing_address " );
98
+ replyError (sock , "MISSING_ADDRESS" , "Message address is missing " );
99
99
return ;
100
100
}
101
101
switch (type ) {
@@ -113,7 +113,7 @@ private void handleSocketData(SockJSSocket sock, Buffer data, Map<String, Messag
113
113
break ;
114
114
default :
115
115
LOG .error ("Invalid type in incoming message: " + type );
116
- replyError (sock , "invalid_type " );
116
+ replyError (sock , "INVALID_TYPE" , "Invalid message type " );
117
117
}
118
118
}
119
119
@@ -165,19 +165,19 @@ private void internalHandleSendOrPub(SockJSSocket sock, boolean send, JsonObject
165
165
() -> {
166
166
String address = msg .getString ("address" );
167
167
if (address == null ) {
168
- replyError (sock , "missing_address " );
168
+ replyError (sock , "MISSING_ADDRESS" , "Message address is missing " );
169
169
return ;
170
170
}
171
171
doSendOrPub (send , sock , address , msg );
172
- }, () -> replyError (sock , "rejected" ));
172
+ }, () -> replyError (sock , "REJECTED" , "Message is rejected" ));
173
173
}
174
174
175
175
private boolean checkMaxHandlers (SockJSSocket sock , SockInfo info ) {
176
176
if (info .handlerCount < maxHandlersPerSocket ) {
177
177
return true ;
178
178
} else {
179
179
LOG .warn ("Refusing to register as max_handlers_per_socket reached already" );
180
- replyError (sock , "max_handlers_reached " );
180
+ replyError (sock , "HANDLERS_MAX_LIMIT" , "Registration handlers exceed the maximum limit " );
181
181
return false ;
182
182
}
183
183
}
@@ -192,11 +192,11 @@ private void internalHandleRegister(SockJSSocket sock, JsonObject rawMsg, Map<St
192
192
final boolean debug = LOG .isDebugEnabled ();
193
193
final String address = rawMsg .getString ("address" );
194
194
if (address == null ) {
195
- replyError (sock , "missing_address " );
195
+ replyError (sock , "MISSING_ADDRESS" , "Message address is missing " );
196
196
return ;
197
197
} else if (address .length () > maxAddressLength ) {
198
198
LOG .warn ("Refusing to register as address length > max_address_length" );
199
- replyError (sock , "max_address_length_reached " );
199
+ replyError (sock , "ADDRESS_MAX_LENGTH" , "Address exceeds maximum length " );
200
200
return ;
201
201
}
202
202
Match match = checkMatches (false , address , null );
@@ -206,7 +206,7 @@ private void internalHandleRegister(SockJSSocket sock, JsonObject rawMsg, Map<St
206
206
// loop could DDoS the bridge.
207
207
if (registrations .containsKey (address )) {
208
208
LOG .warn ("Refusing to register as address is already registered" );
209
- replyError (sock , "address_already_registered " );
209
+ replyError (sock , "ADDRESS_ALREADY_REGISTERED" , "Address is already registered " );
210
210
return ;
211
211
}
212
212
@@ -247,25 +247,25 @@ private void internalHandleRegister(SockJSSocket sock, JsonObject rawMsg, Map<St
247
247
checkCallHook (() -> new BridgeEventImpl (BridgeEventType .REGISTERED , rawMsg , sock ));
248
248
} else {
249
249
LOG .warn ("Cannot register handler for address " + address , ar .cause ());
250
- replyError (sock , "registration_failure " );
250
+ replyError (sock , "ADDRESS_REGISTRATION" , "Address registration is failed " );
251
251
}
252
252
});
253
253
} else {
254
254
// inbound match failed
255
255
if (debug ) {
256
256
LOG .debug ("Cannot register handler for address " + address + " because there is no inbound match" );
257
257
}
258
- replyError (sock , "access_denied " );
258
+ replyError (sock , "ACCESS_DENIED" , "Address access is denied " );
259
259
}
260
- }, () -> replyError (sock , "rejected" ));
260
+ }, () -> replyError (sock , "REJECTED" , "Message is rejected" ));
261
261
}
262
262
263
263
private void internalHandleUnregister (SockJSSocket sock , JsonObject rawMsg , Map <String , MessageConsumer <?>> registrations ) {
264
264
checkCallHook (() -> new BridgeEventImpl (BridgeEventType .UNREGISTER , rawMsg , sock ),
265
265
() -> {
266
266
String address = rawMsg .getString ("address" );
267
267
if (address == null ) {
268
- replyError (sock , "missing_address " );
268
+ replyError (sock , "MISSING_ADDRESS" , "Message address is missing " );
269
269
return ;
270
270
}
271
271
Match match = checkMatches (false , address , null );
@@ -280,9 +280,9 @@ private void internalHandleUnregister(SockJSSocket sock, JsonObject rawMsg, Map<
280
280
if (LOG .isDebugEnabled ()) {
281
281
LOG .debug ("Cannot unregister handler for address " + address + " because there is no inbound match" );
282
282
}
283
- replyError (sock , "access_denied " );
283
+ replyError (sock , "ACCESS_DENIED" , "Address access is denied " );
284
284
}
285
- }, () -> replyError (sock , "rejected" ));
285
+ }, () -> replyError (sock , "REJECTED" , "Message is rejected" ));
286
286
}
287
287
288
288
private void internalHandlePing (final SockJSSocket sock ) {
@@ -317,7 +317,7 @@ public void handle(final SockJSSocket sock) {
317
317
checkCallHook (() -> new BridgeEventImpl (BridgeEventType .SOCKET_IDLE , null , sock ),
318
318
// We didn't receive a ping in time so close the socket
319
319
((SockJSSocketBase ) sock )::closeAfterSessionExpired ,
320
- () -> replyError (sock , "rejected" ));
320
+ () -> replyError (sock , "REJECTED" , "Message is rejected" ));
321
321
}
322
322
});
323
323
SockInfo sockInfo = new SockInfo ();
@@ -334,9 +334,11 @@ private void handleSocketClosed(SockJSSocket sock, Map<String, MessageConsumer<?
334
334
private void handleSocketException (SockJSSocket sock , Throwable err , Map <String , MessageConsumer <?>> registrations ) {
335
335
LOG .error ("SockJSSocket exception" , err );
336
336
clearSocketState (sock , registrations );
337
- final JsonObject msg = new JsonObject ().put ("type" , "err" ).put ("failureType" , "socketException " );
337
+ final JsonObject msg = new JsonObject ().put ("type" , "err" ).put ("failureCode" , - 1 ). put ( " failureType" , "SOCKET_EXCEPTION " );
338
338
if (err != null ) {
339
339
msg .put ("message" , err .getMessage ());
340
+ } else {
341
+ msg .put ("message" , "A socket exception occurred while attempting to establish or maintain a network connection" );
340
342
}
341
343
checkCallHook (() -> new BridgeEventImpl (BridgeEventType .SOCKET_ERROR , msg , sock ));
342
344
}
@@ -408,7 +410,7 @@ private void doSendOrPub(boolean send, SockJSSocket sock, String address,
408
410
if (replyAddress != null && replyAddress .length () > 36 ) {
409
411
// vertx-eventbus.js ids are always 36 chars
410
412
LOG .error ("Will not send message, reply address is > 36 chars" );
411
- replyError (sock , "invalid_reply_address " );
413
+ replyError (sock , "INVALID_REPLY_ADDRESS" , "Reply address is invalid " );
412
414
return ;
413
415
}
414
416
final boolean debug = LOG .isDebugEnabled ();
@@ -431,19 +433,19 @@ private void doSendOrPub(boolean send, SockJSSocket sock, String address,
431
433
if (ok ) {
432
434
checkAndSend (send , address , body , headers , sock , replyAddress , awaitingReply );
433
435
} else {
434
- replyError (sock , "access_denied " );
436
+ replyError (sock , "ACCESS_DENIED" , "Address access is denied " );
435
437
if (debug ) {
436
438
LOG .debug ("Inbound message for address " + address + " rejected because is not authorised" );
437
439
}
438
440
}
439
441
})
440
442
.onFailure (err -> {
441
- replyError (sock , "auth_error " );
443
+ replyError (sock , "AUTHZ" , "Authorization failed " );
442
444
LOG .error ("Error in performing authorization" , err );
443
445
});
444
446
} else {
445
447
// no web session
446
- replyError (sock , "not_logged_in " );
448
+ replyError (sock , "AUTHN" , "Authentication is required " );
447
449
if (debug ) {
448
450
LOG .debug ("Inbound message for address " + address +
449
451
" rejected because it requires auth and user is not authenticated" );
@@ -454,7 +456,7 @@ private void doSendOrPub(boolean send, SockJSSocket sock, String address,
454
456
}
455
457
} else {
456
458
// inbound match failed
457
- replyError (sock , "access_denied " );
459
+ replyError (sock , "ACCESS_DENIED" , "Address access is denied " );
458
460
if (debug ) {
459
461
LOG .debug ("Inbound message for address " + address + " rejected because there is no match" );
460
462
}
@@ -590,8 +592,12 @@ private boolean regexMatches(String matchRegex, String address) {
590
592
return m .matches ();
591
593
}
592
594
593
- private static void replyError (SockJSSocket sock , String err ) {
594
- JsonObject envelope = new JsonObject ().put ("type" , "err" ).put ("body" , err );
595
+ private static void replyError (SockJSSocket sock , String type , String message ) {
596
+ JsonObject envelope = new JsonObject ()
597
+ .put ("type" , "err" )
598
+ .put ("failureCode" , -1 )
599
+ .put ("failureType" , type )
600
+ .put ("message" , message );
595
601
sock .write (buffer (envelope .encode ()));
596
602
}
597
603
0 commit comments