SecureSocial not using extended classes in Play! 2.1 project inside SBT Multi-Project - scala

Currently I have a Play! 2.1 project that is a sub-project of an SBT Multi-Project that is a front-end interface. The Play! project uses SecureSocial for typical authentication.
I will typically first start the SBT console to run my internal services locally in separate terminals. Finally I perform a play "project interface" "~run 9000" command in a new window to start up the interface sub-project using Play!. Problem is that on a fresh load (even after a clean) SecureSocial does not use my extended services and providers, and instead falls back on its own.
I will make a source change and reload, where SecureSocial will then use my own classes but suddenly starts throwing ClassCast exceptions using two of the same types, indicating there are conflicting ClassLoaders.
Is there a proper way to set this up so this doesn't happen? Thanks for your help!

Though not a real solution, I have in the meantime developed a workaround where I manually instantiate my own extended UserService class and bring the current Application instance into scope. I also wrote my own providers and SecureAction wrappers and designed them to use the custom UserService. It's a lot of extra code, but works around the problem.

Related

Play dependency injection reload

While developing a play framework (version 2.5.9) in Scala using the proposed dependency injection mechanism (https://www.playframework.com/documentation/2.5.x/ScalaDependencyInjection) using guice.
The application uses a custom module (published as jar and imported as external dependency) that has singleton classes (A,B) that uses other classes (1,2) injected with dependency injection mechanism.
The same injected classes (1,2) are used in the current application with the same method.
So for example:
Class A belonging to the custom module uses class 1 that is provided by dependency injection
Class C belonging to the application currently developed uses class 1 that is provided by dependency injection
This set up works fine until changes in the code during the development process triggers sbt to recompile and reload the application.
When this happens the application is restarted but the classes in the module are not provided with the new instances of injected classes (ex. 1) and so if for example class 1 is the database trait in play framework the instance provided in the module stop to work forcing the developer to restart the application from scratch.
Is there any way to prevent this from happening and having sbt/play "autoreload" the application in way that continue to work correctly.
I hope I've made my problem somehow clear :)

What Singletons does Play! Framework 2.4 provide out of the box?

Recently, Play! Framework 2.4 introduced us to the magic world of Dependency Injection and it's benefits but what application specific singletons are there? Digging through the documentation, I've found a couple already:
ActorSystem
Application
Configuration
Are there any more? Is there a central place where all these are listed?
Play 2.4 gets rid of global variables defined in Global, i.e. GlobalSettings, in Play 2.3 and before. A specific implementation of an abstraction will be used at run time via dependency injection. This makes your application more flexible and easier to test. Guice is one of good dependency injection frameworks.
This is an example of using Guice in Play 2.4 for dependency injection.
https://github.com/luongbalinh/play-mongo/blob/master/app/modules/DIBindingModule.scala
In addition, your configurations for different deployment environments, such as local, alpha, and production, are defined in different application.conf files respectively.

Where should JUnit specific Guice module be configured?

I'm going to start using dependency injection in my Eclipse plugin. My test plugin depends on the main one and should use different injection context. Production should work fine standalone (it should have its own injection context), but behave differently when used from tests (should use Junit's injection context).
How could I resolve the injector so that a different one is used in production and in tests?
I don't like the idea to somehow inject context manually in a static variable on test start. Is there a better way? Can extensions be somehow used for that?
I know that in e4 there is a solution for that, but I'm bound to Eclipse Indigo for now and could not find quickly how exactly is that done in latest version. A link to injector configuration with an ability to override in test infrastructure in e4 source is appreciated.
I wound up writing my own JUnit runner modeled largely after the Spring JUnit runner, but would highly recommend looking at the Jukito project now.
At this point I try to have one Guice module per feature, so I end up with one Guice module for test that installs the production module and overrides or binds any external dependencies. I keep that test module in a base test class along with the necessary annotation for the JUnit runner, which is very similar to the JukitoModule examples in the link above.

GWT blamed RequestFactory ValidationTool must be run on on sub module(project) when launching main project

GWT 2.5.0/Google Plugin for Eclipse/m2e/GWT-maven-plugin 2.5.0/Request Factory
I configs my project according to the GWT wiki working with maven and it works pretty well, but has some trouble in my sub-project.
Suppose i have two project A and B, A is a standard GWT project, B is sub-project and has one GWT module, it contains some common UI widgets and some common Entity proxies and RequestFactory, A project depends on B project through Maven dependency, and also in A's Module.gwt.xml, there is an inheritance on B module.
The problem is when i try to lauching A project using GPE, it blames:
The RequestFactory ValidationTool must be run for the … XXXRequestFactory type
where the XXXRequestFactory is in B project. I have to close project B in Eclipse, so it will not blames, this is cumbersome when i want to modify something in B project which used in A to see the changes, i have to close B then see the changes, then open B and made changes...
I wonder if there is a way to solve this problem so my life would be easier.
Thanks.
One more thing, i also use maven-processor-plugin and build-helper-maven-plugin in project B, and make sure the goals are run when i call maven install on B, but seems no help.
I also had this problem and here is the solution which fixed this issue. This answer assumes that you need to execute the GWT app in dev mode (as you mentioned you tried with gwt eclipse plugin)
You may already know this RequestFactory must validate the interfaces, domain types and proxies before execution. So you need to enable annotation processing for this which creates mapping data for server side components in addition to said validation. If this process not succeeded it will throw the error you mentioned.
You can enable the requestfactory validation for project B in the project properties. Go to compiler properties, enable annotation processing providing the path to requestfactory-apt.jar. After this when you compile the project you can see the .apt_generated in your project home dir containing mapping files. If you open one of them you can see generated mappings for your proxies.
Launch the application (project A in your case) and it should run without any errors
In Maven world you have to specify the dependency for this apt jar. In addition to this you might get compiler errors in those generated classes when doing mvn compile, to resolve that simply delete the content in .apt_generated.

Are there disadvantages to setting up unit or integration tests in Eclipse as a separate project?

I'm currently working on a project using Eclipse where the unit and integration tests are in one project that also contains the DAO and service layer, and there is another project that includes the Web interface. The Web interface contains the Spring configuration files, and instead of duplicating them for the tests in the DAO project, I want to reference the ones that already exist. However, as I started thinking about it, if this is possible, why not just move them into their own project completely and setup project dependencies. Has anyone done this, and do you have an example of this setup, or can you provide some roadblocks you encountered?
I went ahead with this approach, and it doesn't appear to be causing any issues so far. One of our projects has a (classpath) dependency on the other, but the third test project is able to manage that with some setup and configuration.