标签:怎么 ash 独立 客户 ecb login 单位 initial 网络协议
Jetty 是一个开源的servlet容器,它为基于Java的web容器,例如JSP和servlet提供运行环境。Jetty是使用Java语言编写的,它的API以一组JAR包的形式发布。开发人员可以将Jetty容器实例化成一个对象,可以迅速为一些独立运行(stand-alone)的Java应用提供网络和web连接。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
//代码:以嵌入模式启动Jetty import org.mortbay.http.HttpContext; import org.mortbay.http.HttpServer; import org.mortbay.http.SocketListener; import org.mortbay.http.handler.ResourceHandler; public class JettySample{ public static void main(String[]args) throws Exception{ //创建JettyHttpServer对象 HttpServer server= new HttpServer(); //在端口8080上给HttpServer对象绑上一个listener,使之能够接收HTTP请求 SocketListener listener= new SocketListener(); listener.setPort( 8080 ); server.addListener(listener); //创建一个HttpContext,处理HTTP请求。 HttpContext context= new HttpContext(); //用setContextPath把Context映射到(/web)URL上。 context.setContextPath( "/web" ); //setResourceBase方法设置文档目录以提供资源 context.setResourceBase( "C:\\j2sdk1.4.1_05" ); //添加资源处理器到HttpContext,使之能够提供文件系统中的文件 context.addHandler( new ResourceHandler()); server.addContext(context); //启动服务器 server.start(); } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
<? xmlversion = "1.0" encoding = "utf-8" ?> < plugin > < groupId >org.mortbay.jetty</ groupId > < artifactId >maven-jetty-plugin</ artifactId > < version >6.1.10</ version > < configuration > < scanIntervalSeconds >10</ scanIntervalSeconds > < stopKey >foo</ stopKey > < stopPort >9999</ stopPort > </ configuration > < executions > < execution > < id >start-jetty</ id > < phase >pre-integration-test</ phase > < goals > < goal >run</ goal > </ goals > < configuration > < scanIntervalSeconds >0</ scanIntervalSeconds > < daemon >true</ daemon > </ configuration > </ execution > < execution > < id >stop-jetty</ id > < phase >post-integration-test</ phase > < goals > < goal >stop</ goal > </ goals > </ execution > </ executions > </ plugin > |
1
|
<pluginGroup>org.mortbay.jetty</pluginGroup> |
版本 | Year | Home | JVM | 协议 | Servlet | JSP | 状态 |
---|---|---|---|---|---|---|---|
9.3 |
2015 |
Eclipse |
1.8 |
HTTP/1.1 (RFC 7230), HTTP/2 (RFC 7540), WebSocket (RFC 6455, JSR 356), FastCGI |
3.1 |
2.3 |
稳定版本 |
9.2 |
2014 |
Eclipse |
1.7 |
HTTP/1.1 RFC2616, javax.websocket, SPDY v3 |
3.1 |
2.3 |
稳定版本 |
8 |
2009- |
Eclipse/Codehaus |
1.6 |
HTTP/1.1 RFC2616, WebSocket RFC 6455, SPDY v3 |
3.0 |
2.2 |
珍贵版本 |
7 |
2008- |
Eclipse/Codehaus |
1.5 |
HTTP/1.1 RFC2616, WebSocket RFC 6455, SPDY v3 |
2.5 |
2.1 |
珍贵版本 |
6 |
2006-2010 |
Codehaus |
1.4-1.5 |
HTTP/1.1 RFC2616 |
2.5 |
2.0 |
已经作废 |
5 |
2003-2009 |
Sourceforge |
1.2-1.5 |
HTTP/1.1 RFC2616 |
2.4 |
2.0 |
已经作废 |
4 |
2001-2006 |
Sourceforge |
1.2, J2ME |
HTTP/1.1 RFC2616 |
2.3 |
1.2 |
远古时期 |
3 |
1999-2002 |
Sourceforge |
1.2 |
HTTP/1.1 RFC2068 |
2.2 |
1.1 |
石器时代 |
2 |
1998-2000 |
Mortbay |
1.1 |
HTTP/1.0 RFC1945 |
2.1 |
1.0 |
传说级别 |
1 |
1995-1998 |
Mortbay |
1.0 |
HTTP/1.0 RFC1945 |
- |
- |
神话级别 |
JSR | 名称 | jetty-9.1.x是否包含 | 支持插件 |
---|---|---|---|
JSR 340 |
Servlet Specification API 3.1 |
Yes |
|
JSR 344 |
Java Server Faces 2.2 (JSF) |
No |
Yes, Mojarra or MyFaces |
JSR 245 / JSR 341 |
Java Server Pages 2.3/Java Expression Language 3.0 (JSP/EL) |
Yes |
Yes |
JSR 52 |
Java Standard Tag Library 1.2 (JSTL) |
Yes |
Yes |
JSR 45 |
Debugging Support for Other Languages 1.0 |
Yes (via JSP) |
Yes (via JSP) |
JSR 346 |
Contexts and Dependency Injection for the JavaEE Platform 1.1 (Web Beans) |
No |
Yes, Weld |
JSR 330 |
Dependency Injection for Java 1.0 |
No |
Yes as part of a CDI implementation, Weld |
JSR 316 |
Managed Beans 1.0 |
No |
Yes, as part of another technology |
JSR 345 |
Enterprise JavaBeans 3.2 Lite |
No |
|
JSR 338 |
Java Persistance 2.1 (JPA) |
No |
Yes, eg Hibernate |
JSR 250 |
Common Annotations for the Java Platform 1.2 |
Yes |
Partially (for non-core Servlet Spec annotations) |
JSR 907 |
Java Transaction API 1.2 (JTA) |
Yes |
Yes |
JSR 349 |
Bean Validation 1.1 |
No |
Yes as part of another technology eg JSF, or a stand-alone implementation such as Hiberate Validator |
JSR 339 |
Java API for RESTful Web Services 2.0 (JAX-RS) |
No |
|
JSR 356 |
Java API for Websocket 1.0 |
Yes |
No |
JSR 353 |
Java API for JSON Processing 1.0 (JSON-P) |
No |
Yes, eg JSON-P reference implementation |
JSR 318 |
Interceptors 1.2 |
No |
Yes as part of a CDI implementation |
表格 1.3. Java EE 6 Web Profile
JSR | Name | Included with jetty-9.0.x | Pluggable |
---|---|---|---|
JSR 315 |
Servlet Specification API 3.0 |
Yes |
|
JSR 314 |
JavaServer Faces 2.0 (JSF) |
No |
Yes, for example, Mojarra or MyFaces |
JSR 245 |
JavaServer Pages 2.2/Java Expression Language 2.2 (JSP/EL) |
Yes |
Yes |
JSR 52 |
Java Standard Tag Library 1.2 (JSTL) |
Yes |
Yes |
JSR 45 |
Debugging Support for Other Languages 1.0 |
Yes (via JSP) |
Yes (via JSP) |
JSR 299 |
Contexts and Dependency Injection for the Java EE Platform 1.0 (Web Beans) |
No |
Yes, Weld or OpenWebBeans |
JSR 330 |
Dependency Injection for Java 1.0 |
No |
Yes as part of a CDI implementation, Weld |
JSR 316 |
Managed Beans 1.0 |
No |
Yes, as part of another technology. |
JSR 318 |
Enterprise JavaBeans 3.1 |
No |
Yes, OpenEJB |
JSR 317 |
Java Persistance 2.0 (JPA) |
No |
Yes, Hibernate |
JSR 250 |
Common Annotations for the Java Platform |
Yes |
Partially (for non-core Servlet Spec annotations) |
JSR 907 |
Java Transaction API (JTA) |
Yes |
Implementations are pluggable, such as Atomikos, JOTM, Jencks (Geronimo Transaction Manager) |
JSR 303 |
Bean Validation 1.0 |
No |
Yes as part of another technology (JSF), or a stand-alone implementation such as Hiberate Validator |
<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-project</artifactId> <version>${project.version}</version> </dependency>
<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-project</artifactId> <version>${project.version}</version> <classifier>version</classifier> <type>txt</type> </dependency>
表格 2.1. Contents
Location | Description |
---|---|
license-eplv10-aslv20.html |
Jetty的许可文件 |
README.txt |
有用的开始信息 |
VERSION.txt |
版本信息 |
bin/ |
存放在Unix系统下运行的shell脚本 |
demo-base/ |
一个可运行包含示例web应用的Jetty服务器基目录 |
etc/ |
Jetty的配置文件 |
lib/ |
Jetty运行所必须的jar文件 |
logs/ |
日志 |
modules/ |
各个模块 |
notice.html |
许可信息等 |
resources/ |
包含新增到classpath配置文件夹,如log4j.properties |
start.ini |
存放启动信息 |
start.jar |
运行Jetty的jar |
webapps/ |
一个用来存放运行在默认配置下的Jetty Web应用目录 |
cd $JETTY_HOME java -jar start.jar
若执行成功会输出以下信息
2015-06-04 10:50:44.806:INFO::main: Logging initialized @334ms 2015-06-04 10:50:44.858:WARN:oejs.HomeBaseWarning:main: This instance of Jetty is not running from a separate {jetty.base} directory, this is not recommended. See documentation at http://www.eclipse.org/jetty/documentation/current/startup.html 2015-06-04 10:50:44.995:INFO:oejs.Server:main: jetty-9.3.0.v20150601 2015-06-04 10:50:45.012:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///opt/jetty-distribution-9.3.0.v20150601/webapps/] at interval 1 2015-06-04 10:50:45.030:INFO:oejs.ServerConnector:main: Started ServerConnector@19dfb72a{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} 2015-06-04 10:50:45.030:INFO:oejs.Server:main: Started @558ms
你可以通过浏览器访问http://localhost:8080.。然而在$JETTY_HOME/webapps目录下并没有部署任何web应用,所以你将会看到一个Jetty提供的404错误页面,并不推荐在$JETTY_HOME下运行Jetty,而是建议运行一个Jetty基础应用。错误页面如下
> cd $JETTY_HOME/demo-base/ > java -jar $JETTY_HOME/start.jar
成功运行将有如下信息输出:
2015-06-04 10:55:24.161:INFO::main: Logging initialized @308ms 2015-06-04 10:55:24.431:WARN::main: demo test-realm is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:24.434:INFO:oejs.Server:main: jetty-9.3.0.v20150601 2015-06-04 10:55:24.457:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///opt/jetty-distribution-9.3.0.v20150601/demo-base/webapps/] at interval 1 2015-06-04 10:55:24.826:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@c038203{/,file:///opt/jetty-distribution-9.3.0.v20150601/demo-base/webapps/ROOT/,AVAILABLE}{/ROOT} 2015-06-04 10:55:24.929:WARN::main: test-jaas webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:24.978:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@46238e3f{/test-jaas,file:///tmp/jetty-0.0.0.0-8080-test-jaas.war-_test-jaas-any-9105214562680121772.dir/webapp/,AVAILABLE}{/test-jaas.war} 2015-06-04 10:55:25.162:WARN::main: async-rest webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:25.208:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@6b67034{/async-rest,[file:///tmp/jetty-0.0.0.0-8080-async-rest.war-_async-rest-any-1023939491558622183.dir/webapp/, jar:file:///tmp/jetty-0.0.0.0-8080-async-rest.war-_async-rest-any-1023939491558622183.dir/webapp/WEB-INF/lib/example-async-rest-jar-9.3.0.v20150601.jar!/META-INF/resources],AVAILABLE}{/async-rest.war} 2015-06-04 10:55:25.311:WARN::main: test-jndi webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:25.386:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@8b96fde{/test-jndi,file:///tmp/jetty-0.0.0.0-8080-test-jndi.war-_test-jndi-any-1692053319754270133.dir/webapp/,AVAILABLE}{/test-jndi.war} 2015-06-04 10:55:25.508:WARN::main: test-spec webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:25.594:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@69930714{/test-spec,[file:///tmp/jetty-0.0.0.0-8080-test-spec.war-_test-spec-any-5518740932795802823.dir/webapp/, jar:file:///tmp/jetty-0.0.0.0-8080-test-spec.war-_test-spec-any-5518740932795802823.dir/webapp/WEB-INF/lib/test-web-fragment-9.3.0.v20150601.jar!/META-INF/resources],AVAILABLE}{/test-spec.war} 2015-06-04 10:55:25.781:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@3eb7fc54{/proxy,file:///tmp/jetty-0.0.0.0-8080-xref-proxy.war-_xref-proxy-any-3068657547009829038.dir/webapp/,AVAILABLE}{/xref-proxy.war} 2015-06-04 10:55:25.786:INFO:oejsh.ContextHandler:main: Started o.e.j.s.h.MovedContextHandler@59662a0b{/oldContextPath,null,AVAILABLE} 2015-06-04 10:55:25.951:WARN::main: test webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 10:55:26.248:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@4f83df68{/test,file:///tmp/jetty-0.0.0.0-8080-test.war-_test-any-5238659347611323540.dir/webapp/,AVAILABLE}{/test.war} 2015-06-04 10:55:26.255:INFO:oejs.ServerConnector:main: Started ServerConnector@5a9c4ad9{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} 2015-06-04 10:55:26.259:INFO:oejus.SslContextFactory:main: x509={jetty.eclipse.org=jetty} wild={} alias=null for SslContextFactory@23941fb4(file:///opt/jetty-distribution-9.3.0.v20150601/demo-base/etc/keystore,file:///opt/jetty-distribution-9.3.0.v20150601/demo-base/etc/keystore) 2015-06-04 10:55:26.269:INFO:oejs.ServerConnector:main: Started ServerConnector@5d908d47{SSL,[ssl, http/1.1]}{0.0.0.0:8443} 2015-06-04 10:55:26.270:INFO:oejs.Server:main: Started @2417ms
现在可以通过浏览器访问 http://localhost:8080, 此时可以看到一个Jetty的欢迎页面,页面上包含几个简单的例子,欢迎页面如下
警告
示例的web应用程序不一定是绝对安全的,所以不应该部署在生产环境上。
你可以通过以下命令查看示例应用的配置信息
> cd $JETTY_HOME/demo-base/ > java -jar $JETTY_HOME/start.jar --list-modules ... > java -jar %JETTY_HOME/start.jar --list-config ...
--list-modules:此命令将返回当前服务所有可用的模块,同时也会显示本地的模块,信息包括模块实现的顺序,依赖模块以及相应的jar信息
> JETTY_BASE=/tmp/mybase > mkdir $JETTY_BASE > cd $JETTY_BASE > java -jar $JETTY_HOME/start.jar WARNING: Nothing to start, exiting ... Usage: java -jar start.jar [options] [properties] [configs] java -jar start.jar --help # for more information > java -jar $JETTY_HOME/start.jar --add-to-startd=http,deploy INFO: server initialised (transitively) in ${jetty.base}/start.d/server.ini INFO: http initialised in ${jetty.base}/start.d/http.ini INFO: security initialised (transitively) in ${jetty.base}/start.d/security.ini INFO: servlet initialised (transitively) in ${jetty.base}/start.d/servlet.ini INFO: webapp initialised (transitively) in ${jetty.base}/start.d/webapp.ini INFO: deploy initialised in ${jetty.base}/start.d/deploy.ini MKDIR: ${jetty.base}/webapps INFO: Base directory was modified > cp $JETTY_HOME/demo-base/webapps/async-rest.war webapps/ROOT.war > java -jar $JETTY_HOME/start.jar 2015-06-04 11:10:16.286:INFO::main: Logging initialized @274ms 2015-06-04 11:10:16.440:INFO:oejs.Server:main: jetty-9.3.0.v20150601 2015-06-04 11:10:16.460:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///tmp/mybase/webapps/] at interval 1 2015-06-04 11:10:16.581:WARN::main: async-rest webapp is deployed. DO NOT USE IN PRODUCTION! 2015-06-04 11:10:16.589:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet 2015-06-04 11:10:16.628:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@1a407d53{/,[file:///tmp/jetty-0.0.0.0-8080-ROOT.war-_-any-4510228025526425427.dir/webapp/, jar:file:///tmp/jetty-0.0.0.0-8080-ROOT.war-_-any-4510228025526425427.dir/webapp/WEB-INF/lib/example-async-rest-jar-9.3.0.v20150601.jar!/META-INF/resources],AVAILABLE}{/ROOT.war} 2015-06-04 11:10:16.645:INFO:oejs.ServerConnector:main: Started ServerConnector@3abbfa04{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} 2015-06-04 11:10:16.646:INFO:oejs.Server:main: Started @634ms
以上命令是Linux下的命令,简单解释:创建一个JETTY_BASE环境变量,并创建指定的文件夹,在此文件夹下运行start.jar时提示没有可以启动的东西,系统退出,此时输入java -jar $JETTY_HOME/start.jar --add-to-startd=http,deploy命令为当前基目录添加标准文件及文件夹,然后java -jar $JETTY_HOME/start.jar运行即可运行成功。在Windows下操作如下:
> cd $JETTY_BASE > java -jar $JETTY_HOME/start.jar jetty.http.port=8081 ...
另外,可以将要设置的端口属性添加到start.ini或者start.d/http.ini文件中。默认情况,在start.d/http.ini文件中定义的jetty.http.port属性可以被修改成另一个值。
提示
配置属性信息通过如下方式获得
- 首先去start.d/http.ini文件中找jetty.http.port=8080配置信息,若找到配置端口即为指定端口
- 根据模块modules/http.mod文件找到指定配置默认为etc/jetty-http.xml,在此配置文件中有jetty.http.port配置信息,若找到即为此端口配置
- 若上面两个都没有,则随机一个没有使用的端口
> java -jar $JETTY_HOME/start.jar --add-to-startd=https,http2 [...] > java -jar $JETTY_HOME/start.jar [...] 2015-06-04 13:52:01.933:INFO:oejs.ServerConnector:main: Started ServerConnector@6f1fba17{SSL,[ssl, alpn, h2, http/1.1]}{0.0.0.0:8443} [...]
--add-to-startd:此命令在ini文件中设置有效的配置信息,使HTTPS和HTTP2支持SSL连接
> cd $JETTY_BASE > java -jar $JETTY_HOME/start.jar jetty.ssl.port=8444
除了在命令行增加参数的方法外,还可以在start.ini和start.d/*.ini文件中进行配置,所以如果用户使用--add-to-startd命令来使HTTPS生效,同样也可以在start.d/https.ini文件中进行修改。
> java -jar $JETTY_HOME/start.jar --help
提示
在Jetty9,只有Jetty基路径下的配置文件被编辑,属性才会被修改
Note
常见典型的模块配置信息通长很少被改动,*.mod文件通常位于$JETTY_HOME/modules/文件夹下,但是额外增加的或者编辑过的通常放在 $JETTY_BASE/module下,如果一个模块需要被修改,最好的做法是在修改前从$JETTY_HOME/modules/拷贝*.mod到 $JETTY_BASE/modules/
XML files:
xml文件一般用与IoC以及spring使用,用在命令行或者模块定义中。xml文件里面的配置将被注入到描述服务的一个对象里。通常改变属性的方法是改变对应的ini文件。xml文件通常放在$JETTY_HOME/etc/下,但是新增的或者被编辑的xml应该被放在 $JETTY_BASE/etc/下,如果xml配置文件有修改的必要,最好的做法是在修改前将xml文件从$JETTY_HOME/etc拷贝到$JETTY_BASE/etc/ 。Note
通常web应用的web.xml文件应该在WEB-INF/web.xml位置被发现,Jetty还支持多个web.xml,可以在 WEB-INF/web.xml文件加载前或者加载后加载(使用方法见test.xml)
// // ======================================================================== // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 // and Apache License v2.0 which accompanies this distribution. // // The Eclipse Public License is available at // http://www.eclipse.org/legal/epl-v10.html // // The Apache License v2.0 is available at // http://www.opensource.org/licenses/apache2.0.php // // You may elect to redistribute this code under either of these licenses. // ======================================================================== // package org.eclipse.jetty.embedded; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.servlet.ServletContextHandler; public class ExampleServer { public static void main( String[] args ) throws Exception { Server server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setPort(8080); server.setConnectors(new Connector[] { connector }); ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(HelloServlet.class, "/hello"); context.addServlet(AsyncEchoServlet.class, "/echo/*"); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] { context, new DefaultHandler() }); server.setHandler(handlers); server.start(); server.join(); } }
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> <Configure id="ExampleServer" class="org.eclipse.jetty.server.Server"> <Set name="connectors"> <Array type="org.eclipse.jetty.server.Connector"> <Item> <New class="org.eclipse.jetty.server.ServerConnector"> <Arg><Ref refid="ExampleServer"/></Arg> <Set name="port">8080</Set> </New> </Item> </Array> </Set> <New id="context" class="org.eclipse.jetty.servlet.ServletContextHandler"> <Set name="contextPath">/hello</Set> <Call name="addServlet"> <Arg>org.eclipse.jetty.embedded.HelloServlet</Arg> <Arg>/</Arg> </Call> </New> <Set name="handler"> <New class="org.eclipse.jetty.server.handler.HandlerCollection"> <Set name="handlers"> <Array type="org.eclipse.jetty.server.Handler"> <Item> <Ref refid="context" /> </Item> <Item> <New class="org.eclipse.jetty.server.handler.DefaultHandler" /> </Item> </Array> </Set> </New> </Set> </Configure>
Note
虚拟主机不能配置连接,用户应该通过虚拟主机的context来实现它们的相应。
Note
Jetty9同时支持连接协议(HTTP,HTTPS,AJP,SPDY)和自然连接(NIO或者BIO),Jetty9以后只有一个主要的连接器ServerConnector
Note
servlet规范定一个web应用。在Jetty规范中一个标准的web项目必须有一个标准的WEB-INF/web.xml文件,用来配置classpath,资源,session处理,登录,以及servlet,jsp,以及静态资源。标准的web应用需要很少的额外的配置文件。
// // ======================================================================== // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 // and Apache License v2.0 which accompanies this distribution. // // The Eclipse Public License is available at // http://www.eclipse.org/legal/epl-v10.html // // The Apache License v2.0 is available at // http://www.opensource.org/licenses/apache2.0.php // // You may elect to redistribute this code under either of these licenses. // ======================================================================== // package org.eclipse.jetty.embedded; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandler; public class OneContext { public static void main( String[] args ) throws Exception { Server server = new Server( 8080 ); // Add a single handler on context "/hello" ContextHandler context = new ContextHandler(); context.setContextPath( "/hello" ); context.setHandler( new HelloHandler() ); // Can be accessed using http://localhost:8080/hello server.setHandler( context ); // Start the server server.start(); server.join(); } }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <!-- Configure a custom context for serving javadoc as static resources --> <Configure class="org.eclipse.jetty.server.handler.ContextHandler"> <Set name="contextPath">/javadoc</Set> <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc/</Set> <Set name="handler"> <New class="org.eclipse.jetty.server.handler.ResourceHandler"> <Set name="welcomeFiles"> <Array type="String"> <Item>index.html</Item> </Array> </Set> <Set name="cacheControl">max-age=3600,public</Set> </New> </Set> </Configure>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/contextpath</Set> </Configure>
还有一种做法是,不用增加配置文件,在war文件同目录,建一个同名的xml文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test.war</Set> <Set name="contextPath">/test</Set> </Configure>
配置例子可以参照$JETTY_HOME/webapps/test.xml
... <login-config> <auth-method>BASIC</auth-method> <realm-name>Test Realm</realm-name> </login-config> ...
这个例子使用名为Test Realm.的验证,但是没有说明其是怎么实现的,在Jetty中有几种实现方式,其中一种是HashLoginService可以读取登录用户,并在配置文件中查找,为了配置HashLoginService用来匹配Test Realm,可以配置$JETTY_BASE/etc/test-realm.xml文件,并且该文件必须在start.ini或者start.d/server.ini中设置。
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-" "http://www.eclipse.org/jetty/configure_9_3.dtd"> <Configure id="Server" class="org.eclipse.jetty.server.Server"> <!-- =========================================================== --> <!-- Configure Authentication Login Service --> <!-- Realms may be configured for the entire server here, or --> <!-- they can be configured for a specific web app in a context --> <!-- configuration (see $(jetty.home)/webapps/test.xml for an --> <!-- example). --> <!-- =========================================================== --> <Call name="addBean"> <Arg> <New class="org.eclipse.jetty.security.HashLoginService"> <Set name="name">Test Realm</Set> <Set name="config"><Property name="jetty.demo.realm" default="etc/realm.properties"/></Set> <Set name="refreshInterval">0</Set> </New> </Arg> </Call> <Get class="org.eclipse.jetty.util.log.Log" name="rootLogger"> <Call name="warn"><Arg>demo test-realm is deployed. DO NOT USE IN PRODUCTION!</Arg></Call> </Get> </Configure>
通过创建和配置LoginService到web应用中,当部署应用时,会通过名字去寻找匹配的登录Service。
参考 https://www.cnblogs.com/yiwangzhibujian/p/5832597.html
标签:怎么 ash 独立 客户 ecb login 单位 initial 网络协议
原文地址:https://www.cnblogs.com/xd502djj/p/10319793.html