Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>it seems i finally figured out the cause that makes my play app so fragile and giving random errors:</p> <p>i was implementing the Registration process as a "play module". I used the registration module from book <a href="http://www.packtpub.com/play-framework-cookbook/book" rel="nofollow">"playframework cook book"</a> (the source code of this module is included below this answer)</p> <p>using this registration module seems to have made play unstable maybe because it conflicts with other play modules like crud module. So the solution i removed the dependency for the above-mentioned registration module. and re-implement registration process in play controllers actions instead. after doing that i noticed the app becomes once again stable and i no more get these infernal errors.</p> <p>the question why does the registration module described in book above make play so fragile and unstable? the src code of this registration module only makes use of two models classes User.java and Registration.java . maybe b/c User model is in someway tied to crud module this made play frequently confused and unstable? I still can't understand the real mechanism that made play be unstable when i added the above registration module to my dependencies.</p> <p>But anyway the solution seems to be removing this custom module altogether .</p> <pre class="lang-java prettyprint-override"><code>import play.Logger; import play.Play; import play.PlayPlugin; import play.classloading.ApplicationClasses.ApplicationClass; public class RegistrationPlugin extends PlayPlugin { private static boolean pluginActive = false; private static RegistrationService service; public void onApplicationStart() { ApplicationClass registrationService = Play.classes .getAssignableClasses(RegistrationService.class).get(0); if (registrationService == null) { Logger.error("Registration plugin disabled. No class implements RegistrationService interface"); } else { try { service = (RegistrationService) registrationService.javaClass .newInstance(); pluginActive = true; } catch (Exception e) { Logger.error(e, "Registration plugin disabled. Error when creating new instance"); } } } public void onEvent(String message, Object context) { boolean eventMatched = "JPASupport.objectPersisted".equals(message); if (pluginActive &amp;&amp; eventMatched &amp;&amp; service.isAllowedToExecute(context)) { service.createRegistration(context); service.triggerEmail(context); } } public static void confirm(Object uuid) { if (pluginActive) { service.confirm(uuid); } } } </code></pre> <hr> <pre class="lang-java prettyprint-override"><code> public interface RegistrationService { public void createRegistration(Object context); public void triggerEmail(Object context); public boolean isAllowedToExecute(Object context); public void confirm(Object context); </code></pre> <h2> }</h2> <pre class="lang-java prettyprint-override"><code>package service; public class RegistrationServiceImpl implements RegistrationService { @Override public void createRegistration(Object context) { if (context instanceof User) { System.out.println("createRegistration() called"); User user = (User) context; RegistrationSession r = new RegistrationSession(); r.uuid = UUID.randomUUID().toString().replaceAll("-", ""); r.user = user; r.save(); // System.out.println(RegistrationSession.findAll()); } } @Override public void triggerEmail(Object context) { if (context instanceof User) { System.out.println("triggerEmail() called"); User user = (User) context; RegistrationSession signUp = RegistrationSession.find("byUser", user).first(); MailNotifier.confirmation(signUp); } } @Override public boolean isAllowedToExecute(Object context) { if (context instanceof User) { System.out.println("isAllowedToExecute() called"); User user = (User) context; return !user.active; } return false; } @Override public void confirm(Object context) { if (context != null) { System.out.println("confirm() called"); User user = null; final String email = Params.current().get("email"); final String status = Params.current().get("status"); /** System.out.print("status="); System.out.println(status); * System.out.println(context.toString()); * System.out.print("Registration="); System.out.println(r); */ RegistrationSession r = RegistrationSession.find("byUuid", context.toString()).first(); if (email == null || email.isEmpty() || status == null || status.isEmpty()) { RenderArgs.current().put("activationFail", "registration.activationFail"); } else if (r == null &amp;&amp; User.getUserByEmail(email) == null) { RenderArgs.current().put("activationFail", "registration.activationFail"); } else if (r == null &amp;&amp; User.getUserByEmail(email) != null &amp;&amp; User.getUserByEmail(email).active) { RenderArgs.current().put("alreadyRegistered", "registration.alreadyRegistered"); } else if (r != null) { user = r.user; if (User.getUserByEmail(email) != null &amp;&amp; !user.active &amp;&amp; status.equals("pending")) { RenderArgs.current().put("pending", "registration.pending"); RenderArgs.current().put("email", user.email); } else if (User.getUserByEmail(email) != null &amp;&amp; !user.active &amp;&amp; status.equals("confirm")) { user.active = true; user.save(); RenderArgs.current() .put("verified", "registration.success"); // delete registration session object r.delete(); } else { if (user != null &amp;&amp; user.active) { RenderArgs.current().put("alreadyRegistered", "registration.alreadyRegistered"); } // todo : when should we make this confirm invalid?! else if (user == null) { RenderArgs.current().put("activationFail", "registration.activationFail"); } } } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload