File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Protocols used by a Generic Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Protocols used by a Generic Servlet" Watch "Protocols used by a Generic Servlet" New topic
Author

Protocols used by a Generic Servlet

Ramesh Chandra
Greenhorn

Joined: Oct 20, 2005
Posts: 17
Hi all,

What are the protocols that are used by Generic Servlet and their purpose..

I know that a Generic Servlet can use all types of protocols....
I just wanna know which protocol is used for which purpose by an Generic Servlet..


THanks In Advance...........
Albin Joseph
Greenhorn

Joined: Jan 22, 2005
Posts: 21
Hi

You can use any type of protocol like FTP, SMTP with GenericServlet. But Sun is providing implementation only for HTTP protocol. So if you want to use FTP with servlet , then extend GenericServlet and provide the necessery implementations


Java source code examples | Java coding community.
Ramesh Chandra
Greenhorn

Joined: Oct 20, 2005
Posts: 17
Originally posted by Albin Joseph:
Hi

You can use any type of protocol like FTP, SMTP with GenericServlet. But Sun is providing implementation only for HTTP protocol. So if you want to use FTP with servlet , then extend GenericServlet and provide the necessery implementations



Hi Albin,
Thanks for ur post. I would like to know how do we provide implementations to a servlet that uses other than Http Protocol

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41096
    
  44
It's not just a matter of extending GenericServlet. The servlet container needs to handle the protocol as well, and I'm not aware of a container that handles anything but HTTP and HTTPS.


Ping & DNS - my free Android networking tools app
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You would need to learn all the ins and outs of that protocol and build a servlet container to handle it.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ramesh Chandra
Greenhorn

Joined: Oct 20, 2005
Posts: 17
Originally posted by Ben Souther:
You would need to learn all the ins and outs of that protocol and build a servlet container to handle it.


Hi Ben,
if we take for a instance...
For implementing an Http Protocol we use HttpServletRequest. In a similar way for implementing FTP or SMTP what class or an interface need to be implemented or Extended... and in what situation we use these protocols
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Ramesh, did you understand what Ulf and Ben explained?

It's not just a matter of extending GenericServlet. Normally, you have a servlet container that listens for HTTP (and HTTPS) requests. If an HTTP request is received, it calls your servlet.

If you want your servlet to be called when a client tries to contact the server via a different protocol (FTP, SMTP, whatever), you need to have server software that listens on the port for the protocol you want to use, and that software has to be able to call your servlet.

There's no ready-made server software available that can do this, so you would have to write it yourself. So it's not just a question of making your own SmtpServlet that subclasses GenericServlet.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

As was said earlier, you would need to build a container first.
Applications like Tomcat, WAS, Weblogic, etc.. have connectors that deal with the lower level aspects of the HTTP protocol. They bind to the correct ports and listen for incoming connections. When one is received, it creates the needed request and response objects and passes them to your servlets.

To work with another protocol, you would need either to build an entire container or to build a new connector for an existing container like Tomcat that understands that protocol. From there, you could create your own "FtpServlet" (which could extend GenericServlet) with the methods required for dealing with that protocol.
Ramesh Chandra
Greenhorn

Joined: Oct 20, 2005
Posts: 17
Originally posted by Jesper de Jong:
Ramesh, did you understand what Ulf and Ben explained?

It's not just a matter of extending GenericServlet. Normally, you have a servlet container that listens for HTTP (and HTTPS) requests. If an HTTP request is received, it calls your servlet.

If you want your servlet to be called when a client tries to contact the server via a different protocol (FTP, SMTP, whatever), you need to have server software that listens on the port for the protocol you want to use, and that software has to be able to call your servlet.

There's no ready-made server software available that can do this, so you would have to write it yourself. So it's not just a question of making your own SmtpServlet that subclasses GenericServlet.


Hi Jesper,
Thanks for ur reply
Ur Explanation is very clear.
It would be more helpful if u can explain me say for an FTP protocol to be implemented by a servlet what all needs to be done i mean what are the additional classes or interfaces that are to be implemented or extended and other related stuff that needs to be done......
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Ramesh Chandra:


Hi Jesper,
Thanks for ur reply
Ur Explanation is very clear.
It would be more helpful if u can explain me say for an FTP protocol to be implemented by a servlet what all needs to be done i mean what are the additional classes or interfaces that are to be implemented or extended and other related stuff that needs to be done......


I think Jesper's point is that it is way beyond the scope of a user's forum to try to explain how to build an entire FTP or SMTP server.
If you want to do this, I would start by finding the specifications for the the protocol you want to write for. You would then, most likely, want to look at the java.net package and learn about socket programming.

The job of a servlet container is to handle all of the low level, icky stuff for you and to provide you with a nice simple interface that you can use to build your application.

At the moment, nobody has done this for any protocol other than HTTP (that I know of).
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Ramesh Chandra:
Thanks for ur reply
Ur Explanation is very clear.
It would be more helpful if u can explain me say for an FTP protocol to be implemented by a servlet what all needs to be done i mean what are the additional classes or interfaces that are to be implemented or extended and other related stuff that needs to be done......


You had better to come up with a servlet container, which is capable to handle FTP, SMTP or some other protocol requests. As we have Tomcat and some other containers for HTTP/HTTPS protocol only. Then we can surly help you further in this regard.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41096
    
  44
Is this an academic discussion about something that's theoretically possible, and you're just curious about what it would take to do, or do you have an actual requirement to do it? If the latter, I think it would be easier if you told us what that requirement is, and we might suggest alternatives. That's because actually implementing a non-HTTP servlet container would be a lot of work, and to me it's not clear what would be gained by doing it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Protocols used by a Generic Servlet
 
Similar Threads
JSP and Servlets
About init(ServletConfig)/Intialization
difference between GenericServlet and HttpServlet
diff between http generic servlet
JSP and Servlets