A Simple NIO-based HTTP/HTTPS Server Example
INTRODUCTION
============
This directory contains a simple HTTP/HTTPS server. HTTP/HTTPS are two
common network protocols that provide for data transfer, and are more
fully described in RFC 2616 and RFC 2818 (Available at
http://www.ietf.org ). HTTPS is essentially HTTP after the connection
has been secured with SSL/TLS. TLS is the successor to SSL, and is
described in RFC 2246.
This server was written to demonstrate some of the functionality new to
the Java 2 platform. The demo is not meant to be a full tutorial, and
assumes the reader has some familiarity with the subject matter.
In particular, it shows:
New I/O (java.nio, java.nio.channels, java.util.regex, java.nio.charset)
Introduced in version 1.4 of the platform, NIO was designed to
overcome some of the scalability limitations found in the
existing blocking java.net.* API's, and to address other
concepts such as Regular Expression parsing and Character
Sets.
This server demonstrates:
ByteBuffer
Blocking and Non-Blocking I/O
SocketChannel
ServerSocketChannel
Selector
CharacterSet
Pattern matching using Regular Expressions
JSSE (javax.net.ssl)
Introduced in version 1.4 of the platform, JSSE provides
network security using SSL/TLS for java.net.Socket-based
traffic. In version 1.5, the SSLEngine API was introduced
which separates the SSL/TLS functionality from the underlying
I/O model. By making this separation, applications can adapt
I/O and compute strategies to best fit their circumstances.
This server demonstrates:
Using SSLEngine to create a HTTPS server
Creating simple key material for use with HTTPS
Concurrency Library (java.util.concurrent)
Introduced in version 1.5 of the platform, the concurrency
library provides a mechanism which decouples task submission
from the mechanics of how each task will be run.
This server demonstrates:
A ThreadPool with a fixed number of threads, which is
based on the number of available processors.
SETUP
=====
The server must be built on version 1.5 (or later) of the platform.
Invoking the following should be sufficient:
% mkdir build
% javac -source 1.5 -target 1.5 -d build *.java
The following creates the document root:
% mkdir root
All documents should be placed in this directory.
For HTTPS, the server authenticates itself to clients by using simple
Public Key Infrastructure (PKI) credentials in the form of
X509Certificates. You must create the server's credentials before
attempting to run the server in "-secure" mode. The server is
currently hardcoded to look for its credentials in a file called
"testkeys".
In this example, we'll create credentials for a fictional widget web
site owned by the ubiquitous "Xyzzy, Inc.". When you run this in your
own environment, replace "widgets.xyzzy.com" with the hostname of your
server.
The easiest way to create the SSL/TLS credentials is to use the
java keytool, by doing the following:
(<CR> represents your end-of-line key)
% keytool -genkey -keyalg rsa -keystore testkeys -alias widgets
Enter keystore password: passphrase
What is your first and last name?
[Unknown]: widgets.xyzzy.com<CR>
What is the name of your organizational unit?
[Unknown]: Consumer Widgets Group<CR>
What is the name of your organization?
[Unknown]: Xyzzy, Inc.<CR>
What is the name of your City or Locality?
[Unknown]: Arcata<CR>
What is the name of your State or Province?
[Unknown]: CA<CR>
What is the two-letter country code for this unit?
[Unknown]: US<CR>
Is CN=widgets.xyzzy.com, OU=Consumer Widgets Group, O="Xyzzy, Inc.",
L=Arcata, ST=CA, C=US correct?
[no]: yes<CR>
Enter key password for <mykey>
(RETURN if same as keystore password): <CR>
This directory also contain a very simple URL reader (URLDumper), which
connects to a specified URL and places all output into a specified file.
SERVER EXECUTION
================
% java -classpath build Server N1
Usage: Server <type> [options]
type:
B1 Blocking/Single-threaded Server
BN Blocking/Multi-threaded Server
BP Blocking/Pooled-thread Server
N1 Nonblocking/Single-threaded Server
N2 Nonblocking/Dual-threaded Server
options:
-port port port number
default: 8000
-backlog backlog backlog
default: 1024
-secure encrypt with SSL/TLS
default is insecure
"http://" URLs should be used with insecure mode, and
"https://" for secure mode.
The "B*" servers use classic blocking I/O: in other words, calls to
read()/write() will not return until the I/O operation has completed. The
"N*" servers use non-blocking mode and Selectors to determine which
Channels are ready to perform I/O.
B1: A single-threaded server which completely services each
connection before moving to the next.
B2: A multi-threaded server which creates a new thread for each
connection. This is not efficient for large numbers of
connections.
BP: A multi-threaded server which creates a pool of threads for use
by the server. The Thread pool decides how to schedule those
threads.
N1: A single-threaded server. All accept() and read()/write()
operations are performed by a single thread, but only after
being selected for those operations by a Selector.
N2: A dual-threaded server which performs accept()s in one thread, and
services requests in a second. Both threads use select().
CLIENT EXECUTION
================
You can test the server using any standard browser such as Internet
Explorer or Mozilla, but since the browser will not trust the
credentials you just created, you may need to accept the credentials
via the browser's pop-up dialog box.
Alternatively, to use the certificates using the simple included JSSE
client URLDumper, export the server certificate into a new truststore,
and then run the application using the new truststore.
% keytool -export -keystore testkeys -alias widgets -file widgets.cer
Enter keystore password: passphrase<CR>
Certificate stored in file <widgets.cer>
% keytool -import -keystore trustCerts -alias widgetServer \
-file widgets.cer
Enter keystore password: passphrase<CR>
Owner: CN=widgets.xyzzy.com, OU=Consumer, O="xyzzy, inc.", L=Arcata,
ST=CA, C=US
Issuer: CN=widgets.xyzzy.com, OU=Consumer, O="xyzzy, inc.",
L=Arcata, ST=CA, C=US
Serial number: 4086cc7a
Valid from: Wed Apr 21 12:33:14 PDT 2004 until: Tue Jul 20 12:33:14
PDT 2004
Certificate fingerprints:
MD5: 39:71:42:CD:BF:0D:A9:8C:FB:8B:4A:CD:F8:6D:19:1F
SHA1: 69:5D:38:E9:F4:6C:E5:A7:4C:EA:45:8E:FB:3E:F3:9A:84:01:6F:22
Trust this certificate? [no]: yes<CR>
Certificate was added to keystore
% java -classpath build -Djavax.net.ssl.trustStore=trustCerts \
-Djavax.net.ssl.TrustStorePassword=passphrase \
URLDumper https://widgets.xyzzy.com:8000/ outputFile
NOTE: The server must be run with "-secure" in order to receive
"https://" URLs.
WARNING: This is just a simple example for code exposition, you should
spend more time understanding PKI security concerns.
SOURCE CODE OVERVIEW
====================
The main class is Server, which handles program startup, and is
subclassed by the "B*" and "N*" server classes.
Following a successful accept(), the "B*" variants each create a
RequestServicer object to perform the actual request/reply operations. The
primary differences between the different "B*" servers is how the
RequestServicer is actually run:
B1
Alibaba-Dragonwell-Standard-8.13.14-x64-windows.zip
需积分: 0 56 浏览量
更新于2022-11-21
收藏 98.94MB ZIP 举报
《Alibaba Dragonwell:探索与理解》
在Java开发领域,Alibaba Dragonwell是一个不容忽视的角色。它是一款由阿里巴巴公司推出的免费OpenJDK发行版,为开发者提供了稳定、高性能的运行环境,尤其对于大型企业应用而言,其长期支持、性能优化和安全更新显得尤为重要。
一、Alibaba Dragonwell简介
Alibaba Dragonwell是阿里巴巴集团贡献给全球开源社区的一款基于OpenJDK的JDK实现。它的主要特点是提供了一个经过精心优化的JVM(Java虚拟机),旨在提高应用程序的运行效率,降低资源消耗,同时保证代码的安全性。由于其源自OpenJDK,因此具备开源、免费的特点,用户可以自由地使用、修改和分发。
二、版本信息——8.13.14
"Alibaba-Dragonwell-Standard-8.13.14-x64-windows.zip"这个压缩包的命名揭示了几个关键信息。“8.13.14”表示这是Dragonwell的一个具体版本,它基于OpenJDK 8的分支,版本号中的“13”可能代表维护更新的次数,“14”则可能是内部迭代的标识。"x64"表明这是针对64位操作系统的版本,而"windows"则意味着它是专为Windows平台设计的。
三、核心特性
1. 性能优化:Alibaba Dragonwell在OpenJDK的基础上进行了深度定制,尤其是在垃圾回收、JIT编译器、线程管理等方面做了大量的性能优化,提升了应用的运行速度和响应时间。
2. 长期支持:作为企业级的JDK发行版,Dragonwell承诺对每个版本提供长期的技术支持,包括定期发布安全补丁和性能改进,确保用户能够持续获得稳定的运行环境。
3. 安全性:鉴于其在商业环境中的广泛应用,Alibaba Dragonwell非常重视安全性,会及时跟进并修复OpenJDK中的已知安全问题,为用户的数据安全提供保障。
4. 社区支持:作为开源项目,Dragonwell有活跃的社区支持,开发者可以参与其中,提交问题、建议或直接贡献代码,共同推动项目的进步。
四、使用与部署
在"dragonwell-8.13.14"这个压缩包中,包含了完整的Dragonwell JDK安装文件,用户只需解压后按照常规步骤配置环境变量,即可在Windows系统上使用。同时,由于其与标准OpenJDK的兼容性,大多数Java应用程序无需修改就能直接运行在Dragonwell之上。
总结,Alibaba Dragonwell以其优化的性能、长期的支持和强大的安全性,成为了企业级Java开发的重要选择。通过深入理解和使用,开发者可以更好地发挥Java平台的潜力,构建高效、稳定的应用系统。
qxmjava
- 粉丝: 24
- 资源: 714
最新资源
- (GUI框架)Matlab设计_的答题纸答题卡识别.zip
- (GUI框架)Matlab设计_的路牌交通牌照识别.zip
- 计算机物联网专业毕业设计的研究成果与实践过程报告模板
- MATLAB:考虑齿面接触变形量,基于石川算法求解齿轮时变啮合刚度,齿轮动力学时域图、相图、分岔图、庞加莱图,可用于参考学习齿轮动力学复现学习,程序内注释解答清晰,便于学习 附赠齿轮系统的非线性动力
- 数据库课程设计《SQL Server图书馆管理系统》(完整版)
- Spark 执行流程.xmind
- (GUI框架)Matlab设计_的车道线标定.zip
- (GUI框架)Matlab设计_的人脸+指纹融合系统.zip
- (GUI框架)Matlab设计_的人脸识别设计.zip
- Linux命令行核心命令详解与应用场景
- (GUI框架)Matlab设计_的人脸门禁预警.zip
- (GUI框架)Matlab设计_的手写汉字识别.zip
- (GUI框架)Matlab设计_的手写字符识别.zip
- MATLAB Simukink基于下垂控制的光储直流微电网离网运行控制 关键字:离网;直流下垂;交流负载;V f
- (GUI框架)Matlab设计_的视频图像去雾.zip
- (GUI框架)Matlab设计_的小波变换dwt数字水印.zip