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

@Singleton -> ClassCastException on broadcaster.addAtmosphereResource() w/ Jersey resource #444

Closed
jeremy303 opened this issue Jun 27, 2012 · 2 comments

Comments

@jeremy303
Copy link

ClassCastException is thrown when calling broadcaster.addAtmosphereResource() w/ injected BroadcasterFactory and AtmosphereResource.

@Path("/ps/")
public class PubSubExperiementResource
{
    @Context 
    BroadcasterFactory _broadcasterFactory;

    @Context
    AtmosphereResource _atmosphereResource;

    @Suspend
    @GET
    public String suspend() 
    {
        return "HELLO";
    }


    @POST
    public String receive( String request)
    {
        if( request.startsWith("s:") & request.length() > 2)
        {
            // subscribe
            String channelId = request.substring(2);
            Broadcaster broadcaster = _broadcasterFactory.get(channelId);

            broadcaster.addAtmosphereResource(_atmosphereResource);

return "SUBSCRIBE OK";
        }
        else if( request.startsWith("p:") & request.length() > 2)
        {
            // publish
            int i = request.indexOf(":", 2);
            String channelId = request.substring(2, i);
            String message = request.substring(i+1);
            _broadcasterFactory.get(channelId).broadcast(message);
            return "PUBLISH OK";
        }

        return "UNKNOWN COMMAND";
    }
}
jfarcand added a commit that referenced this issue Jun 27, 2012
jfarcand added a commit that referenced this issue Jun 27, 2012
@jeremy303
Copy link
Author

Just tested the fix for #444/#445. Works for @PerRequest and still throws the exception for @singleton when injecting @context via fields. However, that it does NOT throw the exception if injecting @context via method parameters.

@jfarcand jfarcand reopened this Jun 28, 2012
@jfarcand
Copy link
Member

Closing as not supported. There are workaround anyway.

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

No branches or pull requests

2 participants