Writing Servlet in OSGi environment

thumbnail
Hamidul Islam, modified 7 Years ago. Regular Member Posts: 111 Join Date: 5/22/08 Recent Posts

Hi All,

Liferay 7 comes with OSGi capabilities. I am exploring especially the OSGi features in Liferay environment. As part of the exploration, I have written a sample Servlet and deployed it. Everything is working good as expected. The context of the servlet is store and the URL pattern of the servlet is myServlet. To access the servlet I need use the URL like this 

http://localhost:8080/o/store/myServlet

My question is why should I use slash o (i.e., /o)  to access the servlet. I believe this is nothing to do with OSGi. Does Liferay have something which reads /o and allows us to access the servlet? Can anyone help me to understand this?

 

Regards 

Hamidul Islam 

Author: www.proliferay.com 

thumbnail
Narsingh Pal, modified 7 Years ago. Junior Member Posts: 53 Join Date: 1/18/14 Recent Posts

Hi Hamidul,

You can see below  link.  It will give you some pointers 

https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html

 

You can refer following section 

 "140.2 Servlet Context entities and their relation"

 

Thanks and regards 

Narsingh pal 

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
Hamidul Islam:

My question is why should I use slash o (i.e., /o)  to access the servlet. I believe this is nothing to do with OSGi.

If you step back, Liferay still has the idea of virtual hosting, where you effectively mount a page to something resembling a context path (which is handled by VirtualHostFilter).

This effectively makes it a lot harder to add arbitrary paths, since you can't know in advance when page friendly URLs will conflict with OSGi servlet context paths (which translates to confusing errors at runtime, and Liferay has enough of those). So for simplicity, Liferay forces them all onto /o and added o to the list of layout.friendly.url.keywords.

Hamidul Islam:

Does Liferay have something which reads /o and allows us to access the servlet?

Kind of, it's actually the application server that is responsible for that piece, because it reads web.xml and discovers that Liferay's ModuleFrameworkServletAdapter is mapped mapped to /o. I might be missing a few steps, but I believe that implementation is waiting for HttpAdapter, which I believe is responsible for setting up the Equinox HttpServiceServlet, which makes everything work.