This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

protocol independent content by the servlet  RSS feed

 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to generate protocol independent content by the servlet?
Normally ,we are using servlet for web application and using HTTP as a protocol, In case I want to use some other protocol to communicate with my system. How to write a servlet for that?
Eg: FTP.ZIP.. I have no idea about other protocols which is compatible with the servlet API.
Please explain with example .
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without the example, you need to extend the class
javax.servlet.GenericServlet
which defines a generic, protocol-independent servlet.
Also, a ServletRequest (which is an interface) object provides data including parameter name and values, attributes, and an input stream. Interfaces that extend ServletRequest can provide additional protocol-specific data.
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If anybody worked on this, could you please come up with example or code?
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony... If I wanted to do this, would that also mean I would have to write my own servlet container? I'm thinking Tomcat and most others only know how to understand HTTP requests.

So not only would you be writing protocol-independant servlets, you'd need to write a container as well?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What port do you plan to run this service on? Does it have to live on a server that also runs a web server?
Bill
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In all books on servlet, it is mentioned that GenericServlet could be used for protocol-independant services.
Out of my curiosity, If it is possible to use GenericServlet for this service, What is the procedure to be followed and how to implement it?
Nor have an idea about which port being used and neither have an idea about on which server it is being used to serve this sort of processes.
Books on servlets are neither provided the examples nor given the information like where and when it is being used.
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please try to explain with example,I mean port no,server,snippet to be used..
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thomas,

You're asking a fairly generic question and it's difficult to answer. The reason that the books don't show examples is that no one (yet) has bothered to write any Servlets that *aren't* being used to process HTTP requests.

It's difficult for a number of reasons.

protocol- If you're not using a well-known/well-defined protocol (HTTP, FTP, etc...) then you will have to write your own protocol. This is "down the wire" stuff. You can't use a browser to access your servlet. Browsers only do HTTP. You'd have to write up a little Java program that opens a socket and writes out data to a certain port on your...

container- I previously asked a question (so far unanswered) in this post about the container, but I'm pretty sure of the answer, the more I think of it. Tomcat, JBoss, Jetty, Resin, and all those other 'Servlet' containers understand HTTP on the way in. (they listen to port 80 and expect an HTTP formatted request). You would ALSO need to write your own servlet container to listen for your custom protocol mentioned above. It would also open a socket and listen for incoming requests. You will have to parse the 'request' and then forward it along in some fashion that makes sense to your customized servlet, which brings us to...

process/response - what kind of methods are you using? doGet(), doPost() are in HttpServlet, but these are methods that map to the HTTP GET and POST requests. Your protocol will have to have some other kind of command/content structure that will map to one or more methods.
What sort of output makes sense? HTML? XML? binary?

And is all that really worth it , for some academic exercise? The fact is the API *supports* this extensibility. But I'm not sure I'm up to the task of writing a client and a server just to extend GenericServlet.

On the other hand, maybe I'm wrong and it's way easier than all this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!