WebService错误:404未找到 - 未找到请求的上下文

时间:2014-03-30 06:07:37

标签: java web-services

我使用下面的代码发布ssl Web服务。当我浏览https://localhost/时,它会给我这个错误:

404 Not Found

No context found for request

代码:

Endpoint endpoint = Endpoint.create(new TicketQueryImpl());
        javax.net.ssl.SSLContext ssl = javax.net.ssl.SSLContext.getInstance("TLS");
        javax.net.ssl.KeyManagerFactory keyFactory = javax.net.ssl.KeyManagerFactory
                .getInstance(javax.net.ssl.KeyManagerFactory.getDefaultAlgorithm());
        KeyStore store = KeyStore.getInstance("JKS");

        store.load(new FileInputStream("c:/thekey.txt"), "password".toCharArray());
        keyFactory.init(store, "password".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("localhost", 443), 443);
        httpsServer.setHttpsConfigurator(configurator);
        HttpContext httpContext = httpsServer.createContext("/127.0.0.1:443/");
        httpsServer.start();

        endpoint.publish(httpContext);

我该如何解决这个问题,以及为什么会出现这个问题?

1 个答案:

答案 0 :(得分:2)

我多么愚蠢。 https.createContext(uri)中的URI不是整个路径的URI。我改变了

HttpContext httpContext = httpsServer.createContext("/127.0.0.1:443/");

HttpContext httpContext = httpsServer.createContext("/test");

然后浏览https://127.0.0.1/test?wsdl 有效。