Restlet - 如何使用HTTP / HTTPS公开资源?

时间:2017-03-14 21:01:36

标签: java ssl keystore restlet

使用restlet 2.3.1。我是通过HTTP公开的资源。是否可以通过HTTPS公开它?以下代码段显示了我的服务器今天的样子:

final Router router = new Router();

Filter filter = new Filter(){};

filter.setNext( DaemonsResource.class );
router.attach( "daemons/{p1}", filter );

Application myApp = new Application() 
{
    @Override
    public org.restlet.Restlet createInboundRoot()
    {
        router.setContext(getContext());

        return router;
    };
};

Component component = new Component();

component.getDefaultHost().attach( "/", myApp );

new Server( Protocol.HTTP, port, component ).start();

我已经从CA获得了crt,并在其上构建了密钥库。

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试类似:

Component component = new Component();
Server server = component.getServers().add(Protocol.HTTPS, 8082);

component.getDefaultHost().attach( "/", myApp );
component.start();

请参阅restlet tutorials

设置密钥库等

Series<Parameter> parameters = server.getContext().getParameters();
parameters.add("keystorePath","add_keystore_file_path_here"));
parameters.add("keystorePassword", "mypassword");
parameters.add("keyPassword", "mypassword");
parameters.add("keystoreType", "PKCS12");  

// Start the component.
component.start(); 

请参阅restlet mailing list此消息有点过时但参数仍应相同