{"action":"created","issue":{"url":"https://api.github.com/repos/LivePersonInc/dropwizard-websockets/issues/2","labels_url":"https://api.github.com/repos/LivePersonInc/dropwizard-websockets/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/LivePersonInc/dropwizard-websockets/issues/2/comments","events_url":"https://api.github.com/repos/LivePersonInc/dropwizard-websockets/issues/2/events","html_url":"https://github.com/LivePersonInc/dropwizard-websockets/issues/2","id":122529679,"number":2,"title":"Can't @Inject into websocket endpoint","user":{"login":"mpbarnwell","id":6087327,"avatar_url":"https://avatars.githubusercontent.com/u/6087327?v=3","gravatar_id":"","url":"https://api.github.com/users/mpbarnwell","html_url":"https://github.com/mpbarnwell","followers_url":"https://api.github.com/users/mpbarnwell/followers","following_url":"https://api.github.com/users/mpbarnwell/following{/other_user}","gists_url":"https://api.github.com/users/mpbarnwell/gists{/gist_id}","starred_url":"https://api.github.com/users/mpbarnwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpbarnwell/subscriptions","organizations_url":"https://api.github.com/users/mpbarnwell/orgs","repos_url":"https://api.github.com/users/mpbarnwell/repos","events_url":"https://api.github.com/users/mpbarnwell/events{/privacy}","received_events_url":"https://api.github.com/users/mpbarnwell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-16T15:31:19Z","updated_at":"2015-12-16T20:54:13Z","closed_at":null,"body":"I'm trying to figure out the best way of accessing singleton services in from a websocket endpoint class without resorting to static fields/methods. I was expecting to be able to use @Inject since it's managed by jersey but it's not working.\r\n\r\nI've thrown together an example project using @Inject on both a regular Dropwizard resource and a websocket endpoint, see https://github.com/mpbarnwell/dropwizard-websockets-test \r\n\r\nAs expected, using curl against the Dropwizard resource returns the service's hash code:\r\n\r\n```\r\ncurl -X GET http://localhost:8080/test\r\n1979257230\r\n```\r\n\r\nBut running against the webservice endpoint produces a NPE.\r\n\r\n```\r\ncurl 'http://localhost:8080/ws' -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: Yx2RoE1qwByK+r3fO25+/Q==' -H 'Upgrade: websocket' -H 'Connection: Upgrade'\r\n��NullPointerException\r\n```"},"comment":{"url":"https://api.github.com/repos/LivePersonInc/dropwizard-websockets/issues/comments/165241286","html_url":"https://github.com/LivePersonInc/dropwizard-websockets/issues/2#issuecomment-165241286","issue_url":"https://api.github.com/repos/LivePersonInc/dropwizard-websockets/issues/2","id":165241286,"user":{"login":"mpbarnwell","id":6087327,"avatar_url":"https://avatars.githubusercontent.com/u/6087327?v=3","gravatar_id":"","url":"https://api.github.com/users/mpbarnwell","html_url":"https://github.com/mpbarnwell","followers_url":"https://api.github.com/users/mpbarnwell/followers","following_url":"https://api.github.com/users/mpbarnwell/following{/other_user}","gists_url":"https://api.github.com/users/mpbarnwell/gists{/gist_id}","starred_url":"https://api.github.com/users/mpbarnwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpbarnwell/subscriptions","organizations_url":"https://api.github.com/users/mpbarnwell/orgs","repos_url":"https://api.github.com/users/mpbarnwell/repos","events_url":"https://api.github.com/users/mpbarnwell/events{/privacy}","received_events_url":"https://api.github.com/users/mpbarnwell/received_events","type":"User","site_admin":false},"created_at":"2015-12-16T20:54:13Z","updated_at":"2015-12-16T20:54:13Z","body":"I spent a little more time on this, this would achieve the result I'm expecting, of course the environment isn't available during initialization, so it doesn't actually work. \r\n\r\n```java\r\n        websocket.addEndpoint(ServerEndpointConfig.Builder.create(DeviceRegistrationHandler.class, \"/device\").configurator(new BasicServerEndpointConfigurator() {\r\n            @Override\r\n            public <T> T getEndpointInstance(Class<T> clazz)\r\n                    throws InstantiationException {\r\n                ServiceLocator sl = ((ServletContainer) environment.getJerseyServletContainer()).getApplicationHandler().getServiceLocator();\r\n                return sl.createAndInitialize(clazz);\r\n            }\r\n        }).build());\r\n```\r\n\r\nIt looks like this is a wider symptom of JSR-356, even Spring has to use a static method to lookup the context, https://github.com/spring-projects/spring-framework/blob/master/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/SpringConfigurator.java\r\n\r\nProbably best to close this issue but I would appreciate any other suggestions on how to 'wire up' endpoints with services."}}