• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
Ranch Hand
Posts: 198
  • 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: 1903
12
  • 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: 198
  • 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: 12027
257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, where did you declare response?
 
Sheriff
Posts: 21954
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: 198
  • 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: 198
  • 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.
 
Your mother was a hamster and your father was a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic