手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Jetty和Maven HelloWorld

[日期:2014-11-19] 来源:Linux社区  作者:fan_hai_ping [字体:大 中 小]

启用SSL

      在嵌入式Jetty 9中启用SSL的过程如下:

      1)首先使用解释安全方案和端口的HTTP配置创建一个HttpConfiguration。

HttpConfiguration http_config = newHttpConfiguration();

http_config.setSecureScheme("https");

http_config.setSecurePort(8443);

      然后,我们为从上面的配置中扩展的https创建另外一个HttpConfiguration,但是添加一个SecureRequestCustomizer。

HttpConfiguration https_config = newHttpConfiguration(http_config);

https_config.addCustomizer(newSecureRequestCustomizer());

      3)接下来创建一个SslContexFactory指向你的JavaKeystore文件。

SslContextFactory sslContextFactory = newSslContextFactory("/its_dir/cert.keystore");

sslContextFactory.setKeyStorePassword("password");

      注意:你能使用OBF前缀密码,如果你打算使用Jetty模糊的密码。

    4)接下来我们创建一个ServerConnector,传递给它Server类,SslConnectorFactory和HttpConnectionFactory。如下:

ServerConnector httpsConnector = newServerConnector(server,

      new SslConnectionFactory(sslContextFactory, "http/1.1"),

      new HttpConnectionFactory(https_config));

httpsConnector.setPort(8443);

httpsConnector.setIdleTimeout(50000);     

      最后使用这个连接给服务,与正常的HTPP ServerConnector一样。

server.setConnectors(new Connector[]{httpsConnector });

与Jersey一起使用

官方网址:https://jersey.java.net/

文档网址:https://jersey.java.net/documentation/latest/index.html

下载网址:

      你能在代码中混合使用Jersey的2个版本,来自Jersey2.x(org.glassfish.jersey*包)中的ServletContainer和来自Jersey 1.x(包前缀com.sum.jersey.*)的属性。

      为了使用Jersey2.x开发你的应用,修改下面两行:

h.setInitParameter("com.sun.jersey.config.property.resourceConfigClass","com.sun.jersey.api.core.PackagesResourceConfig");

h.setInitParameter("com.sun.jersey.config.property.packages","resources");

      从main方法到下面函数中:

      h.setInitParameter(ServerProperties.PROVIDER_PACKAGES,"resources");

      并且检查其他ServerProperties,你可能找到有用的。

Jetty 的详细介绍:请点这里
Jetty 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-11/109573.htm

linux
相关资讯       Jetty  Maven 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款