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 hp.contex. (Access needed variables currently logged in , JPA connection ...).

Of course, because the promise is executed in another thread, he does not have access to Http.Context.current () . Can I preserve it in the word, or should I manually restore it? Should I Use Another Pattern?

Example:

  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));}}); }    

Yes, is the HTTPProduction Contex that you need.

When someone is made to HttpExecutionContext , when used for later code execution of HttpExecutionContext .

Therefore, they should campaign properly in the Http.Context threads.

Your example code should work fine, for example. However, you need to make sure that when you call 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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -