Skip to content
forked from why2012/jNetty

a simple servlet container based on netty.

Notifications You must be signed in to change notification settings

zyingfei/jNetty

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jNetty

About jNetty

a simple non-blocking servlet server/container based on netty.

1、bootstrap (start Service and Connector)
2、connector (build Server,create Httpprocessor and process HTTP request)
3、httpprocessor (establish Httprequest,Httpresponse,invoke Container to process Servlet) staticresourceprocessor (process static resource)
4、httprequest,httpresponse (implement HttpServletRequest/Response)
5、container(load servlet,choose a servlet based on request)

Bootstrap
      |- n -Service
                  |- n -Connector
                  |- 1 -Container
                         |- n -Servlet

How to use:

First, you should create a global configuration like this :
Config config = new Config();
Then, create a service config, a service is mapping to a webapp:
ServiceConfig sconfig = new ServiceConfig();
And configure the service config:
sconfig.connectorQueue.add(new Config.ConnectorConfig());
sconfig.JNettyBase = "/Users/webapps-basedir/";
sconfig.WebAppName = "transaction";
Add service config to global config:
config.serviceConfig.add(sconfig);
Finally, create a bootstrap and start it:
Bootstrap bootstrap = new Bootstrap();
bootstrap.setConfig(config);
bootstrap.initialize();
bootstrap.start();

Code:

Config config = new Config();
	ServiceConfig sconfig = new ServiceConfig();
	//if you don't want to use WAR file, you could, alternatively , add a servlet like this.
	sconfig.servletList.add(new Config.MappingData("name", "com.jnetty.jnetty.servlets.SessionServlet", "/session", 0));
	//add a connector, default port is 8080
	sconfig.connectorQueue.add(new Config.ConnectorConfig());
	sconfig.JNettyBase = "/Users/webapps-basedir/";
	sconfig.WebAppName = "transaction";
	sconfig.staticResourceLoc = "/resources/";
	
	config.serviceConfig.add(sconfig);
	
	Bootstrap bootstrap = new Bootstrap();
	bootstrap.setConfig(config);
	bootstrap.initialize();
	System.out.println(sconfig);//print config params

	bootstrap.start();

About

a simple servlet container based on netty.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%