使用 Spring IoC 配置 SSL Restlet 服务器?

Configuring SSL Restlet server with Spring IoC?

所以,google 今天没用。

this page,但它向您展示了如何在 code 中设置 SSL restlet。

Spring XML 你是怎么做到的?

这是我现在拥有的:

<bean id="container" class="org.restlet.ext.spring.SpringComponent">
            <property name="server">
                    <bean class="org.restlet.ext.spring.SpringServer">
                            <constructor-arg value="http" />
                            <constructor-arg value="3080" />
                    </bean> 
            </property>     
            <property name="defaultTarget" ref="router"/>
    </bean> 

我可以只使用构造函数参数 "https" 和“3443”,但是如何设置服务器密钥的密钥库位置以及密码和类型以及 yadda yadda yadda?

遇到了类似的问题,我已经通过以下方式解决了。

在我的 属性 文件中,我有以下内容:

trustStore.path = /path/to/certificate/cert.jks
trustStore.password = CertPassword

并且在 xml- 配置中:

<bean id="trustStore" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject" value="#{@systemProperties}" />
    <property name="targetMethod" value="putAll" />
    <property name="arguments">
        <props>
            <prop key="javax.net.ssl.trustStore">${trustStore.path}</prop>
            <prop key="javax.net.ssl.trustStorePassword">${trustStore.password}</prop>
        </props>
    </property>
</bean>

这个例子怎么样?

Java:

import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class RestletApplication extends ServerResource {
    @Get
    public String present() {
        return "hello, world";
    }

    public static void main(String... args) throws Exception {
        new ClassPathXmlApplicationContext("restlet-context.xml").registerShutdownHook();
    }
}

Spring:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="top" class="org.restlet.ext.spring.SpringComponent" init-method="start" destroy-method="stop">
        <property name="server">
            <bean class="org.restlet.ext.spring.SpringServer">
                <constructor-arg value="https"/>
                <constructor-arg value="8183"/>
                <property name="parameters">
                    <props>
                        <prop key="sslContextFactory">org.restlet.engine.ssl.DefaultSslContextFactory</prop>
                        <prop key="keyStorePath">/my/path/to/serverX.jks</prop>
                        <prop key="keyStorePassword">password</prop>
                        <prop key="keyPassword">password</prop>
                        <prop key="keyStoreType">JKS</prop>
                    </props>
                </property>
            </bean>
        </property>
        <property name="defaultTarget">
            <bean class="org.restlet.ext.spring.SpringRouter">
                <property name="attachments">
                    <map>
                        <entry key="/v1" value="RestletApplication"/>
                    </map>
                </property>
            </bean>
        </property>
    </bean>
</beans>

似乎适用于 Restlets 2.3.4。

基于: