• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring and binary responses

 
Stu Thompson
Hooplehead
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have put together a simple HttpServlet that (on HTTP GET) interprets the query string, performs a little magic, and then returns binary data. It is a proof-of-concept prototype and works well.

Now I want to bring it into my Spring-based application properly. But I cannot seem to figure out how that is done! It seems like such a simple task, but my searches on "the google" have gotten me no where. Clearly I am missing a basic concept.

Could someone please point me in the correct direction?

Other potentially important details: Java 5, Spring 2, Hibernate 3, Tomcat 5.5.

tia,

Stu
 
Chris Stehno
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am assuming that your servlet adds the binary data to the response using getOutputStream(). If that is the case you can create a spring Controller that does the same thing. If your Controller does not return a ModelAndView object (null) no view will be rendered... it will trust that you have done something to the response if you wanted anything done.

Depending on what you are trying to do, you could also implement your own View/ViewResolver to write out the binary data... this is a better approach if you will have multiple controllers that need their response data sent in this manner.

The Spring documentation has very good examples around their MVC framework and Controllers.

Hope this helps.
 
Stu Thompson
Hooplehead
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chris Stehno:
I am assuming that your servlet adds the binary data to the response using getOutputStream(). If that is the case you can create a spring Controller that does the same thing. If your Controller does not return a ModelAndView object (null) no view will be rendered... it will trust that you have done something to the response if you wanted anything done.


Hi Chris,

My Spring application (Flash client remoting via AMF) does not utilize any Spring MVC stuff, so I plan to go with your first suggestion rather.

Correct, I am using getOutputStream(). Could you (or anyone reading this) please point me in the right direction regagarding "create a spring Controller that does the same thing"?

Thanks in advance and Happy New Year!

Stu
 
Stu Thompson
Hooplehead
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just in case somebody searches for this thread, I've figured out how to do it! The gory details are on http://static.springframework.org/spring/docs/2.0.x/reference/mvc.html . Here is what I did:

1) My servlet now...
  • extends org.springframework.web.servlet.mvc.AbstractController instead of javax.servlet.http.HttpServlet
  • implements handleRequestInternal(..) instread of doGet(..), which returns null. Everything else in my method is exactly the same.

  • 2) my web.xml defines a <servlet> with the class org.springframework.web.servlet.DispatcherServlet and has an appropriate <servlet-mapping> definition
    3) my spring app configuration file, {servlet-name}-servlet.xml, has two beans:
  • the first is for org.springframework.web.servlet.handler.SimpleUrlHandlerMapping which has a 'mappings' property configured to map URLs to my class below
  • the second is my custom AbstractController class


  • Hope this helps someone someday!

    Stu
    [ January 23, 2007: Message edited by: Stu Thompson ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic