Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Spring: Post request not reaching controller class

Posted on 2014-01-28
12
Medium Priority
?
2,269 Views
Last Modified: 2014-03-04
I am developing my first sample spring based project. Following is an excerpt from my dispatcher-servlet.xml .

<mvc:view-controller path="" view-name="test" />
<!-- location to scan for controllers -->
<context:component-scan base-package="com.test.demo.student.controller" />

Open in new window


I try to do a post to the following url, but it never seem to reach the corresponding controller class:

url:
http://localhost:8080/TestProject/student/retrieveDetails

Open in new window


@Controller
@RequestMapping("student")
public class StudentController {

private final Logger logger = Logger.getLogger(StudentController.class);

@Autowired
public StudentService studentService;

public void setStudentService(StudentService studentService) {
    this.studentService = studentService;
}


 @RequestMapping(value = "/retrieveDetails", method = RequestMethod.POST)
public @ResponseBody String retrieveDetails(@RequestBody RetrieveStudentRequestBo retrieveStudentRequestBo,HttpServletRequest req,HttpServletResponse res) {

    logger.info("Entering StudentController.retrieveDetails()" );

Open in new window


input for post

{"testID":"1"}

Open in new window


ERROR [400]
Bad Request 

Open in new window


is the response.

Why I get the 400 error though everything seem to be in place?
0
Comment
Question by:Sreejith22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 36

Expert Comment

by:mccarl
ID: 39816914
Is there any helpful error message in the logs (tomcat/stdout/etc) ?
0
 

Author Comment

by:Sreejith22
ID: 39816970
INFO: Server startup in 7059 ms

Open in new window


Beyond this, tomcat does not show any progress, though I perform some actions from the loaded page in jsp.

Also, should there be a project folder generated in webapps folder of tomcat, corresponding to my project? If yes, I am afraid, I do not have such a folder created.
0
 
LVL 36

Accepted Solution

by:
mccarl earned 1000 total points
ID: 39816991
Can you post the FULL log file (the lines before the "Server startup" line), so that I may see what is starting?

Also, should there be a project folder generated in webapps folder of tomcat
There should be a project folder "somewhere" but it might not be in the location that you are expecting/looking. When you install Tomcat, there is generally a folder created called "webapps" within the installation where Tomcat looks to 'Hot Deploy' applications while it is running. If your project folder was here, it would be started by the default configuration of Tomcat.

However, if you are developing in Eclipse (which I am assuming) and you "Run on Server..." within Eclipse, it starts Tomcat but with a different configuration than if you just start Tomcat manually. The Tomcat application files are obtained from the location where you installed it, but the configuration is taken from Eclispe's settings and the webapp that is launched with that Tomcat instance is located elsewhere on your machine. It's actually the path the I gave you in your previous question, ie...
D:\ielect_sw\ws_workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\

Open in new window

If you look in the above directory (assuming nothing too much has changed since that last question) then you should find your project's folder within.

If not, then the issue may well be that Tomcat isn't even loading your app (or Eclipse hasn't deployed it) and that will cause a 400 error.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 20

Assisted Solution

by:chaitu chaitu
chaitu chaitu earned 1000 total points
ID: 39817193
need to put dispatcher-servlet.xml.i think you are missing  <mvc:annotation-driven /> tag.

<context:component-scan base-package="com.test.demo.student.controller" />
    <mvc:annotation-driven />  
    <mvc:view-controller path="" view-name="test" />
0
 

Author Comment

by:Sreejith22
ID: 39817195
Can you post the FULL log file (the lines before the "Server startup" line), so that I may see what is starting?
Jan 29, 2014 9:54:21 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.7.0_10\bin;.
Jan 29, 2014 9:54:22 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StudentServices' did not find a matching property.
Jan 29, 2014 9:54:22 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jan 29, 2014 9:54:22 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jan 29, 2014 9:54:22 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1218 ms
Jan 29, 2014 9:54:22 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 29, 2014 9:54:22 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.33
Jan 29, 2014 9:54:27 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Jan 29, 2014 9:54:27 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Jan 29, 2014 9:54:29 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
Jan 29, 2014 9:54:29 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jan 29, 2014 9:54:29 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jan 29, 2014 9:54:29 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 7059 ms

Open in new window


I found the project folder in the path you mentioned. I deleted it and cleaned the project again. The project folder gets created , but only with the web inf folder and the class files inside that. Now when I run the project from eclipse, it says requested resource is not found.


Please advise.
0
 

Author Comment

by:Sreejith22
ID: 39817199
@chaituu

I have that tag in my dispatcher-servlet.xml
0
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 39817202
are you able to see your web application in tomcat/web-apps folder?if yes then can you see all jars in WEB-INF/lib folder.
0
 

Author Comment

by:Sreejith22
ID: 39817215
@chaituu - As mentioned in one of my replies above, I cannot see my web applicationin tomcat/web-apps folder.
0
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 39817348
in eclipse when you double click tomcat server you will see the image that you can see in the attached screen shot.check the server locations tab... and need to check tomcat installation and put the server path where tomcat is installed.
tomcat.xlsx
0
 

Author Comment

by:Sreejith22
ID: 39817564
resolved!! It was an issue with the syntax/camelcasing of the post json parameter. After hours of debugging, I could find that. Will post details soon and close it.
0
 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39817569
Have you added entries inside web.xml about Dispatcher Servlet?

For Example :-
  <servlet>
    <description>Reads Dispatcher-servlet.xml for Spring MVC Configurations</description>
    <display-name>MyDispatcher</display-name>
    <servlet-name>MyDispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>MyDispatcher</servlet-name>
    <url-pattern>*.action</url-pattern>
  </servlet-mapping>

So your url could be,
http://localhost:8080/TestProject/student/retrieveDetails.action
0
 
LVL 36

Expert Comment

by:mccarl
ID: 39819512
resolved!! It was an issue with the syntax/camelcasing of the post json parameter. After hours of debugging, I could find that. Will post details soon and close it.
Glad that you found that. Although I would still have expected a log message to be given in such cases, so you might want to double check that your logging is correctly setup so you don't miss this or similar issues in the future!
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question