spring based bundle in apache felix osgi - spring-mvc

I am working one POC where I want to create plugin based web application. Main application will have all the spring mvc context. Plugins can write spring controllers but they cannot have their own spring context file. What I want is when plugin is installed all its controller is scanned (plugins controller need to be in specific package so for that package component scan will be defined in parent context) and ready to use. I am able achieve the installation part however when I am trying to access bundle/plugin controller end point through rest call I get no mapping found error.
Has anyone tried something like this? It will be great if I can get reference to some example.
Thanks!!!

If you remove the spring part, I've already done this with
a) Apache Wicket and Pax Wicket
b) Vaadin
For a) you might want to look at the Apache Karaf WebConsole.
For b) take a look at this rather "old" showcase of mine.
Both of those showcases use either standard OSGi services or Blueprint for the services (http-services) and the discovery of new "web-components" or views.

Related

jax-rs url inside an ejb module

I created a tutorial that incorporates various components of J2EE in them. The app is an ear module that has an ejb project and a web project.
the project structure is
john-app
john-ear
john-ejb
john-web
the ejb project has a couple dao that perform basic crud operations using jpa. I'm trying to learn/understand jax-rs to gain a better understanding of json and handling json objects. the project is loosly based on
this project:
http://www.developer.com/java/creating-restful-web-services-with-jax-rs.html
so, i created my BookResource here and made it a stateless ejb. i have everything compiling and deploying without any obvious errors - other parts of the app work (the jpa stuff) but i can't get the jax-rs stuff to
work. i have a couple of"Books" that I created in my database and am wanting to test this by making a rest call through the browser.
so i deploy my .ear file in wildfly (v10) with no obvious errors, I see JNDI mappings for my EJB's...etc
initially, i'd like to be able to test this through my browser, but am not certain what url to use -- the class i have extending javax.ws.rs.core.Application has an application path of /rest and my
BookResource has a path of /library, and for getting all books from the library, the sub-resource is books. I've tried every combination of the url below,
http://localhost:8080/john-[app|ear|ejb|web]/rest/library/books
all to no avail. every call results in a 404 error, and the only time i got ANYTHING is when i tried john-web combination, it threw some ugly exception in the browser. so the questions is with a rest service living inside an ejb module within an ear, what should the url be given the above information. nothing i've tried
seems to work!??
I've not included any code samples to try and keep the explanation short -- i didn't want to include every java file in my little project, but can add anything as requested.
Thanks,
JG

How to integrate spring-security.xml file into spring boot ? using Annotation base only

I have searched and didn't find any helpful solution that's why i am going to post this question.
Actually i have spring boot project which is completely configure based upon 'Annotation'.
Now for some reason, i need to add spring-security into this project.
for that i am getting spring-security-XXX.xml file from other co-worker.
Now, i am thinking how can i wrote some Annotation which will automatically load that spring-serity-xxx.xml file into my current project environment without change any other part, so that i can achieve security feature as per spring-serity-xxx.xml file.
For example, #Configuration(classpath:spring-security-config.xml) something like, is it possible ?.
if it's possible then provide me completed list of configuration.
NOTE : security added to get OAuth integration.
Any Help Appreciate..!!
Use #ImportResource annotation.

A welcome message, that is pulled from a servlet that is configurable from the OSGi console

I am new to CQ5. I created a bundle that is configurable via the OSGi console. Now, I need the value that is configured on the console to be returned to my content page. I am not sure how to proceed with this. Looking for any tutorial or help. Thanks in advance.
Assuming the configured value is available via an OSGi service, you can access that service from java code using an #Reference SCR annotation with a suitable build setup to generate the corresponding OSGi metadata. You can also access OSGi services from scripts, in JSP that's done using sling.getService(YourService.class) in a script where you have called or its CQ equivalent.

Symfony2 where to place custom helper classes

I'm starting with a Symfony2 project. I know the framework basics but I have a question:
Where is the right place to pot those helper classes I create for help or for the business logic?
Max's answer is correct. However I question the path he recommends for your code.
The following classes and files have specific emplacements:
Service Container Extensions (belong in) DependencyInjection/
from http://symfony.com/doc/current/cookbook/bundles/best_practices.html
That says your Services should be placed in a folder called 'DependencyInjection', not 'Services'. In full, it should be src/Foo/BarBundle/DependencyInjection
I say this as someone that had the former and has just finished moving them all to the latter (!)
What #Adam says is wrong, you have to store your Dependency Injection Extensions in DependecyInjection directory, not the services itself. In the documentation says that you can store your (custom) business logic classes in any place you like.
http://symfony.com/doc/current/best_practices/business-logic.html
The best way to keep the business logic is create service to handle all the logic. So it will be in:
src/Foo/BarBundle/Service
and you need to call the service in the services.yml.
I recently did some small work on an existing Symfony2 project. As described by answer from Tuong Le, I created my Helper classes under the Helper directory of the bundle and class name with Helper suffix i.e. the helper class is located at:
src/MyBundle/Helper/MyUtilHelper.php
I can use MyUtilHelper class in my bundle without calling the service container i.e. I didn't need to call.
$container->get('my_util');
I don't really know whether there is some special config. in my setup; someone already got it setup and I was just adding new functionality.
You can create the custom classes under your Bundle, such as under a folder Helper/..
However, to use those helper in your code, you'll need to define those Helper(s) in your service description file (such as services.xml)... Then you can use $container->get('your_helper')->
According to official documentation - in particular - Symfony Best Practices - you should store your services in Utils folder under the src. I belive, that this is correct way regardless of whether you want or don't wont to make the functionality provided by services of your bundle available to other parts of application via Service Container. Furthermore, you can store helper classes in any place you consider suitable. Concerning #Adam Knowles and #PachinSV answers - they are not quite right because they do not answer your question - "Where is the right place to pot those helper classes I create for help or for the business logic?" or "Where to store classes which I want to register and use via Service Container" - but not where to put bundle Extension class - which main purpose is to provide information about configuration which should be automatically loaded from your bundle to apps Service Container during the process of booting the Kernel.

Securing JAX-RS in a bundle

I am creating a REST service in glassfish (which uses Jersey as the JAX-RS impl.). I want to deploy my service as an OSGI bundle which works fine, I add the "Web-ContextPath:" in the manifest and then use an annotated #javax.ws.rs.ApplicationPath application object. This all makes the service usable but then, I want to use container based security. I found I can use security contrains in a web.xml and then do the user-to-role mappings in sun-web.xml. That said, a OSGI bundle does not have either.
Is there a set of annotations and or parameters to the manifest where I can specify application roles, security constrains and role-user mappings (I think the latter can just be globally configured)?
Thanks!
Here's how I would try this:
Use a library that would automatically detect OSGi services with specific annotations, and translate them to REST resources. For Jersey, you could try this: https://github.com/hstaudacher/osgi-jax-rs-connector
Use OSGi embedded application server like jetty (or tomcat) which provides the OSGi HTTP Service implementation.
Configure Jetty/Tomcat. This should be easy now as the Jetty/Tomcat bundles can pick up configurations from the configuration area.
It would also save a lot of time to use Karaf which would do all the packaging related work for you, including providing features like embedded Jetty with externalized configurations, etc. But that's totally up to you.

Resources