Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoders are populated only with the encoders specified with @Message #1487

Closed
aleksandarn opened this issue Mar 2, 2014 · 4 comments
Closed
Labels

Comments

@aleksandarn
Copy link
Contributor

If you create a @managedservice and implement and annotate only @ready method and you specify some encoders - you will receive NPE because when atmosphere tries to encode the return value of the @ready method the list of encoders is null.

The reason for that is because the encoders list is populated only with the encoders declared with @message annotation, which is visible in https://github.com/Atmosphere/atmosphere/blob/master/modules/cpr/src/main/java/org/atmosphere/config/managed/ManagedAtmosphereHandler.java#L100

The populateEncoders() method correctly parses @message and @ready annotations, but is only called if at least one @message annotation is present.

@jfarcand
Copy link
Member

jfarcand commented Mar 3, 2014

@aleksandarn Can you attach a test I can play with? For this issue and the other one you created. Thanks

@aleksandarn
Copy link
Contributor Author

I need time to prepare stand alone example, but this code snippet below
will reproduce the error:

@ManagedService( path="/pubsub")
public class ProtocolHandler{

   @Ready(encoders = {JacksonEncoder.class})
     public GenericMessage onReady(final AtmosphereResource r) {
        return new GenericMessage( "connect", "User connected");
    }

/*
* This is here to prevent the NPE. Without it, the encoders are not  
populated
*/
/*
@Message(encoders = {JacksonEncoder.class}, decoders =  
{JacksonDecoder.class})
public GenericMessage authorMessage(GenericMessage message) {
return null;
}
*/

}

class GenericMessage{
   public String type;
   public String data;
   public  GenericMessage(final String t, finalString d){
     type = t;
     data=d;
   }
}

Classes JaxonEncode and JacksonDecoder are the same found in the chat
sample.
The exception happens when the client connects.

On Mon, 03 Mar 2014 17:46:48 +0200, Jeanfrancois Arcand
notifications@github.com wrote:

@aleksandarn Can you attach a test I can play with?


Reply to this email directly or view it on GitHub.

Using Opera's mail client: http://www.opera.com/mail/

@aleksandarn
Copy link
Contributor Author

Here is a small project to reproduce issues #1487 and #1488

https://www.dropbox.com/sh/us976u6fzoxhisj/go7TziAvn_

Steps how to reproduce on Glassfish 3.1.2.2

Reproducing #1487

  1. In file realm add some user that you will use later to authenticate (exampe: testUser / password)
  2. Load the application.
  3. Choose any protocol except websocket - schoos any topic but not "protected"
  4. Connect - no message will appear in the browser, but exception will be dumped into the server log.

Working around #1487
In the code - uncomment the @message annotted method, re-compile and re-deploy
Reproduce the above steps - the browser will display: {"type":"connect","data":"Dummy message"}

Reproducing #1488

  1. Uncomment the "else" part in the @ready method, re-compile and re-deploy
  2. Reproduce the steps from above - you will get an exception dumpet into the server log. and
    {"type":"connect","data":"Not logged in"} in the browser.
    With websockets, it will try to re-connect and you will see the exception and the message in the browser repeatedly.
  3. Reload the page. If you use websockets, press the log-in button and authenticate with the already created user/password. If you use any of the other protocols, enter topic: protected
  4. On connecting you will see in the browser {"type":"connect","data":"User connected"}

@jfarcand
Copy link
Member

jfarcand commented Mar 5, 2014

The error is

java.lang.NullPointerException: null
    at org.atmosphere.config.managed.Invoker.matchEncoder(Invoker.java:118) ~[atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.config.managed.Invoker.encode(Invoker.java:68) ~[atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.config.managed.Invoker.all(Invoker.java:93) ~[atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.config.managed.ManagedAtmosphereHandler.message(ManagedAtmosphereHandler.java:350) ~[atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.config.managed.ManagedAtmosphereHandler.processReady(ManagedAtmosphereHandler.java:361) ~[atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.config.managed.ManagedAtmosphereHandler$1.onSuspend(ManagedAtmosphereHandler.java:118) ~[atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.cpr.AtmosphereResourceImpl.onSuspend(AtmosphereResourceImpl.java:640) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.cpr.AtmosphereResourceImpl.notifyListeners(AtmosphereResourceImpl.java:587) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.cpr.AtmosphereResourceImpl.notifyListeners(AtmosphereResourceImpl.java:564) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.cpr.AtmosphereResourceImpl.suspend(AtmosphereResourceImpl.java:383) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor.postInspect(AtmosphereResourceLifecycleInterceptor.java:119) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.cpr.AsynchronousProcessor.postInterceptors(AsynchronousProcessor.java:310) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:181) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:95) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.container.Jetty9AsyncSupportWithWebSocket.service(Jetty9AsyncSupportWithWebSocket.java:179) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1782) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:421) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.websocket.DefaultWebSocketProcessor.open(DefaultWebSocketProcessor.java:175) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.atmosphere.container.Jetty9WebSocketHandler.onWebSocketConnect(Jetty9WebSocketHandler.java:62) [atmosphere-runtime-2.1.1-SNAPSHOT.jar:2.1.1-SNAPSHOT]
    at org.eclipse.jetty.websocket.common.events.JettyListenerEventDriver.onConnect(JettyListenerEventDriver.java:86) [websocket-common-9.1.2.v20140210.jar:9.1.2.v20140210]
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.openSession(AbstractEventDriver.java:227) [websocket-common-9.1.2.v20140210.jar:9.1.2.v20140210]
    at org.eclipse.jetty.websocket.common.WebSocketSession.open(WebSocketSession.java:406) [websocket-common-9.1.2.v20140210.jar:9.1.2.v20140210]
    at org.eclipse.jetty.websocket.server.WebSocketServerFactory.sessionOpened(WebSocketServerFactory.java:443) [websocket-server-9.1.2.v20140210.jar:9.1.2.v20140210]
    at org.eclipse.jetty.websocket.server.WebSocketServerConnection.onOpen(WebSocketServerConnection.java:73) [websocket-server-9.1.2.v20140210.jar:9.1.2.v20140210]
    at org.eclipse.jetty.server.HttpConnection.completed(HttpConnection.java:318) [jetty-server-9.1.2.v20140210.jar:9.1.2.v20140210]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:406) [jetty-server-9.1.2.v20140210.jar:9.1.2.v20140210]
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:232) [jetty-server-9.1.2.v20140210.jar:9.1.2.v20140210]
    at org.eclipse.jetty.io.AbstractConnection$1.run(AbstractConnection.java:505) [jetty-io-9.1.2.v20140210.jar:9.1.2.v20140210]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607) [jetty-util-9.1.2.v20140210.jar:9.1.2.v20140210]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536) [jetty-util-9.1.2.v20140210.jar:9.1.2.v20140210]
    at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants