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
没有合适的资源?快使用搜索试试~ 我知道了~
java-1.8.0-openjdk.windows.x86_64位
共669个文件
java:112个
xml:80个
exe:63个
5星 · 超过95%的资源 需积分: 38 63 下载量 2 浏览量
2018-02-27
16:07:10
上传
评论
收藏 83.3MB ZIP 举报
温馨提示
java-1.8.0-openjdk.windows.x86_64位-win64位的openjdk
资源推荐
资源详情
资源评论
收起资源包目录
java-1.8.0-openjdk.windows.x86_64位 (669个子文件)
jmxremote.access 4KB
ASSEMBLY_EXCEPTION 1KB
ASSEMBLY_EXCEPTION 1KB
memory.bat 2KB
fontconfig.bfc 4KB
AccessBridgeCalls.c 45KB
cacerts 32B
blacklisted.certs 1KB
jvm.cfg 2KB
SpreadSheet.class 7KB
BarChart.class 6KB
CLSFractal.class 6KB
Cell.class 5KB
Clock.class 5KB
DitherTest.class 5KB
SortItem.class 5KB
NervousText.class 3KB
DrawPanel.class 3KB
Blink.class 3KB
DrawControls.class 3KB
DitherControls.class 3KB
CardTest.class 2KB
ContextLSystem.class 2KB
InputField.class 2KB
GraphicsTest.class 2KB
ArcCanvas.class 2KB
ArcTest.class 2KB
SpreadSheetInput.class 2KB
Node.class 2KB
CellUpdater.class 2KB
GraphicsPanel.class 2KB
DitherCanvas.class 1KB
CardPanel.class 1KB
CardinalTextField.class 1KB
IntegerTextField.class 1KB
ArcControls.class 1KB
AppletFrame.class 1KB
PolygonShape.class 1KB
ShapeTest.class 1KB
ArcPanel.class 1KB
ArcDegreePanel.class 1KB
DrawTest.class 1KB
CLSTurtle.class 1KB
QSortAlgorithm.class 1KB
SortAlgorithm.class 1KB
DitherMethod.class 988B
GraphApplet.class 806B
CLSRule.class 792B
BidirBubbleSortAlgorithm.class 751B
DitherTest$1.class 708B
GraphicsCards.class 696B
ColorUtils.class 619B
BubbleSortAlgorithm.class 560B
ArcCard.class 492B
RoundRectShape.class 433B
OvalShape.class 408B
RectShape.class 408B
Blink$1.class 403B
Shape.class 250B
classlist 82KB
tzdb.dat 102KB
currency.data 4KB
jvm.diz 7.06MB
awt.diz 1.32MB
fontmanager.diz 342KB
jli.diz 274KB
jdwp.diz 241KB
splashscreen.diz 237KB
java.diz 234KB
WindowsAccessBridge-64.diz 230KB
lcms.diz 223KB
instrument.diz 216KB
hprof.diz 198KB
net.diz 182KB
JavaAccessBridge-64.diz 163KB
jpeg.diz 154KB
sunec.diz 140KB
mlib_image.diz 133KB
unpack.diz 128KB
nio.diz 108KB
j2pkcs11.diz 95KB
jawt.diz 95KB
jsoundds.diz 92KB
management.diz 90KB
jsound.diz 89KB
zip.diz 88KB
verify.diz 74KB
sunmscapi.diz 70KB
dt_shmem.diz 66KB
w2k_lsa_auth.diz 57KB
java_crw_demo.diz 57KB
dt_socket.diz 57KB
attach.diz 54KB
j2pcsc.diz 49KB
sawindbg.diz 48KB
jsdt.diz 48KB
npt.diz 47KB
jaas_nt.diz 42KB
JAWTAccessBridge-64.diz 40KB
jvm.dll 8.06MB
共 669 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
- 生活教会我们2023-07-28这个文件在Windows系统上运行良好,没有出现过任何兼容性问题。
- 人亲卓玛2023-07-28使用这个文件可以方便地进行Java程序的编译和运行,提高开发效率。
- 洋葱庄2023-07-28这个文件提供了稳定可靠的Java开发环境,适合各种项目需求。
- 一筐猪的头发丝2023-07-28通过下载安装这个文件,可以快速搭建一个稳定且高效的Java开发环境。
- 三更寒天2023-07-28无论是初学者还是经验丰富的开发者,都能轻松上手使用这个文件。
Dawn丶夜
- 粉丝: 2
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 重启进行BIOS快捷方式,不需要开机按BIOS键
- 威纶通触摸屏编程软件Easy builder pro V6.09.01.556安装包(2024.04).txt
- WindowsAdminCenter
- 老飞飞搭建基础通用数据库V19数据库.rar
- jquery.js
- 机械设计多工位ACF贴胶带&预压设备sw18可编辑非常好的设计图纸100%好用.zip
- 基于Pytorch复现Point-Transformer,用于ShapeNet数据集点云分割
- 【医学影像分析】2D超声图像的分割检测(Ultrasound Nerve Segmentation - Kaggle数据集)
- 嘎嘎香的五款神仙谷歌插件
- .arch书源导入教程.mp4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功