[英]Using javax.xml.ws.Endpoint with HTTPS
I'm working on a project to control light and heating in buildings. 我正在研究控制建筑物的光和热的项目。 The backend (written in Java) will run on a Mac Mini and should be accessible via SOAP.
后端(用Java编写)将在Mac Mini上运行,并且应该可以通过SOAP进行访问。
I want to keep the complexity of this project to a minimum because I don't want everyone using it having to set up an application server. 我希望将此项目的复杂性降至最低,因为我不希望每个使用它的人都必须设置应用程序服务器。 So up till now I worked with javax.xml.ws.Endpoint:
所以直到现在我都使用javax.xml.ws.Endpoint:
Endpoint endpoint = Endpoint.create(frontendInterface);
String uri = "http://"+config.getHost()+":"+config.getPort()+config.getPath();
endpoint.publish(uri);
This works surprisingly well (hey, when did you last see something in Java working with just 3 lines of code?), but now I'm looking for a way to use HTTPS instead of HTTP. 这样的效果出奇的好(嘿,您什么时候最后一次只用3行代码看到Java中的东西?),但是现在我正在寻找一种使用HTTPS而不是HTTP的方法。
Is there a way to do this without using an application server or is there another way to secure this connection? 有没有可以在不使用应用程序服务器的情况下执行此操作的方法,还是有另一种方法可以保护此连接的安全?
Greetings, Marek 问候,Marek
For server: 对于服务器:
SSLContext ssl = SSLContext.getInstance("TLS");
KeyManagerFactory keyFactory = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore store = KeyStore.getInstance("JKS");
store.load(new FileInputStream(keystoreFile),keyPass.toCharArray());
keyFactory.init(store, keyPass.toCharArray());
TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustFactory.init(store);
ssl.init(keyFactory.getKeyManagers(),
trustFactory.getTrustManagers(), new SecureRandom());
HttpsConfigurator configurator = new HttpsConfigurator(ssl);
HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(hostname, port), port);
httpsServer.setHttpsConfigurator(configurator);
HttpContext httpContext = httpsServer.createContext(uri);
httpsServer.start();
endpoint.publish(httpContext);
For client, be sure you do this: 对于客户,请确保您执行以下操作:
System.setProperty("javax.net.ssl.trustStore", "path");
System.setProperty("javax.net.ssl.keyStore", "password");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
//done to prevent CN verification in client keystore
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.