{"action":"created","issue":{"url":"https://api.github.com/repos/playframework/playframework/issues/6162","repository_url":"https://api.github.com/repos/playframework/playframework","labels_url":"https://api.github.com/repos/playframework/playframework/issues/6162/labels{/name}","comments_url":"https://api.github.com/repos/playframework/playframework/issues/6162/comments","events_url":"https://api.github.com/repos/playframework/playframework/issues/6162/events","html_url":"https://github.com/playframework/playframework/issues/6162","id":155111070,"number":6162,"title":"[2.4.x] Java Http Context not set when using EventSource","user":{"login":"gmethvin","id":171663,"avatar_url":"https://avatars.githubusercontent.com/u/171663?v=3","gravatar_id":"","url":"https://api.github.com/users/gmethvin","html_url":"https://github.com/gmethvin","followers_url":"https://api.github.com/users/gmethvin/followers","following_url":"https://api.github.com/users/gmethvin/following{/other_user}","gists_url":"https://api.github.com/users/gmethvin/gists{/gist_id}","starred_url":"https://api.github.com/users/gmethvin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gmethvin/subscriptions","organizations_url":"https://api.github.com/users/gmethvin/orgs","repos_url":"https://api.github.com/users/gmethvin/repos","events_url":"https://api.github.com/users/gmethvin/events{/privacy}","received_events_url":"https://api.github.com/users/gmethvin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-05-16T20:11:24Z","updated_at":"2016-05-18T04:15:28Z","closed_at":null,"body":"For example, the following code\r\n\r\n```java\r\npublic Result connect() {\r\n  return ok(EventSource.whenConnected(this::createClientConnection));\r\n}\r\n\r\n\r\npublic void createClientConnection(EventSource eventSource) {\r\n  System.out.println(\"in manager \" + play.mvc.Http.Context.current());\r\n}\r\n```\r\nshould provide some obvious way to set the HTTP context in the `createClientConnection` method."},"comment":{"url":"https://api.github.com/repos/playframework/playframework/issues/comments/219920964","html_url":"https://github.com/playframework/playframework/issues/6162#issuecomment-219920964","issue_url":"https://api.github.com/repos/playframework/playframework/issues/6162","id":219920964,"user":{"login":"wsargent","id":71236,"avatar_url":"https://avatars.githubusercontent.com/u/71236?v=3","gravatar_id":"","url":"https://api.github.com/users/wsargent","html_url":"https://github.com/wsargent","followers_url":"https://api.github.com/users/wsargent/followers","following_url":"https://api.github.com/users/wsargent/following{/other_user}","gists_url":"https://api.github.com/users/wsargent/gists{/gist_id}","starred_url":"https://api.github.com/users/wsargent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wsargent/subscriptions","organizations_url":"https://api.github.com/users/wsargent/orgs","repos_url":"https://api.github.com/users/wsargent/repos","events_url":"https://api.github.com/users/wsargent/events{/privacy}","received_events_url":"https://api.github.com/users/wsargent/received_events","type":"User","site_admin":false},"created_at":"2016-05-18T04:15:28Z","updated_at":"2016-05-18T04:15:28Z","body":"Same with 2.5.x:\r\n\r\n```\r\n    public Result streamClock() {\r\n        final Http.Context context = Http.Context.current();\r\n        final Source<EventSource.Event, ?> eventSource = getStringSource(context).map(EventSource.Event::event);\r\n        return ok().chunked(eventSource.via(EventSource.flow())).as(Http.MimeTypes.EVENT_STREAM);\r\n    }\r\n\r\n    default Source<String, ?> getStringSource(Http.Context context) {\r\n        play.Logger.info(\"context = \" + context);\r\n        final DateTimeFormatter df = DateTimeFormatter.ofPattern(\"HH mm ss\");\r\n        final Source<String, Cancellable> tickSource = Source.tick(Duration.Zero(), Duration.create(100, MILLISECONDS), \"TICK\");\r\n        return tickSource.map((tick) -> {\r\n            play.Logger.info(\"tick \" + tick + \", context = \" + context);\r\n\r\n            return df.format(ZonedDateTime.now());\r\n        });\r\n    }\r\n```"}}