Is it possible to Handle ftp request using servlet? - java

Is it possible to write a servlet which handles FTP request instead of usual HTTP request?, If yes, how can we do this?

Although it says that you can extend GenericServlet to use other protocols than HTTP - you can't. There's no implementation that handles the networking, especially since FTP is a statefull protocol.
I would suggest implementing something like the Apache Mina Ftp Server (http://mina.apache.org/ftpserver-project/) to handle that for you.

Related

How to create a Spring API which receives HTTP and internally communicate with another endpoint using TCP/IP?

I'm trying to create an application which follows the next structure:
Project structure
I saw Spring Integration documentation, but it seems like it doesn't fit for that project structure.
Am I missing something? I can't found useful information about this.
Thanks for helping!
TCP/IP is a protocol like the Http. For me, you can use the RestTemplate to communicate between your API and your Backend.
TCP/IP, UDP are in transport layer of OSI network model where as HTTP is in application layer. HTTP also relies on TCP. So when you are using HTTP you are also using TCP.
The question you need to ask yourself is what kind of data you are transferring. TCP is a stream of packets.
If it is a single long text then do it with a single connection.
Or is the data in chunks? Then you will need to create multiple connections.
Looking at the image you shared, you can send plain text on HTTP as well. See Mime Types.

Is it possible to write a non-HTTP servlet for Tomcat container?

I would like to handle non-HTTP traffic, but (now it seems) I have to run it at Cloud Foundry ecosystem.
Is there any way to write (and push) a servlet which can handle raw TCP connections or is this against the whole servlet container design (as I can see now)?
As of right now TCP is not supported in Cloud Foundry. However, TCP is coming this year. Check out http://www.slideshare.net/Pivotal/cloud-foundry-summit-2014-cloud-foundry-roadmap for the roadmap!
Tomcat listens to an HTTP port, and converts the requests sent to it on Java objects that passes to a servlet method.
You cannot make Tomcat listen to anything different than HTTP or HTTPS. So, if you have a class that handles raw TCP connections it will take no advantage of being in Tomcat.
Servlets handle requests (not necessarily HTTP requests per the spec, but always requests). You could write code that would listen on a raw TCP socket, but that would have nothing to do with whether it's running in Tomcat.
To add some more information about your original question of if it is possible to write a non-HTTP servlet for a Tomcat container, the answer is yes, this is very much possible. TomCat is preconfigured with built-in support for the HTTP protocol; however, it is not too farfetched of an idea that you can extend the servlet concept and adapt this to support other protocols on top of TCP/IP.
If you look at your servlet class, you will see that this class extends HttpServlet, and that HttpServlet extends the GenericServlet class. It would be up to you to create your own unique protocol class that extends GenericServlet. For example, you could create a FTPServlet or a SMTPServlet class. However, it will be up to you to investigate if the servlet paradigm is the best architecture to implement other protocols with. Wish you luck.

how to cache http requests at proxy server in java?

I am a student building a http proxy server. I want to cache those requests that are frequently accessed. May I get any idea about this? Especially in java.
To figure out what you need to implement, read and understand the HTTP specification. Focus particularly on the sections on how a proxy is supposed to behave.
You could possibly base part of the implementation on the Apache HttpClient library, but I have a feeling that the APIs will prove to be unsuitable for the proxy server use-case.
I'd also like to point out that a more practical way to implement an HTTP proxy server would be to simply deploy an existing server like Squid.

Compressing result of Web Service

I have a .NET web service that returns XML, and I'd like to compress this before it is sent.
There's a couple of ways that I can do this, but I'd rather not have to do it in code.
Can I set up IIS to gzip all content returned by my WebService? It's not being called from a browser.
The other question is if this web service is being consumed by a Java client - will that affect anything?
I imagine that the client proxy will still need to decompress, but there shouldn't be any problem if I use gzip - that is a universal protocol, right?
The standard way to do this kind of thing is to use gzip compression over HTTP since it's directly supported by the protocol. As long as your client supports that then you should be good to go.
If you are writing the client from scratch with more fundamental tools you may need to add handling for this yourself: a good example of this is shown here (python).
I would expect a lot of SOAP client libraries to have built-in support for this but you'll have to try yours to be sure: if they lean on a lower level HTTP library to do their work, in all likelihood it should Just Work.
you can configure metabase.xml in iis for better control over compression. you may want redefine your web application format (.asp,.asmx,...) to metabase if it is not already included.
you can see below:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/25d2170b-09c0-45fd-8da4-898cf9a7d568.mspx?mfr=true
and also
http://www.businessanyplace.net/?p=wscompress

Implementation of AJP protocol in Java

From Apache, you can use the "mod_jk" module to send HTTP requests to Tomcat using the "AJP" protocol, which is far more efficient that HTTP itself.
I want to do the same, but from a Java program. I want to use "AJP" because of its good performances (and Tomcat is not bad after all).
Does someone know about a Java implementation of the client side of "AJP" ?
Doesn't the tomcat-ajp.jar present in %TOMCAT_HOME%/server/lib have the AJP implementation?
There's open source Apache ajp-client available if someone needs it:
This is a java implementation of an ajp13 client, allowing to send requests to a servlet container using this protocol.
Whithout any real idea, but have you looked into Tomcat's source code, yet? Maybe Tomcat doesn't just implement the receiving end of AJP.

Categories