TV Nath
TV Nath

Reputation: 490

Spring integration in Rest API module

I have a rest API module developed using apache cxf. I want to have spring integration component to be run in the same module. This feature simply do a file polling every midnight, copies to some directories, and do some processing. I just need to know whether the spring-integration must be implemented in a different module or is it okay that I do in the same API module. I don't want the rest api service calls to be interrupted because of spring integration processes.

Upvotes: 0

Views: 256

Answers (1)

Gaurav Srivastav
Gaurav Srivastav

Reputation: 2551

You can use same module as it doesn't affect the current api service calls. As Spring has dispatcher servlet entry which will process the requests as per servlet mapping provided.I have changed the mapping slightly for CXF servlet to /services to handle api requests.

Dispatcher Servlet entry in web.xml.

  <web-app id="Expertwebindia" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        <display-name>Spring MVC Application</display-name>
        <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
        </servlet-mapping>
        </web-app>

Add the following servlet entry for Apache CXF for handling the api call.

 <servlet>
           <servlet-name>CXFServlet</servlet-name>
           <display-name>CXF Servlet</display-name>
        <servlet-class>
            org.apache.cxf.transport.servlet.CXFServlet
        </servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>

<servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
</servlet-mapping>

Learn more about JAX-WS web Services here

Upvotes: 1

Related Questions