1919import java .lang .reflect .Field ;
2020import java .lang .reflect .InvocationTargetException ;
2121import java .lang .reflect .Method ;
22+ import java .lang .reflect .Modifier ;
2223import java .util .ArrayList ;
2324import java .util .Arrays ;
2425import java .util .List ;
@@ -147,7 +148,7 @@ public void configureChannel(ConfigurableServerChannel channel)
147148 boolean flip = false ;
148149 try
149150 {
150- logger .debug ("Configure channel {} with method {} on bean {}" , new Object []{ channel , method , bean } );
151+ logger .debug ("Configure channel {} with method {} on bean {}" , channel , method , bean );
151152 if (!method .isAccessible ())
152153 {
153154 flip = true ;
@@ -171,13 +172,13 @@ public void configureChannel(ConfigurableServerChannel channel)
171172
172173 if (initialized )
173174 {
174- logger .debug ("Channel {} already initialized. Not called method {} on bean {}" , new Object []{ channel , method , bean } );
175+ logger .debug ("Channel {} already initialized. Not called method {} on bean {}" , channel , method , bean );
175176 }
176177 else
177178 {
178179 if (configure .configureIfExists ())
179180 {
180- logger .debug ("Configure channel {} with method {} on bean {}" , new Object []{ channel , method , bean } );
181+ logger .debug ("Configure channel {} with method {} on bean {}" , channel , method , bean );
181182 init .configureChannel (bayeuxServer .getChannel (channel ));
182183 }
183184 else if (configure .errorIfExists ())
@@ -242,6 +243,9 @@ public boolean processCallbacks(Object bean)
242243 if (serviceAnnotation == null )
243244 return false ;
244245
246+ if (!Modifier .isPublic (klass .getModifiers ()))
247+ throw new IllegalArgumentException ("Service class '" + klass .getName () + "' must be public" );
248+
245249 LocalSession session = findOrCreateLocalSession (bean , serviceAnnotation .value ());
246250 boolean result = processListener (bean , session );
247251 result |= processSubscription (bean , session );
@@ -335,7 +339,7 @@ else if (field.getType().isAssignableFrom(serverSession.getClass()))
335339 {
336340 setField (bean , field , value );
337341 result = true ;
338- logger .debug ("Injected {} to field {} on bean {}" , new Object []{ value , field , bean } );
342+ logger .debug ("Injected {} to field {} on bean {}" , value , field , bean );
339343 }
340344 }
341345 }
@@ -358,7 +362,7 @@ else if (parameterTypes[0].isAssignableFrom(serverSession.getClass()))
358362 {
359363 invokeMethod (bean , method , value );
360364 result = true ;
361- logger .debug ("Injected {} to method {} on bean {}" , new Object []{ value , method , bean } );
365+ logger .debug ("Injected {} to method {} on bean {}" , value , method , bean );
362366 }
363367 }
364368 }
@@ -378,6 +382,9 @@ private boolean processListener(Object bean, LocalSession localSession)
378382 Listener listener = method .getAnnotation (Listener .class );
379383 if (listener != null )
380384 {
385+ if (!Modifier .isPublic (method .getModifiers ()))
386+ throw new IllegalArgumentException ("Service method '" + method .getName () + "' in class '" + method .getDeclaringClass ().getName () + "' must be public" );
387+
381388 String [] channels = listener .value ();
382389 for (String channel : channels )
383390 {
@@ -395,7 +402,7 @@ private boolean processListener(Object bean, LocalSession localSession)
395402 }
396403 callbacks .add (listenerCallback );
397404 result = true ;
398- logger .debug ("Registered listener for channel {} to method {} on bean {}" , new Object []{ channel , method , bean } );
405+ logger .debug ("Registered listener for channel {} to method {} on bean {}" , channel , method , bean );
399406 }
400407 }
401408 }
@@ -433,6 +440,9 @@ private boolean processSubscription(Object bean, LocalSession localSession)
433440 Subscription subscription = method .getAnnotation (Subscription .class );
434441 if (subscription != null )
435442 {
443+ if (!Modifier .isPublic (method .getModifiers ()))
444+ throw new IllegalArgumentException ("Service method '" + method .getName () + "' in class '" + method .getDeclaringClass ().getName () + "' must be public" );
445+
436446 String [] channels = subscription .value ();
437447 for (String channel : channels )
438448 {
@@ -449,7 +459,7 @@ private boolean processSubscription(Object bean, LocalSession localSession)
449459 }
450460 callbacks .add (subscriptionCallback );
451461 result = true ;
452- logger .debug ("Registered subscriber for channel {} to method {} on bean {}" , new Object []{ channel , method , bean } );
462+ logger .debug ("Registered subscriber for channel {} to method {} on bean {}" , channel , method , bean );
453463 }
454464 }
455465 }
@@ -498,25 +508,24 @@ public boolean onMessage(ServerSession from, ServerChannel channel, ServerMessag
498508 if (from == localSession .getServerSession () && !receiveOwnPublishes )
499509 return true ;
500510
501- boolean accessible = method .isAccessible ();
502511 try
503512 {
504- method .setAccessible (true );
505513 Object result = method .invoke (target , from , message );
506514 return !Boolean .FALSE .equals (result );
507515 }
508516 catch (InvocationTargetException x )
509517 {
510- throw new RuntimeException (x .getCause ());
518+ Throwable cause = x .getCause ();
519+ if (cause instanceof RuntimeException )
520+ throw (RuntimeException )cause ;
521+ if (cause instanceof Error )
522+ throw (Error )cause ;
523+ throw new RuntimeException (cause );
511524 }
512525 catch (IllegalAccessException x )
513526 {
514527 throw new RuntimeException (x );
515528 }
516- finally
517- {
518- method .setAccessible (accessible );
519- }
520529 }
521530 }
522531
@@ -541,24 +550,23 @@ public SubscriptionCallback(LocalSession localSession, Object target, Method met
541550
542551 public void onMessage (ClientSessionChannel channel , Message message )
543552 {
544- boolean accessible = method .isAccessible ();
545553 try
546554 {
547- method .setAccessible (true );
548555 method .invoke (target , message );
549556 }
550557 catch (InvocationTargetException x )
551558 {
552- throw new RuntimeException (x .getCause ());
559+ Throwable cause = x .getCause ();
560+ if (cause instanceof RuntimeException )
561+ throw (RuntimeException )cause ;
562+ if (cause instanceof Error )
563+ throw (Error )cause ;
564+ throw new RuntimeException (cause );
553565 }
554566 catch (IllegalAccessException x )
555567 {
556568 throw new RuntimeException (x );
557569 }
558- finally
559- {
560- method .setAccessible (accessible );
561- }
562570 }
563571 }
564572}
0 commit comments