playframework - How to use Http.Context.current() in a Promise in Play? -
In Play Framework 2.2.2, I want to return the promise. However, I'm calling a function which is called Of course, because the promise is executed in another thread, he does not have access to Example: Yes, When someone is made to Therefore, they should campaign properly in the Your example code should work fine, for example. However, you need to make sure that when you call hp.contex. (Access needed variables currently logged in , JPA connection ...).
Http.Context.current () . Can I preserve it in the word, or should I manually restore it? Should I Use Another Pattern?
Public stable promise & lt; Results & gt; GetAvailableServices () {Return the new operation. Launch (new function 0 & lt; result & gt; () {@ Override public results apply) Throwshell {// Long Operation List & lt; Services & gt; data = buildResult (); // template // template // header for htp.context.current (). Args.get ("usermodel") returns the results. Need access (services_template.render (services));}}); }
is the HTTPProduction Contex that you need.
HttpExecutionContext , when used for later code execution of
HttpExecutionContext .
Http.Context threads.
getAvailableServices , it is available in the
HTP.Contax thread that is calling from you Are there. If you are not
htp.context while calling the method, then
httpexunecontax code
from that code. Contex will be unable to capture the thread and promote it when the promise
Function0 is implemented.
Comments
Post a Comment