Starting jetty with spring xml as a background process/thread

Posted by compass on Stack Overflow See other posts from Stack Overflow or by compass
Published on 2012-11-25T08:28:35Z Indexed on 2012/11/26 5:04 UTC
Read the original article Hit count: 156

My goal is to set up a jetty test server and inject a custom servlet to test some REST classes in my project. I was able to launch the server with spring xml and run tests against that server. The issue I'm having is sometimes after the server started, the process stopped at the point before running the tests. It seems jetty didn't go to background. It works every time on my computer. But when I deployed to my CI server, it doesn't work. It also doesn't work when I'm on VPN. (Strange.)

The server should be completed initialized as when the tests stuck, I was able to access the server using a browser.

Here is my spring context xml: ....

<bean id="servletHolder" class="org.eclipse.jetty.servlet.ServletHolder">
    <constructor-arg ref="courseApiServlet"/>
</bean>

<bean id="servletHandler" class="org.eclipse.jetty.servlet.ServletContextHandler"/>

<!-- Adding the servlet holders to the handlers -->
<bean id="servletHandlerSetter" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject" ref="servletHandler"/>
    <property name="targetMethod" value="addServlet"/>
    <property name="arguments">
        <list>
            <ref bean="servletHolder"/>
            <value>/*</value>
        </list>
    </property>
</bean>

<bean id="httpTestServer" class="org.eclipse.jetty.server.Server" init-method="start" destroy-method="stop" depends-on="servletHandlerSetter">
    <property name="connectors">
        <list>
            <bean class="org.eclipse.jetty.server.nio.SelectChannelConnector">
                <property name="port" value="#{settings['webservice.server.port']}" />
            </bean>

        </list>
    </property>

    <property name="handler">
        <ref bean="servletHandler" />
    </property>
</bean>

Running latest Jetty 8.1.8 server and Spring 3.1.3. Any idea?

© Stack Overflow or respective owner

Related posts about spring

Related posts about testing