aspose file tools*
The moose likes Spring and the fly likes Spring servlet equivalent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring servlet equivalent" Watch "Spring servlet equivalent" New topic
Author

Spring servlet equivalent

Maciej Opala
Ranch Hand

Joined: Jul 18, 2011
Posts: 38
Hi,
There is a following scenario: several desktop applications are working with a remote, j2ee application. These client applications are sending requests (POST) to the server is handling these incoming requests and sending appropriate responses. Pure servlets are used to handle this task. I'd like to refactor this backend application to use spring framework and have no idea what is equivalent of the servlet in spring framework? What is the correct (or maybe appropriate way) to do it? Is it good idea to leave the servlets and just use CDI to inject beans to servlets or maybe spring has easy solution to this problem out-of-the-box? Any help would be greatly appreciated. There's no GUI in backend application (if this has any meaning).
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

What type of desktop apps. Swing? Web pages? Makes a bit of a difference.

But if you are describing remote procedure calls using HTTP at the protocol. Then you can look at Spring's HttpInvoker. Or if you are using Spring 3.x then I think REST Web Services are the way to go. (No Servlets)

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Kevin Cho
Greenhorn

Joined: Nov 12, 2008
Posts: 20
I think I understand your question and yes there is a spring version of Servlets. They are SpringMVC.

You can use the @Controller to define a class that'll handle your HTTP traffic. It sounds like you want the back-end app to be written in SpringMVC.
Maciej Opala
Ranch Hand

Joined: Jul 18, 2011
Posts: 38
I'm not sure how desktop applications can be written using web pages, but this isn't the problem. Clients are written in Adobe Flex and use HttpService to connect to backend. Requests and responses are sent in xml format.

Maybe SpringMVC is the solution but I'd like to emphasize that there's no view in the mentioned scenario - or maybe view is independent from the backend. AFAIK ModelAndView is returned after processing in SpringMVC - isn't it disturbing?

Do you know any sites/blogs with sample apps in the mentioned technologies?
Kevin Cho
Greenhorn

Joined: Nov 12, 2008
Posts: 20
It sounds more like Spring MVC is the right solution. Don't think Spring MVC just outputs HTML file. After all who says JSP's can't be in xml format? It's just an output that's formatted by YOU. For example, many use SpringMVC RESTful Web Service that spits out XML. I've seen some people taking Spring OXM where it serializes Java -> XML. Do not think that MVC only spits out HTML. It can output whatever you printed out to be. I did see a Spring Subproject called Spring Flash or something I forget... I don't know how that one well but you may want to peek if that's better. Still, I am confident that SpringMVC will work fine.
Kevin Cho
Greenhorn

Joined: Nov 12, 2008
Posts: 20
There is a view in your case, it's XML
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Maciej Opala wrote:I'm not sure how desktop applications can be written using web pages, but this isn't the problem. Clients are written in Adobe Flex and use HttpService to connect to backend. Requests and responses are sent in xml format.

Maybe SpringMVC is the solution but I'd like to emphasize that there's no view in the mentioned scenario - or maybe view is independent from the backend. AFAIK ModelAndView is returned after processing in SpringMVC - isn't it disturbing?

Do you know any sites/blogs with sample apps in the mentioned technologies?


And Spring Controller methods do not have to return ModelAndView.

Spring has a BlazeDS integration where you can just use your Pojo classes as backing beans in Flex forms.

Mark
Maciej Opala
Ranch Hand

Joined: Jul 18, 2011
Posts: 38
Thanks for your useful advice. I'm not sure if I really need to use SpringMVC only for substituting servlets. Also I wouldn't rather need to use BlazeDS at this time - nevertheless it was very useful piece of advice. What I've found is HttpRequestHandler and IMO this would be the best solution in this case.
Kevin Cho
Greenhorn

Joined: Nov 12, 2008
Posts: 20
I had no idea that even existed but now I know!

Still, I still recommend using Spring MVC Controller. Main reason being is the "testability"

void handleRequest(HttpServletRequest request, HttpServletResponse response)

With that signature it's really hard to execute JUnit for that. Also, you get convertion feature as well. For example if you pass URI "date=12-23-2011" then you can use the converter feature to "Date" directly w/o polluting your business logic. Of course, it's totally upto you but Spring MVC comes w/ Spring Core already and you can write JUnit tests against that. Just IMO.
Maciej Opala
Ranch Hand

Joined: Jul 18, 2011
Posts: 38
Do You have/know any materials/websites with Spring MVC sample projects?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring servlet equivalent