我有一个使用Grails的应用程序,它通过org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter公开Web服务:
<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
<property name="baseAddress" value="http://0.0.0.0:8091/api/"/>
</bean>
我按照本指南http://www.codeghost.co.uk/post/50912832626/https-with-java-6-web-services为这些Web服务配置了HTTPS,这是我得到的代码:
<bean class="org.springframework.remoting.jaxws.SimpleHttpServerJaxWsServiceExporter">
<property name="server" ref="httpsServer" />
<property name="basePath" value="/api/" />
</bean>
<!-- HTTPS Server -->
<bean id="httpsServer" class="com.sun.net.httpserver.HttpsServer" factory-method="create" init-method="start" autowire="byName">
<constructor-arg ref="httpsServerSocket" />
<constructor-arg value="0"/>
</bean>
<!-- HTTPS Server Socket -->
<bean id="httpsServerSocket" class="java.net.InetSocketAddress">
<constructor-arg value="0.0.0.0"/>
<constructor-arg value="8092"/>
</bean>
<!-- HTTPS Configurator -->
<bean id="httpsConfigurator" class="com.sun.net.httpserver.HttpsConfigurator">
<constructor-arg ref="sslContext"/>
</bean>
<bean id="sslContext" class="com.application.config.HttpsConfigurator" factory-method="getSSLContext">
<constructor-arg value="${keystore.filename}" />
<constructor-arg value="${keystore.password}" />
<constructor-arg value="${keystore.cryptstore.password}" />
</bean>
com.application.config.HttpsConfigurator.getSSLContext()如下:
public static SSLContext getSSLContext(String keyStoreName,
String keyStorePassword, String cryptStorePassword) throws Exception {
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(new FileInputStream(keyStoreName),
keyStorePassword.toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyManagerFactory.init(keyStore, cryptStorePassword.toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509");
trustManagerFactory.init(keyStore);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
return sslContext;
}
如果我使用run-app
Grails命令运行应用程序,则可以在https://localhost:8092/api/service?wsdl访问Web服务,但是当我在Tomcat上部署war时,相同的地址将返回500 Internal Server Error,对于上下文。这是无需编辑Tomcat的server.xml的配置。
我尝试在server.xml上使用此HTTPS配置来启动tomcat,但是由于地址(https://localhost:8092)已被使用,因此我从应用程序中获取了异常:
<Connector port="8092" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="200" scheme="https" secure="true" SSLEnabled="true"
keystoreFile="${user.home}/.keystore" keystorePass="password"
clientAuth="false" sslProtocol="TLS" />
如果将端口更改为另一个端口,则结果始终为500 Internal Server Error,没有上下文处理程序。
有人对我的缺失或做错事有任何想法吗?