简体   繁体   English

在HTTPS中使用javax.xml.ws.Endpoint

[英]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.

相关问题 不支持基于https协议的地址-javax.xml.ws.Endpoint - https protocol based address is not supported - javax.xml.ws.Endpoint 'javax.xml.ws.Endpoint'和2种方式SSL - 'javax.xml.ws.Endpoint' and 2 ways SSL 导入Javax.xml.ws.Endpoint出现错误 - import Javax.xml.ws.Endpoint got error Javax.xml.ws.Endpoint如何处理多个连接? - Javax.xml.ws.Endpoint how does it deal with multiple connections? 使用javax.xml.ws.Endpoint公开Java Web服务的局限性? - Limitations of exposing Java web services using javax.xml.ws.Endpoint? ClassNotFoundException:javax.xml.ws.Endpoint 尽管具有正确的(?)maven 依赖项并且仅在 CLI 中 - ClassNotFoundException: javax.xml.ws.Endpoint despite having the correct(?) maven dependency and only in CLI “异常javax.xml.ws.WebServiceException:不支持的端点地址”尝试使用JAX-WS 2.1调用Web服务 - “Exception javax.xml.ws.WebServiceException: Unsupported endpoint address” trying to call web service using JAX-WS 2.1 使用javax.ws.rs将XML转换为带有反斜杠的json - XML into json coming with backslash using javax.ws.rs 使用javax.xml.namespace.Qname和javax.xml.ws.handler.PortInfo的Classcast异常 - Classcast exception using javax.xml.namespace.Qname and javax.xml.ws.handler.PortInfo Java WebService抛出带有无效端点接口的javax.xml.ws.WebServiceException - Java WebService throwing javax.xml.ws.WebServiceException with Invalid Endpoint Interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM