• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question for Spring gurus

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to test a REST Web Service I created in spring using Tomcat 8. Before I proceed I want to verify that I can run MVC applications in Tomcat, but I am having problems; in STS the application is called as "http://localhost:8080/mvc/". I exported a war file and deployed it in Tomcat (I can even see it in the webapps folder), but I am getting a 404 Error. I did some modifications; I added

to pom.xml which worked for me some time.
The web.xml is

I have no idea how how it was working without <welcome-file-list> (maybe it has an invisibe index.jsp), but copied home.jsp to under webapp. I find it interesting that in STS it works with "http://localhost:8080/mvc/", although the servlet-name is appServlet; I also tried with appServlet but got the same error.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm no guru but what does your /WEB-INF/spring/appServlet/servlet-context.xml look like?

By the way if your app is a web service app, why are you trying to access it using the browser?

Say your REST web service method is abc and mapped to http://localhost:8080/mvc/abc then you can use JMeter or similar tool to test your service.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have never examined /WEB-INF/spring/appServlet/servlet-context.xml all I know is that it is created by Spring and what I have read in the books.
As I explained the application I am working on is not a Webe Sevice application, it is an MVC web application.
 
Ranch Hand
Posts: 32
1
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure this will help you, but I worked on a project where we made both an MVC web application and a restful service run out of the same spring instance.  We just had a different controller for each.  You just map the controller methods to different URLs, and the service URL is not protected by Spring security.  The service URL instead validates the credentials that are sent as xml entries within each service request.
 
Matt Keller
Ranch Hand
Posts: 32
1
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what the controller for the json service looked like.  The Spring annotation @RequestBody does the magical parsing of the incoming json into your bean.

 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Matt; I am already differentiating between the MVC application and the REST application; they are actually different projects. I am using the MVC project only to learn how to run in Tomcat, which is the problem, because it is not working for me.
I created the rest application with your code with New->Spring Legacy Project, but I cannot find defaults for CustomerProfileService, BusinessEntityService and  BusinessEntityServicePayload. What's the correct way to create the application? I know how to create the client; how do i run the application in Tom cat with a WAR file? what URI do I use localhost:8080/???
 
Matt Keller
Ranch Hand
Posts: 32
1
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those 3 objects you mentioned are our custom code so you won't find them in your libraries.  The service objects are objects with methods that make database calls.  The payload objects are beans with setters which match the property names of the json object that is coming in.  So, say your json object has a property called firstName.  If that payload bean object has a setter called setFirstName then spring will parse the json object for you and send the value into the setter call. The beauty of it is that you don't have to write your own parser.  

As far as your tomcat/spring setup goes, that is complicated and really hard to assist you with through a forum like this.  However, I can lead you to a working instance of tomcat with Spring in it that you can download and use as your example.  Go to the URL in my footer in the message labeled WebRocketX.  It leads to the free SPA framework I am working on.  Go to the downloads page, accept the user agreement etc, and download the dynamic web application demo.  It contains a complete running copy of tomcat with spring, java, and jstl all wrapped up together.  Make sure you read the directions on how to get it running.  It is a windows version of tomcat btw.  If you like our SPA framework well then that is cool too. It is really the most basic configuration of tomcat with Spring you can have so its a good starting point for you for whatever you want to do with Spring and Tomcat.  I think almost all of the Spring configuration is in the xml files in the "web-inf" folder.  I hope this helps.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, Matt, I appreciate your help, but although I have insisted on Tomcat, what I am really trying to learn is how to deploy the WAR file of a REST application to any server. I am preparing myself for a future job.
 
Matt Keller
Ranch Hand
Posts: 32
1
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the controller code I pasted for you above is probably your best resource then.  To test your service there is a nice tool called REST Console.  It's a plug in for Chrome.
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic