【JAVA之Undertow 介绍】

一、Undertow 介绍

Undertow is a flexible performant web server written in java, providing both blocking and non-blocking API’s based on NIO.

Undertow has a composition based architecture that allows you to build a web server by combining small single purpose handlers. The gives you the flexibility to choose between a full Java EE servlet 3.1 container, or a low level non-blocking handler, to anything in between.

Undertow is designed to be fully embeddable, with easy to use fluent builder APIs. Undertow’s lifecycle is completely controlled by the embedding application.



 

二、Why Undertow

1、Lightweight

Undertow is extremely lightweight, with the Undertow core jar coming in at under 1Mb. It is lightweight at runtime too, with a simple embedded server using less than 4Mb of heap space.

 

2、HTTP Upgrade Support

Support for HTTP upgrade, to allow multiple protocols to be multiplexed over the HTTP port.

 

3、Web Socket Support

Undertow provides full support for Web Sockets, including JSR-356 support.

 

4、Servlet 3.1

Undertow provides support for Servlet 3.1, including support for embedded servlet. It is also possible to mix both Servlets and native undertow non-blocking handlers in the same deployment.

 

5、Embeddable

Undertow can be embedded in an application or run standalone with just a few lines of code.

 

6、Flexible

An Undertow server is configured by chaining handlers together. It is possible to add as much or as little functionality as you need, so you don’t pay for what you are not using.

 

 

三、Show me the code

Ok then. Here is a simple Hello World server using Async IO:

public class HelloWorldServer {

public static void main(final String[] args) {

Undertow server = Undertow.builder()

.addHttpListener(8080, "localhost")

.setHandler(new HttpHandler() {

@Override

public void handleRequest(final HttpServerExchange exchange) throws Exception {

exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");

exchange.getResponseSender().send("Hello World");

}

}).build();

server.start();

}

}

 

 

 

------------------------------------------------

Undertow 是红帽公司(RedHat)的开源产品,是 WildFly8(JBoos) 默认的 Web 服务器。

官网API给出一句话概述Undertow:

Undertow is a flexible performant web server written in java, providing both blocking and non-blocking API’s based on NIO.

译文: Undertow是一个用java编写的灵活的高性能Web服务器,提供基于NIO的阻塞和非阻塞API。

 

官网API总结特点:

 

1、Lightweight(轻量级)

Undertow非常轻量级,Undertow核心jar包在1Mb以下。 它在运行时也是轻量级的,有一个简单的嵌入式服务器使用少于4Mb的堆空间

 

2、HTTP Upgrade Support(支持http升级)

支持HTTP升级,允许多个协议通过HTTP端口进行多路复用

 

3、Web Socket Support(支持WebScoket)

Undertow提供对Web Socket的全面支持,包括JSR-356支持

 

4、Servlet 3.1  

Undertow提供对Servlet 3.1的支持,包括对嵌入式servlet的支持。 还可以在同一部署中混合Servlet和本机Undertow非阻塞处理程序

 

5、Embeddable(可嵌入的)

Undertow可以嵌入在应用程序中或独立运行,只需几行代码

 

6. Flexible(灵活性)

Undertow框架jar包: undertow-core.jar undertow-servlet.jar

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值