0

I develop simple servlet in Liferay. I see that its getting initialised ( verified by putting System.out in init() method). But when I post some data to the servlet, Its not getting invoked. How can this be debugged or what I need to add it to get it working.

Made servlet entry file : webapps/ROOT/WEB-INF/web.xml, The liferay has other custom webapps working.

   .....
   <servlet>
       <servlet-name>HealthCheckServelet</servlet-name>
       <servlet-class>com.test.HealthCheck</servlet-class>
       <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
       <servlet-name>HealthCheckServelet</servlet-name>
       <url-pattern>/health-check/*</url-pattern>
   </servlet-mapping>
   .......

The servlet is invoked using HTTP GET http://host-ip/health-check/temperature

iam
  • 53
  • 1
  • 1
  • 8
  • 1
    Apart from this (editing Liferay's web.xml) being bad style, unsupported and potentially hard to maintain: You're not telling us how you actually try to invoke this servlet. – Olaf Kock Apr 09 '16 at 07:04
  • thanks added the information. I missed that. Also do let me know how can i improve for that bad practice comment you mentioned above. – iam Apr 09 '16 at 07:09

1 Answers1

1

The invoking URL suggests that the health check has nothing to do with Liferay, rather with the server that your application is running on. I'd implement this in a separate web application totally independent of Liferay and deploy it on the same application server. This way you don't need to mess with Liferay's web.xml (which would need to be migrated should you update Liferay) and still gives you the same benefits. If you still need Liferay information in your health check, just use the API to get the data you need. Again - you gain far better maintainability.

The side effect of this is that you gain easy debugging in a tiny web application that doesn't need Liferay running. It'll be easy to post a MCVE here with all the code you're seeking advice on.

Also, by running outside of Liferay, you're not subject to any of the servlet filters that Liferay will apply to the request handling - your request might get caught in them already, who knows. It's a way too complicated solution for a simple problem.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • you answer is good. But for my case I need to extend some of the Liferay APIs(Filters ap) etc also. Putting it all in seprate webapp will be more of solving more problems I think. Hence right now I want to do it the way I describe. – iam Apr 09 '16 at 12:22
  • Can you show your minified servlet code? Only copy the relevant parts here. – Olaf Kock Apr 09 '16 at 19:58
  • sure, i will get back – iam Apr 11 '16 at 04:45