1

我有一个关于使用 javax.xml.ws.Provider 以编程方式为 CXF 前端配置 SSL 的问题。

基本上我已经实现了一个简单的Restful webservice,比如

@WebServiceProvider()
@ServiceMode(value = Service.Mode.PAYLOAD)
public class RestWebServiceProvider implements Provider<DOMSource> {
    ...
}

并用类似的代码发布它

public class RestServer {

    protected RestServer() throws Exception {
        System.out.println("Starting Server");
        Endpoint e = Endpoint.create(HTTPBinding.HTTP_BINDING, new RestWebServiceProvider() );
        String address = "http://localhost:9000/rest/test";
        e.publish(address);

    }

    public static void main(String args[]) throws Exception {
        new RestServer();
        System.out.println("Server ready...");

        Thread.sleep(5 * 60 * 1000);
        System.out.println("Server exiting");
        System.exit(0);
    }

}

与 CXF 下载的示例文件夹中的 restful_dispatch 示例项目完全一样。

现在我想要实现的是以编程方式配置 SSL,而不是使用 XML。

为什么?因此,可以在运行时从浏览器配置 SSL,而无需重新启动 Web 应用程序。

我做了一些功课,看到示例项目 /jax_rs/basic_https 是这样做的

 static {
    // set the configuration file
    SpringBusFactory factory = new SpringBusFactory();
    Bus bus = factory.createBus("ServerConfig.xml");
    BusFactory.setDefaultBus(bus);
}

在 Server 类中,ServerConfig.xml 定义了实际的 SSL 配置。但这对于我的用例来说不够灵活。

我已经对 stackoverflow 进行了一些挖掘,我发现的最佳链接似乎来自带有 HTTPS 的 javax.xml.ws.Endpoint

我自己还没有尝试过这种方法,但是如果这是你的专家所做的或者是否有更好的方法,我正在徘徊。

以前有没有人做过这样的事情并愿意分享一些建议?

谢谢

山姆

4

0 回答 0