Announcement Announcement Module
Collapse
No announcement yet.
How can I develop a headless servlet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • A_Spring_Developer
    started a topic How can I develop a headless servlet

    How can I develop a headless servlet

    I hope this is the correct forum to ask this and the term headless describes what I want to do.

    I want to write an application that consists solely of JMS listeners, i.e. no SOAP/REST endpoints and no http servlet requests, that can run in a tomcat container.

    The application consists of a couple of parallel JMS listeners that handle requests for multiple clients and is intended to run as a permanent daemon. The clients send their requests and receive the results via activemq.

    The reason I want to deploy to a tomcat container is because it is very hard to write a well controlled daemon service using java.

    I have written the api which works perfectly well under JUnit and was pleasantly easy to do using the spring framework but I am completely lost as to how I deploy to tomcat using spring, as all examples I find for deploying to tomcat involve writing SOAP/REST or http servlets.

  • ponder.muse
    replied
    This question is a Tomcat question more than a Spring question. See http://stackoverflow.com/questions/1...ithout-servlet for some answers.

    Regards,
    PM

    Leave a comment:


  • ponder.muse
    replied
    Hello,

    I have deployed a headless SI webapp into an Apache Tomcat server (7.0.x) and I am using a ContextLoaderListener to bootstrap the configuration as described in this thread and it all works fine. However, I do not want my webapp to auto-start when the Tomcat server starts but instead start/stop it manually. The examples I see online all show using the
    Code:
    <servlet><load-on-startup>1</load-on-startup></servlet>
    option to tell Tomcat whether to auto-start a webapp but, my webapp does not include a servlet. Is there any other way of specifying this auto-start option for webapps with no servlets? Or would I need to use the servlet method to bootstrap the webapp instead?

    Regards,
    PM.

    Leave a comment:


  • A_Spring_Developer
    replied
    After a very long xmas break, I have now returned to this project.

    Thanks for the reply, I took the plunge and removed everything else except for the contextloaderlistener and the application now runs successfully in Tomcat as a headless service

    Sorry for the omission of the tags, I thought I had added them but that's what happens when you are writing a quick message as you walk out the door for a much needed xmas break.

    Leave a comment:


  • Marten Deinum
    replied
    Please use [ code][/code ] tags when posting code that way it remains readable..

    As mentioned you need the contextloaderlistener nothing else. I strongly suggest a read of the reference guide. Basically the only thing you need is something that loads your application context.

    Leave a comment:


  • A_Spring_Developer
    replied
    I started the project by copying a lot of stuff from an existing project and it already has the ContextLoaderListener configured in web.xml. The whole thing works as long as I code SOAP and REST endpoints but when I remove them from the code, tomcat starts complaining.

    I've been trying to get my head around this configuration and wondering if I need to remove the servlet and servlet-mapping configuration from web.xml as I am not running a servlet.

    Here's the web.xml I am using.

    <!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd" >

    <web-app>
    <display-name>myservice</display-name>
    <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>file://opt/services/myservice/log4j.xml</param-value>
    </context-param>
    <context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>myservice</param-value>
    </context-param>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
    <listener-class>org.springframework.web.util.Log4jConfigList ener</listener-class>
    </listener>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>
    org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    </servlet>
    <servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>
    org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/*</url-pattern>
    </servlet-mapping>
    </web-app>

    Leave a comment:


  • Marten Deinum
    replied
    Create configuration (you should already have this) (applicationContext.xml), add ContextLoaderListener to web.xml... Deploy... Go home, drink coffee...

    You could use a servlet (DispatcherServlet) instead of the ContextLoaderListener... The fact that there is a servlet doesn't mean you need to add soap or http or whatever... You need something that loads/bootstraps your configuration...

    Leave a comment:

Working...
X