This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Can the following Servlet be converted to a webservice call in spring framework?

 
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following servlet which is deployed on tomcat. And I can download a file by calling the servlet on the browser in the following manner :

https://myservername.com/DownloadFileFromServer/DownloadFileServlet?filename=Requested_files_80A50AD.zip&user=JACK

However, I want to convert this servlet into a webservice call in a spring framework. I already have a Spring framework with many GET and POST webservice end points, where I've defined controller, interface and implementation of the interface. Can I convert the following servlet into a webservice end point? How should I proceed? Just to show how my controller, DAOs etc are defined, I have pasted a sample GET request in the code below.



Sample GET requests in my controller:

GetCompanyNamesController.java




GetCompanyNamesDao.java



GetCompanyNamesDaoImpl.java
 
Ranch Foreman
Posts: 1922
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have a controller:

Here is an example:
https://howtodoinjava.com/spring-mvc/spring-mvc-download-file-controller-example/
 
Jack Tauson
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Himai Minh wrote:You can have a controller:

Here is an example:
https://howtodoinjava.com/spring-mvc/spring-mvc-download-file-controller-example/



Thanks. I tried doing it as you suggested as shown below. I don't see any errors, however, whenever Iam trying to call the end point, I'm getting 404 Not found for some reason.



Here's how I'm calling my file :

localhost:8080/MyFileDownloader/downloadFile?filename=file1_927204A50BB.zip&user=JACK


Another way I tried to convert it - just like I have been doing it using @RequestMapping annotation below, it's generating an error like this:




It's resulting in the following error in ECLIPSE  -`response cannot be resolved`. What am I doing wrong here?Eclipse doesn't complain in the first conversion approach mentioned above.



       
 
Saloon Keeper
Posts: 12128
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, where did you declare response?
 
Sheriff
Posts: 21971
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jack Tauson wrote:[I'm getting 404 Not found for some reason.

localhost:8080/MyFileDownloader/downloadFile?filename=file1_927204A50BB.zip&user=JACK


Of course that gives you a 404, the paths don't match. Your new implementation has a correctly matching path, but this one requires the URL to be localhost:8080/MyFileDownloader/downloadFile/file1_927204A50BB.zip/JACK.
 
Jack Tauson
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:

Jack Tauson wrote:[I'm getting 404 Not found for some reason.

localhost:8080/MyFileDownloader/downloadFile?filename=file1_927204A50BB.zip&user=JACK


Of course that gives you a 404, the paths don't match. Your new implementation has a correctly matching path, but this one requires the URL to be localhost:8080/MyFileDownloader/downloadFile/file1_927204A50BB.zip/JACK.



Thanks, that worked.
 
Jack Tauson
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Well, where did you declare response?



Sorry! My bad. I didn't notice that in the late evening hours of Sunday working on this.
    Bookmark Topic Watch Topic
  • New Topic