2014-03-30 112 views
2

我使用下面的代码发布ssl webservice。当我浏览https://localhost/它给我这个错误:WebService错误:404找不到 - 找不到请求的上下文

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); 

我怎么能解决这个问题,为什么这个问题occures?

回答

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 它的工作。