Open alexweirig opened 7 years ago
One can workaround this if you get a ServiceReference from the OSGi context in the init method of the UI.
Hi Alex,
The osgi-integration
bundle tracks VaadinServlet
registrations, and sets the path to the resources (themes and widgetsets) so that the servlet can work in Karaf.
Since you have control of the application servlet which extends VaadinServlet
you can override createServletService and use something similar to OsgiVaadinPortletService
(extend VaadinServletService instead). Add an OsgiUIProvider (you can copy and adapt the class with the same name from vaadin-liferay-integration
.
If your UI has a service scope you should be getting a new copy with the dependencies injected. Providing this kind of utility classes is an option we could look at.
Hi Mirjan,
thanks for the update. That sounds like a very good approach to solve the problem.
Currently I'm working on creating a prototype of the application using a plain Vaadin app. I feel that my OSGi architecture is mature enough so I'm focussing on how the application should look like. In order to do this, I don't necessarily need OSGi.
My expectation is that I hopefully finish the prototype by the end of this year or during January.
We would then start implementing the application using OSGi.
Regards,
Alex
Hi Mirjan,
I've tried to implement what you recommended in you previous post, but at the end of day I ended up having to create the following classes: 1) OsgiServletUIServiceTrackerCustomizer 2) OsgiUIProvider 3) OsgiVaadinServlet 4) OsgiVaadinServletRegistration 5) OsgiVaadinServletService 6) VaadinServletProvider
Yet, with all this in place, I still don't get the OsgiUIProvider to be executed. So I guess I must be missing something in the flow of the different classes between the UI and the servlet.
Can I send you my sample project and could you please have a look at the code?
Many thanks in advance,
Alex
Hi Alex, Please attach your project here. I'll try to find some time for this task over the next month and see if my idea could be some sort of PoC that would fulfill your requirements.
BR, Mirjan
Hi Mirjan,
thank you very much.
BTW: If there is anything useful in my code, please consider it a contribution. You're free to use it and integrate it into the framework.
Regards,
Alex
Thanks Alex!
I'll check as soon as I have time (after this week) and let you know. If anything is included I'll make sure to use your name as the commit author. Thanks for putting the effort!
BR, Mirjan
Hi Mirjan,
I had a couple of hours to spend on my code so I went ahead and modified it a little bit and now it seems to sometimes work a little better.
Unfortunately I still get a
javax.servlet.ServletException: com.vaadin.server.ServiceException: com.vaadin.server.ServiceException: com.example.myosgiapplication.MyUI could not be loaded
message when I try to display the UI for the first time, when I then refresh the page, the UI is displayed and the DS (LogService) is available in the UI.
So some improvement over the initial code but not perfect yet.
Regards,
Alex
Sorry for not being active on this. We have discussed the OSGi support we have and we consider this to be a new feature for now, unless we can point out something that is broken in the current implementation that makes it impossible to get the custom UIProvider to be used properly.
Hi Pekka,
thank you very much for the update.
Could you then please provide me some sample code that uses such a custom UIProvider with the current OSGi support in place.
Many thanks in advance
Schéin Gréiss, Mit freundlichen Grüßen, Meilleures salutations, Kind regards, Alex Weirig Responsable Technique
Ville de Luxembourg - Centre Technolink 2, rue Charles de Tornaco L - 2623 LUXEMBOURG [ mailto:alex.weirig@technolink.lu | alex.weirig@technolink.lu ]
Tel: +352 4796 - 6127 Fax: +352 42 88 81 [ http://www.technolink.lu/ | www.technolink.lu ]
From: "Pekka Hyvönen" notifications@github.com To: "vaadin/framework" framework@noreply.github.com Cc: "Alex Weirig" alex.weirig@technolink.lu, "Author" author@noreply.github.com Sent: Tuesday, December 19, 2017 12:23:40 PM Subject: Re: [vaadin/framework] OSGi DS @Reference not working in OSGi UI (#10200)
Sorry for not being active on this. We have discussed the OSGi support we have and we consider this to be a new feature for now, unless we can point out something that is broken in the current implementation that makes it impossible to get the custom UIProvider to be used properly.
— You are receiving this because you authored the thread. Reply to this email directly, [ https://github.com/vaadin/framework/issues/10200#issuecomment-352720834 | view it on GitHub ] , or [ https://github.com/notifications/unsubscribe-auth/ADsklT0YgHehaneGleafQyEpFhRwKZiwks5tB5y7gaJpZM4P9V0F | mute the thread ] . |
---|
This email was Anti Virus checked by SOPHOS UTM
Hi Alex,
I'll try to do that for you when I find some time, but this is not related to the team responsible for the development of the framework.
BR, Mirjan
Hello Mirjan,
do you know when your fix will make it into the framework?
Kind regards,
Alex
Hello,
I'm using 8.1.5 and want to create an OSGi UI (not portlet). Unfortunately in the UI there seems to be the same problem as there was in portlet when using @Reference to inject OSGi DS services into the UI
When the UI bundle is activated the reference to the service gets correctly injected in the UI instance, unfortunately when the UI is displayed, the UIProvider seems to create a new instance of the UI and thus all references are lost.
Here the flow ...
setting testService = test.impl.TestServiceImpl@8508b80 com.example.myapplication.MyUI@79405478
in activate test.impl.TestServiceImpl@8508b80 com.example.myapplication.MyUI@79405478
all this happens on the same UI instance
@PreserveOnRefresh doesn't seem to work because I suppose it only acts on the refresh not on the first init.
OSGi injects the service before the new UI instance gets actually created by the UIProvider.
In portlets the solution was to support the ServiceScope.PROTOTYPE in the OsgiUiProvider.
Regards,
Alex