This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Servlets and the fly likes Listener on URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Listener on URL" Watch "Listener on URL" New topic
Author

Listener on URL

George Carlson
Greenhorn

Joined: Aug 24, 2000
Posts: 15
Ok guys and gals, please be nice to me. This may seem like a newb question and it probably is, but here is my situation.

I need to write a servlet (or web service or whatever I need to write) that listens for xml code that will be streamed to it and then parses the xml and processes it.

In other words, the servlet (or jsp) just sits there and waits for an incoming request. Another server will call this jsp or servlet and pass it an xml stream. I'll input the stream and process it.

I know how to parse and process the xml. i just need to get started on writing the file that will listen and stream in the xml.

Hopefully this makes sense and somebody may be willing to help me out.

Thanks for the help
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2834
    
    9

Not sure if I am getting the requirement right. Are you trying to log or write processed XML to files on the server?

SCJP, SCWCD.
|Asking Good Questions|
Niranjan Aithal
Greenhorn

Joined: Mar 17, 2012
Posts: 6
Are you talking about controller servlet ?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17142
    
  27

All servlets listen. They're not continuously-executing processes, nor are they callable subroutines. They're modules that process requests routed to them by the webapp dispatcher.

In the case of processing an XML upload, you'd typically embed the XML in an HTTP POST request. You would then put the parsing/processing code in the servlet's doPost() method. The raw data stream is accessible via the request.getInputStream() method, although if you use a form with a file upload button, the data will instead usually be spooled to a temporary location that you would access.


An IDE is no substitute for an Intelligent Developer.
George Carlson
Greenhorn

Joined: Aug 24, 2000
Posts: 15
Tim Holloway wrote:All servlets listen. They're not continuously-executing processes, nor are they callable subroutines. They're modules that process requests routed to them by the webapp dispatcher.

In the case of processing an XML upload, you'd typically embed the XML in an HTTP POST request. You would then put the parsing/processing code in the servlet's doPost() method. The raw data stream is accessible via the request.getInputStream() method, although if you use a form with a file upload button, the data will instead usually be spooled to a temporary location that you would access.


Thanks. So, I don't need to do anything different if the servers are posting a stream from another server (possibly in another state or country). I've done a lot of servlet work, but I always call it from my local server.

Thanks again.
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19738
    
  10

That's right. When your servlet processes a request, it doesn't know or care where the request comes from or how it was produced or what was in the mind of the person who caused it to be produced.
George Carlson
Greenhorn

Joined: Aug 24, 2000
Posts: 15
Paul Clapham wrote:That's right. When your servlet processes a request, it doesn't know or care where the request comes from or how it was produced or what was in the mind of the person who caused it to be produced.


Great. Thanks for the help.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Listener on URL
 
It's not a secret anymore!