Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Writing Servlet in OSGi environment
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
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
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.