简体   繁体   English

在Citrus Simulator中使用HTTPS

[英]Using HTTPS with Citrus Simulator

I am cureently evaluating Citrus Simulator for writing Mocks for Rest Services. 我正在积极评估Citrus Simulator编写Mocks for Rest Services的技巧。 It looks promising, but I couldn't find out how to use HTTPS instead of HTTP while trying to setup a REST Service. 看起来很有希望,但是在尝试设置REST服务时,我找不到如何使用HTTPS而不是HTTP的方法。 Nothing found in the user Manual as well. 在用户手册中也找不到任何内容。 Does somebody already tried that succesfully? 有人已经成功尝试过吗?

Looking into the underlying product citrusframework delivered half the answer, thx to Korashen for the tipp. 研究底层产品柑橘框架只能得到一半的答案,这要付给Korashen小费。

The relevant change is to set the correct endpoint adapter. 相关更改是设置正确的端点适配器。 For others looking for a solution: 对于其他寻求解决方案的人:

@Autowired
private SimulatorEndpointAdapter simulatorEndpointAdapter;

@Bean
public HttpServer buildSslServer() throws Exception {
    return CitrusEndpoints.http()
            .server()
            .port(8080)
            .endpointAdapter(simulatorEndpointAdapter)
            .connector(sslConnector())
            .autoStart(true)
            .build();
}

@Bean
public ServerConnector sslConnector() {
    ServerConnector connector = new ServerConnector(new Server(),
            new SslConnectionFactory(sslContextFactory(), "http/1.1"),
            new HttpConnectionFactory(httpConfiguration()));
    connector.setPort(securePort);
    return connector;
}

private HttpConfiguration httpConfiguration() {
    HttpConfiguration parent = new HttpConfiguration();
    parent.setSecureScheme("https");
    parent.setSecurePort(securePort);
    HttpConfiguration configuration = new HttpConfiguration(parent);
    configuration.setCustomizers(Collections.singletonList(new SecureRequestCustomizer()));
    return configuration;
}

private SslContextFactory sslContextFactory() {
    SslContextFactory contextFactory = new SslContextFactory();
    contextFactory.setKeyStorePath(sslKeyStorePath);
    contextFactory.setKeyStorePassword("secret");
    return contextFactory;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM