[英]How to publish SOAP web service over HTTPS in java
我正在嘗試通過HTTPS發布SOAP Web服務。 我可以使一切正常運行,但是無法在瀏覽器中訪問該服務。
下面提供的是我與端點一起發布的SSL和服務器設置。 我確保來自KeyStore的證書位於我的瀏覽器和計算機的信任庫中。
SOAP服務
@WebService(name = "TestService")
@SOAPBinding
public interface TestService {
@WebMethod
void test();
}
服務實施
@MTOM
@WebService(
targetNamespace = "https://localhost",
endpointInterface = "bootstrap.TestService",
portName = "TestPort",
serviceName = "TestService"
)
public class TestServiceImpl implements TestService {
@Override
public void test() {
System.out.println("Hello");
}
}
SSL設置
SSLContext sslContext = SSLContext.getInstance("SSL");
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
store.load(EndpointPublisher.class.getResourceAsStream("KeyStore.ks"), "password".toCharArray());
System.setProperty("javax.net.ssl.keyStore", "/bootstrap/dev/KeyStore.ks");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
keyManagerFactory.init(store, "password".toCharArray());
trustManagerFactory.init(store);
KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
sslContext.init(keyManagers, trustManagers, new SecureRandom());
服務器設置
String host = "localhost";
int port = 8080;
String uri = "/test";
TestService service = new TestServiceImpl();
HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(host, port), port);
httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
HttpContext context = httpsServer.createContext(uri);
httpsServer.start();
Endpoint endpoint = Endpoint.create(service);
endpoint.publish(context);
我希望在連接到時能看到wsdl
https://localhost:8080/test?wsdl
但是,我得到
無法訪問該網站
本地主機意外關閉了連接。
嘗試:
Checking the connection
Checking the proxy and the firewall
Running Windows Network Diagnostics
ERR_CONNECTION_CLOSED
請按照以下步驟操作:
檢查狀態的步驟打開CMD並鍵入:netstat -na | findstr 8443看到它的狀態是LISTENING嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.