javaspringresthttpaction-mapping

restful service without MVC


I wanted to create a Restful service but when i tried the url "http..:8080/appanalytix-web/requirementservice/saverequirements" its not working

Myservice :

@Path("/requirementservice")
@Service("dimRequirementManager")
public class DimRequirementManagerImpl extends GenericManagerImpl<DimRequirement, Long> implements DimRequirementManager {
    DimRequirementDao dimRequirementDao;

    @Autowired
    public DimRequirementManagerImpl(DimRequirementDao dimRequirementDao) {
        super(dimRequirementDao);
        this.dimRequirementDao = dimRequirementDao;
    }
    @PUT
    @Path("/saverequirements")
    @Consumes("application/json")
    @Override
    public void saveAllDimRequirements(List<DimRequirement> requirementList) {
        dimRequirementDao.saveAllDimRequirements(requirementList);

    }
}

Is it necessary to have a dispatcher servlet for using the url ? And as this is my service how will the client pass a json String using HTTP PUT or POST

EDIT After adding servlet

<servlet>
        <servlet-name>dispatcher</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>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/restServices/*</url-pattern>
    </servlet-mapping>

i have added the servlet in web.xml and I tried the url http..:8080/appanalytix-web/restServices/requirementservice/saverequirements i am getting the following error

 ERROR [tomcat-http--17] Dispatcher.error(38) | Exception occurred during processing request: There is no Action mapped for namespace [/] and action name [restServices/requirementservice/saverequirements] associated with context path [/appanalytix-web].
There is no Action mapped for namespace [/] and action name [restServices/requirementservice/saverequirements] associated with context path [/appanalytix-web]. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:534)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter.doFilter(StrutsExecuteFilter.java:88)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
    at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter.doFilter(StrutsPrepareFilter.java:82)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.vxl.appanalytix.webapp.filter.RequestAuthentication.doFilter(RequestAuthentication.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

Solution

  • You must have a servlet, otherwise the @Path annotation does nothing. In the saveAllDimRequirements method - you'll have to use put because you have the @PUT annotation.