如何在Java中通过HTTPS发布SOAP Web服务

问题描述 投票:0回答:1

我正在尝试通过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

但是,我得到

无法访问此网站

localhost意外关闭了连接。

尝试:

 Checking the connection

 Checking the proxy and the firewall

 Running Windows Network Diagnostics

 ERR_CONNECTION_CLOSED
java ssl soap
1个回答
0
投票

请执行以下步骤:

  • 将端口更改为8443
  • 启动Web服务

用于检查状态打开CMD并输入:netstat -na | findstr 8443查看其状态是否为“正在侦听”?

© www.soinside.com 2019 - 2024. All rights reserved.