• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

explicitly sending http 200ok message from servlet

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Problem: I am Receiving a post message to my servlet from a thirdparty server and then it is Expecting 200ok response from servlet.But i am executing my logic in dopost method before my logic execution completes the timeout happens from thirdparty server for post message.
So now i want to send the Http 200ok immediately once i receive a post message and then start executing my logic.How can i send a Http 200ok message.

Thanks,
-Ramprasad.G.K.
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ram,

You can explicitly set status of the response using HttpServletResponse setStatus() , in this case (200) setStatus(HttpServletResponse.SC_OK) . But i don't know what is the logic processing that is carried out after that and whether that impacts the response status. If your question is just how to set status , then here it is setStatus(HttpServletResponse.SC_OK)
 
ram prasadgk
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bala,

Yes i agree with the answer but setStatus only sets the type of http message but does not trigger the response message[Correct me if i am wrong]
I want to send a response to the POST message as 200 ok and then start executing a logic.
Regarding my logic it contains some database related operations and then triggers the GET message to the thirdparty server.
I Hope i am clear with my question.

Thanks,
-Ramprasad
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think there is a more fundamental design issue here. If you send a 200 to the other server before you finish processing and then your processing fails, the other server would have falsely got a positive response. You need to find ways to speed up your processing or increase the timeout for the other server.

If you are ok with the false positive then this is fundamentally an asynchronous call. Your servlet can just put a message is something like a JMS queue and reply back with a 200OK to the other server. You will then have some kind of a message listener or MDB to process this JMS message. There are other ways to process anything asynchronously - such as EJB timers, Quartz timers or your own thread pool.

PS: Do not create your own threads in servlets. If you really must, then use a threadpool such as the one provided by Executors.newFixedThreadPoolExecutor() on JDK 5+
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Examine the "Long Running Process" example here, for a more approriate way to deal with long-running processes.
 
ram prasadgk
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks All for your Solutions.It was really helpfull.
 
The moustache of a titan! The ad of a flea:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic