HTTPS 客户端发送请求(二)

https 完整web开发

Tomcat 6.0 配置

1、生成安全访问的证书。命令行下执行:keytool -genkey -alias tomcat -keyalg RSA -keystore c:\tomcat.keystore然后按提示输入一些密码等信息:输入keystore密码:再次输入新密码:您的名字与姓氏是什么? [Unknown]: tomcat您的组织单位名称是什么? [Unknown]: tomcat您的组织名称是什么? [Unknown]: tomcat您所在的城市或区域名称是什么? [Unknown]: bj您所在的州或省份名称是什么? [Unknown]: bj该单位的两字母国家代码是什么 [Unknown]: cnCN=tomcat, OU=tomcat, O=tomcat, L=bj, ST=bj, C=cn 正确吗? [否]: y输入<tomcat>的主密码 (如果和 keystore 密码相同,按回车):输入完成后,会在C盘下生成tomcat.keystore文件,这个文件的位置不做要求。注:上述命令中的蓝色部分可以不输入,这样会默认生成一个.keystore的证书文件。2、配置tomcat,使其支持https连接。打开tomcat目录下conf/server.xml文件,将之前的连接部分注释,找到以下节点:

<!– Define a SSL HTTP/1.1 Connector on port 8443This connector uses the JSSE configuration, when using APR, theconnector should be using the OpenSSL style configurationdescribed in the APR documentation –><!–<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"maxThreads="150" scheme="https" secure="true"clientAuth="false" sslProtocol="TLS" />–>

将<connectore节点的注释去掉,8443修改为你要使用的端口。节点中添加两个属性:keystoreFile="C:/tomcat.keystore" keystorePass="123456"其中,keystoreFile指的是你第一步生成的证书文件位置,keystorePass是你在生成证书时所输入的密码。通过以上两步操作,基本上就可以使用https访问tomcat连接了,不过我在使用tomcat6配置的时候,,启动tomcat报错:

2011-9-8 10:11:20 org.apache.catalina.core.AprLifecycleListener init 信息: Loaded APR based Apache Tomcat Native library 1.1.20. 2011-9-8 10:11:20 org.apache.catalina.core.AprLifecycleListener init 信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. 2011-9-8 10:11:20 org.apache.catalina.startup.SetAllPropertiesRule begin 警告: [SetAllPropertiesRule]{Server/Service/Connector} Setting property 'keystoreFile' to 'C:\tomcat.keystore' did not find a matching property. 2011-9-8 10:11:20 org.apache.catalina.startup.SetAllPropertiesRule begin 警告: [SetAllPropertiesRule]{Server/Service/Connector} Setting property 'keystorePass' to 'mvtech' did not find a matching property. 2011-9-8 10:11:20 org.apache.catalina.startup.SetAllPropertiesRule begin 警告: [SetAllPropertiesRule]{Server/Service/Connector} Setting property 'clientAuth' to 'false' did not find a matching property. 2011-9-8 10:11:20 org.apache.coyote.http11.Http11AprProtocol init 严重: Error initializing endpoint java.lang.Exception: No Certificate file specified or invalid file format at org.apache.tomcat.jni.SSLContext.setCertificate(Native Method) at org.apache.tomcat.util.net.AprEndpoint.init(AprEndpoint.java:720) at org.apache.coyote.http11.Http11AprProtocol.init(Http11AprProtocol.java:107) at org.apache.catalina.connector.Connector.initialize(Connector.java:1014) at org.apache.catalina.core.StandardService.initialize(StandardService.java:680) at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:795) at org.apache.catalina.startup.Catalina.load(Catalina.java:524) at org.apache.catalina.startup.Catalina.load(Catalina.java:548) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) 2011-9-8 10:11:20 org.apache.catalina.startup.Catalina load 严重: Catalina.start LifecycleException: Protocol handler initialization failed: java.lang.Exception: No Certificate file specified or invalid file format at org.apache.catalina.connector.Connector.initialize(Connector.java:1016) at org.apache.catalina.core.StandardService.initialize(StandardService.java:680) at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:795) at org.apache.catalina.startup.Catalina.load(Catalina.java:524) at org.apache.catalina.startup.Catalina.load(Catalina.java:548) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)没有一种不通过蔑视、忍受和奋斗就可以征服的命运。

HTTPS 客户端发送请求(二)

相关文章:

你感兴趣的文章:

标签云: