I am developing a GWT Web application and I would like to integrate it within the Equinox OSGi container. In the application I have integrated the client/server packages and the Activator class into the server package. This Activator is quite simple with a single line in the start method printing a line (System.out.println). However, this line is never printed. I know the solution of OSGi declarative services in GWT, but the design of the whole platform is done by events, therefore, I need to access to the BundleContext and EventAdmin in the OSGi framework. For such purpose, I should implement the Activator class. However, it does not work... Coudl you help me, please?
Thank you very much in advance!!!
well, you can access BundleContext and EventAdmin using declarative services(DS) too... if you know that solution go ahead.
But if you activator is not being called means that you don't activate the bundle or you don't create a proper manifest.
Solved by using Spring Dynamic Modules and the injection of dependencies (IoD) feature provided by the framework. Now it gets the EventAdmin instance at the starting point and I can use the OSGi events for the communication from the GWT interface to the business logic.
Related
I am new to the OSGI world and could use some advice from the experts out there. My aim is to deploy a few servlets along with REST resources into a standard Karaf installation. I am planning to use Grizzly (w/Jersey) as the http container.
I am trying to figure out a way to create an eclipse project, in which I can compile my custom code, and deploy this code along with all dependencies such as Grizzly, Jersey, OSGI frameworks & bundles as a single archive into Karaf.
The end goal is to have a single deployable entity which includes all my code and the dependencies without needing to manually install dependencies in Karaf.
Is this possible or am I looking at it the wrong way? I have been reading up on OBR, features and KAR but not able to put the whole picture together as yet. What would be the best practice wrt achieving this objective?
Thanks!
To give you the general idea regarding embedding and launching a complete OSGi application, I suggest you check out chapter 13 on this book. It explains it using Equinox implementation but I hope the overall approach should look similar. If you follow through you will see that you can put all your bundles in a folder where the system will iterate through and install them.
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.
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.
I want to test an enterprise java bean (that should later be deployed to a JBoss server) using JUnit. But I don't exactly know how tools I can use for this. Plain JUnit fails because of the missing EJB Container and the caused lack of needed injections.
Googling a bit around lead me to a library called JBoss EJB embedded container, but it seems that it is obsolete. I also couldn't find any source or binary files to download.
So please help, what's a easy way to locally generate a "mock" container that is able to run the JUnit tests on the enterprise beans?
Greetings
Ben
I suggest you to have a look at Arquillian:
Arquillian enables you to test your business logic in a remote or embedded container. Alternatively, it can deploy an archive to the container so the test can interact as a remote client.
There is still a living Embedded JBoss AS. The Seam Framework also provides a testing environment with an embedded JBoss to run component tests (with TestNG) of your application.
openEJB is an embedded EJB container that's a perfect fit for unit testing EJBs. You can test them outside your normal app server. And, it's fast! And, it spins up fast! And, it has an Eclipse plugin for easy management! Gotta love it! It's been around for a while, there are plenty of tutorials on how to set it up and use it, so you shouldn't have problems with it.
You can use a EJB remote client in your JUnit program to test your EJB. Only drawback is that you have to have a running Application Server during testing.
Check out this blog entry for an example on how to invoke a EJB remotely.
It's been awhile, but I always wrote my EJBs as simple wrappers of POJOs. An interface would define the methods, and both the POJO and the EJB (session, of course) would implement that interface.
I could fully test the "business logic" of the POJOs without any container issues. Then if I had the server running, I could run the same tests against the session bean, just by testing against the client instead of the POJO...
Since I did not need the JNDI stuff (e.g. Cannot instantiate class: org.jnp.interfaces.NamingContextFactory) altogether in my DAO (ORM interface) tests it was enough for me to
include the hibernate jars in the classpath
remove/outcomment the <jta-data-source>...</jta-data-source> part in my persistence.xml
inject/assign your own entitymanagerfactory with Persistence.createEntityManagerFactory( "my-persistence-unit-name" )
Is it possible to use a Spring container for DI from inside Eclipse plugins?
I'm wondering because I know that Eclipse causes a lot of issues with class loading, looking up things within the plugin, etc.
The plugin is intended to be distributed as a JAR.
Yes but you will need Spring DM http://www.springsource.org/osgi
The answer is yes. You can use Spring DM, but you don't have to. It is probably better with it.
I did it without Spring DM and the main concern is class loading issues (not sure if Spring DM solves them, but I guess it should). Assuming you bundle the Spring JAR in a separate plugin with dependencies, you will need to load the context with the class loader of the invoking plugin .
Example:
Plugin A - your functional plugin
Plugin B - The Spring lib plugin exporting the spring packages
Plugin A depends on B. When plugin A starts, it will load the application context, when invoking this load, you will need to do something like:
Thread.currentThread().setContextClassLoader(PluginAActivator.class.getClassLoader())
So that the loading of the classes will happen under your own class loader. Now you can use a ClassPathXmlApplicationContext to load configuration XMLs from your class path.
One small note: the default ClassPathXmlApplicationContext validates your XMLs upon loading. You may want to disable it or point your XMLs to a local schema (rather than the standard Spring schema on springframework.org), otherwise, you will connect to the internet to download the schema files upon loading and working offline will fail.
do you have a code example for your post?
This would be great, since I´m hanging around with this for a while.
Cheers!