Injecting blueprint OSGi service into JSF/PrimeFaces bean - jsf

I have a project built on top OSGi and Karaf server. For dependency injection we are using Aries Blueprint.
The main part of the project is a Apache Camel routes and integration things, but now I need to create some maintenance web interface.
So I give a try to JSF - PrimeFaces implementation. I was able to create some demo, which works in OSGi under Karaf, that's ok.
Now I'd like to know if it's possible to use Blueprint here, to reference some already existing OSGi services we have and inject the service into JSF Bean, so we can benefit from already written code.
Can you help me, please?

We solved this in the following way:
We created a listener that:
Creates a ServiceTracker that tracks the BlueprintContainer service attached to the same bundle
Puts the servicetracker into the ServletContext attributes
We created an ELResolver that uses this ServiceTracker and if there is a BlueprintContainer available it uses the getComponentInstance of that to get the value
The listener opens the servicetracer during application initialization and closes it during application destroy
Our listener class: https://source.everit.biz/svn/everit-util/trunk/core/src/main/java/org/everit/util/core/servlet/ServiceLoaderListener.java
Our EL resolver class: https://source.everit.biz/svn/everit-util/trunk/core/src/main/java/org/everit/util/core/el/OsgiELResolver.java
User/pass: guest/guest
After you registered your custom el-resolver all el-expressions will be evaluated in the way that id-s of component instances will be searched inside the blueprint container. In case you say that you have a bean-property in your faces-config.xml with the value #{myComponent} it will be searched inside the BlueprintContainer.

Related

Customize Controller from commercewebservices in SAP Commerce Cloud

From what I understand, from SAP Commerce Cloud 2005 onward the way to customize the REST-endpoints within SAP Commerce Cloud for Spartacus is to use commercewebservices (non-template) and then add own occ-extensions with your REST-endpoints.
That works fine for new endpoints, but what if I want to customize an existing controller from within commercewebservices? Since I am not using the template anymore commercewebservices cannot be modified anymore. I don't see a way how I could for example customize de.hybris.platform.commercewebservices.core.v2.controller.CartsController.
Swapping out commercewebservices with your own extension generated from the template does not work since multiple OOTB (e.g. cmsocc) extensions depend on commercewebservices hence it will always be loaded and clash with our own extension derived from commercewebservices.
Customizing commercewebservices with an addOn also does not solve the problem since, as I understand, it is not possible to add your own controller and bind it to the a url-pattern already used from a controller within commercewebservices
If you want to override an existing API endpoint (CartsController in our case), you can do so with the #RequestMappingOverride annotation.
Using this annotation, you can "shadow" the existing request mapping of the out-of-the-box controller with your custom controller in your own OCC extension.
You can find more details and an example here:
Overriding the REST API [help.sap.com]
EDIT
And let's not forget:
All of the action happens in the facades anyway, and you can also extend the API responses without overriding the Controller using the WsDTO concept plus additional converters. (see Extending Data Objects[help.sap.com] for more details)
Thanks for the response.
The annotation RequestMappingOverride works fine. There is one problem with this approach, lets assume I do following:
Introduce an new called MyController extending the CartsController
Override a single method and annotated this method with RequestMappingOverride
Starting up the system I do get now ambiguous mappings on all mappings of CartsController which I did not override
The reason is, I have now two Controllers registered with the same mappings. The CartsController and MyController which inherits all the methods which are not overriden from CartsController. The only solution I found is to override every single method of the CartsController, annotate all methods with RequestMappingOverride and then just do a super call. That is a bit clumsy and leads to a lot of boilerplate code. I wish the annoation RequestMappingOverride would work on class-level rather than only on method level

How to retrieve post data, validate it in controller and save it in database using GORM in Micronaut?

I come from Grails background and have recently started a project in Micronaut using GORM.
I tried to find required information in documentation but its not clear how we retrieve post data in controller, validate it similar to Command Objects offered in Grails and save it into database using interface service provided in documentation
PS : I know I can map every field to action argument in controller, and also declare a interface method specifying each argument as property but that does not seems right thing to do as my domain class has so many properties.
Making the action #Transactional or any method would work for saving data as far as I know but I want to know the proper way in Micronaut.
My requirement is simple, save post data in database using GORM in Micronaut.
If I were you I would look back at the documentation, sections 6.4 to 6.11:
https://docs.micronaut.io/snapshot/guide/index.html#binding
https://docs.micronaut.io/snapshot/guide/index.html#datavalidation
http://hibernate.org/validator/
Micronaut is very annotation based, unlike Grails which uses convention over configuration. However in Grails 4, Micronaut will toke over the application context, giving you some of the benefits of Micronaut, but still maintaining the convention over configuration.

How to listen on a stateless POST request and set JSF managed bean properties

I have a Java-EE application that works with JSF (ManagedBean, ManagedProperty, ect ...) and Spring framework. I need to be able to retrieve data via a javascript form sent from an external website. I have opened the rights to authorize the CORS (Cross Origin or Cross Domain).
I would like to know what is the best way to grab an external form with JSF so that it is processed by my ManagedBean.
To make my question more explicit I made a diagram
==============
EDIT
The application works with JSF, I'm looking for a way to retrieve data (from a Javascript form on an external site) in a ManagedBean under JSF. I tried to retrieve this data by creating a Java-EE standard servlet and using the doPost ... methods of HttpServlet. But this solution does not work (this was the subject of my previous question on S.O). Several people told me that in a web application do not mix Java-EE standard and JSF, it is either Servlet or JSF. I made a diagram (above) explaining quickly what I am trying to do.
To recap: I would like to retrieve data from an external website (via a Javascript form) in the ManagedBean of my application.
==============
I've already tried with a standard Java-EE servlet but it's not the right way. Indeed, with a standard servlet I can recover the data from the form but I can not access the ManagedBean. I must therefore have abandoned this hypothesis.
I did not find a similar question about Stackoverflow, If necessary I can give more indications.
Thank you for your help.

How to use CDI Conversation Filter in JSF2.2 Application

In my JSF 2.2 bases application I created a wizard which is based on #ConversationScope. To deal with errors I added CDI Conversation Filter to my web.xml.
My first question is about the right url-pattern for the filter-mapping. My Wizard runs behind the url /report/*. If I use this as pattern, all other pages throw the following exception:
javax.servlet.ServletException: A request must be associated with the context in order to load the known conversations
So, i had to use "/*" as pattern, which worked fine so far.
But now, I want to integrate container-managed security. When requesting the restricted resource, the mentioned error is thrown, when redirecting to login-page.
Does anybody know, how to solve that?
Thanks in advance.

JSF Duplicate Id issue in Alfresco webclient

I am using myfaces 1.1.8 and Alfresco 3.3.5
Even after giving id for all the JSF component in browse.jsp page i am facing duplicate id exception.
"java.lang.IllegalStateException: duplicate Id for a component browse:browse-col9"
This id is not repeated anywhere still it gives duplicate exception. Exception comes randomly.
Please let me know how can i resolve this issue.
This can happen if you've bound the component to a session or application scoped bean using binding and the view where the component is located is subject to dynamic changes (when components are dynamically added/removed).
You would then need to bind it to a request scoped bean instead, or to look for an alternative way for the binding or the dynamic nature of the view.

Resources