Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC / Jetty 404 Eror - New to Spring MVC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC / Jetty 404 Eror - New to Spring MVC

    I am getting a 404 error when I try to access a Spring MVC @Controller. I need some help as I am new to Spring

    My web.xml file for the server is as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app 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"
    version="2.4">
    <display-name>Provider Validation CDAC Server Simulator</display-name>

    <distributable />
    <!-- ================================================== ====== -->
    <!-- Spring Configs -->
    <!-- context-param supplies application-wide initialization -->
    <!-- params to servlets/JSPs -->
    <!-- contextConfigLocation tells ContextLoaderListner listener -->
    <!-- servlet to load additional configuration into a -->
    <!-- Spring web application context -->
    <!-- ================================================== ====== -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    classpathrovider-validation-config-ws-server.xml
    <!-- classpathrovider-validation-config-security.xml -->
    <!-- classpathrovider-validation-config-mysql.xml -->
    </param-value>
    </context-param>
    <!-- ================================================== ======= -->
    <!-- Spring Context Listener -->
    <!-- Listeners notified when session/servlet context created -->
    <!-- ContextLoaderListener bootstrap listener, starts up -->
    <!-- XmlWebApplicationContext which initializes SpringFramework -->
    <!-- when application is loaded by servlet engine. Takes its -->
    <!-- configuration from XML documents -->
    <!-- ================================================== ======= -->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <!-- ================================================== ======== -->
    <!-- Spring MVC Configuration -->
    <!-- Declare Spring DispatcherServlet-a Spring front controller -->
    <!-- and indicate all URLs will be handled by DispatcherServlet -->
    <!-- ================================================== ========= -->
    <servlet>
    <servlet-name>SpringDispatcher</servlet-name>
    <servlet-class>
    org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>SpringDispatcher</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    <!-- ================================================== ======== -->
    <!-- Session Timeout to throw away session if not accessed -->
    <!-- set to 3 hours -->
    <!-- ================================================== ======== -->
    <session-config>
    <session-timeout>30</session-timeout>
    </session-config>

    My SpringDispatcher-servlet.xml file is as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc
    http://www.springframework.org/schem...ng-mvc-3.0.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <!-- ================================================== ====== -->
    <!-- Spring MVC DispatcherServlet loads Spring Application Context -->
    <!-- from this file -->
    <!-- ================================================== =========== -->

    <!-- ================================================== =========== -->
    <!-- Handle requests for static content (if needed) -->
    <!-- path must begin with /resources, -->
    <!-- serve content from resources folder: Commented out -->
    <!-- as required Spring 3.0.4 and there is a bug in that release -->
    <!-- that won't let the Jetty server start up without an error -->
    <!-- ================================================== =========== -->
    <!-- <mvc:resources mapping="/resources/**"
    location="/resources/" /> -->

    <!-- Flip on annotation-driven features so -->
    <!-- DefaultAnnotationHandlerMapping works -->
    <mvc:annotation-driven/>
    </beans>

    My controller class that I am trying to access is as follows:
    package gov.hhs.cms.ocsq.hospital.provider.validation.wscd ac.server;

    import gov.hhs.cms.ocsq.hospital.provider.validation.wscd ac.server.PropertiesReader;
    import gov.hhs.cms.ocsq.hospital.provider.validation.wscd ac.server.CreateHandshake;

    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMap ping;
    import org.springframework.web.bind.annotation.RequestMet hod;
    import org.springframework.web.bind.annotation.RequestBod y;
    import org.springframework.web.bind.annotation.ResponseBo dy;
    import org.springframework.web.bind.annotation.ResponseSt atus;

    import java.io.InputStream;
    import java.io.IOException;
    import java.util.LinkedHashMap;
    import java.util.Properties;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    // @Controller-annotated classes are registered as beans
    // Class-level Controller handles all requests starting with /pv
    @Controller
    @RequestMapping("/pv")
    public class CDACController
    {
    private static final Log logger = LogFactory.getLog(CDACController.class);
    private static String filename = "resources/handshakeSession.properties";
    Properties sessionProp;
    LinkedHashMap<String,Object> sessionHandshake;

    // @RequestMapping--handle /pv/session POST requests
    // @RequestBody--convert client JSON POST data to object via HTTP message converter
    // @ResponseBody--use HTTP message converter to convert response to JSON resource
    // Client specifies acceptable representation via Accept HTTP header
    // Content-Type header allows conversion of JSON session data into Java object
    // HTTP Response status determined by Properties File
    @RequestMapping(value="/session", method=RequestMethod.POST,
    headers = {"Accept=application/json",
    "Content-Type=application/json"})
    public @ResponseBody LinkedHashMap<String,Object> postSession (@RequestBody LinkedHashMap<String,Object> session,
    HttpServletResponse response){

    String sessionAcn = (String)session.get("ACN");
    String sessionToken = (String) session.get("token");
    String sessionDatetime = (String)session.get("date-time");
    logger.debug("CDAC Server--Session Event received: ACN=" + sessionAcn);
    logger.debug("CDAC Server--Session Event received: token=" + sessionToken);
    logger.debug("CDAC Server--Session Event received: date-time" + sessionDatetime);

    // get handshake "STATUS" value, HTTP Response status line "status code" value from a file to return to client

    PropertiesReader reader = new PropertiesReader();
    try {
    sessionProp = reader.loadProperties(filename);
    } catch (IOException e) {
    // file read failure, just use default values
    logger.debug("CDAC Server--File read failure, using default status values");
    Properties sessionProp = new Properties();
    sessionProp.setProperty("status","SUCCESS");
    sessionProp.setProperty("HTTPstatus","201");
    }
    sessionHandshake = CreateHandshake.buildHandshake (sessionToken,sessionProp.getProperty("status"),se ssionDatetime);

    // set the HTTP response from value in file in the HttpServletResponse object passed in to controller
    Integer httpStatus = Integer.valueOf(sessionProp.getProperty("HTTPstatu s"));
    response.setStatus(httpStatus);
    return sessionHandshake;
    }
    }

    Any help would greatly be appreciated.
    Carol
Working...
X