Porting Servlet Based Logic to Netty

Sumit Arora sumit1234 at gmail.com
Sun Nov 21 19:11:52 EST 2010


/* I am posting this question on netty-users group, earlier I mistakenly
posted in netty-devloper group , which was not a right group for this
question */

Currently I am using Servlets to Implement a HttpRequest/Response Logic, On
which following scenarios happens:
 
-- Client                  : Send Http Request from a Device to Server
-- Server                 : Http Response to the Client
-- Common Scenario  :  Initially client sends a connection request and get
the response from Server, after that it send A or B or C contents in
httpRequest and Server execute a business logic based on the received
contents in httpRequest and send httpResponse back to Client.
 
On this scenario, several devices Connects to the Server, and Server need to
maintain the Connections, and Servlets spawns a thread for each connection
(Based on his Internal Mechanism).
 
Now I am Trying to use Netty on this way, and need to port Servlets code to
Netty, So I am considering following approach :
[ Using Http Snoop Example]
 
1.  Converting Calls for HttpServletRequest httpRequest[Changed to
==>HttpRequest httpRequest = this.request = (HttpRequest) e.getMessage();],
HttpServletResponse httpResponse [Changed to HttpResponse httpResponse to
create a response //to Build the response object].
 
2. Run Netty Based Converted Servlet to as a Http Server - running it from
Spring as a Service.
 
3. Placed Servlet - init() method to the HttpServer (Customized)'s Main
function from where      
        ServerBootstrap bootstrap = new ServerBootstrap(...) was called.
 
4. For httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST," XYZ");
changed to Build the response object.(As mentioned in Http Snoof Example)
 
 
 
 
##Question Q1. It calls HttpURLConnection (Current Servlets Code) several
places to send any response back to Client (On Some situation), Is there a
way to do the same in Netty ? Any different Approach
 
##Question Q2. InputStream input = httpRequest.getInputStream();
             >>Where HttpRequest is the type of HttpServletRequest,
On this case it reads received Inputstream (read it byte by byte until it
receive CR or LF), and based on this received message it take appropriate
action?
 
>> So it always is in while loop here, it reads data from HttpRequest and
>> based on received data e.g;
 
   A or B or C -- it performs corresponding action, Once Client sends Closed
request , it closed this servlet or Connection and come out from this loop.
(Blocking Scenario).
 
 
 
How I can read such stream in netty ? By using ChannelBuffer , what is the
exact way to do that ?
 
Should I write such code inside messageReceived ? and when every time
messageReceived Called , I should find out contents in it , and based on
that content either A or B or C or D , It should take appropriate action ?
 
##Question Q3. do I need to build the response always ? Seems in Servlets
send by default 200 OK with header transfer-encoding: chunk, if Servlet
received a request contains transfer-encoding: chunk ?
 
##Question Q4 : On the above explained scenario : I am planning to run this
customizes Http Server (Netty) inside Jetty or Tomcat , as a Service from
Spring ? Is that doable scenario? 
-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Porting-Servlet-Based-Logic-to-Netty-tp5761283p5761283.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list