• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

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

 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2265
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 14683
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, where did you declare response?
 
Sheriff
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic