import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import javax.jws.WebService;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.xml.ws.Endpoint;
import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
@WebService(targetNamespace="http://hello/")
public class HelloWorld {
public String sayHi(){
return "Hello World!";
}
public static void main(String[] args) throws CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException {
try {
SSLContext ssl = SSLContext.getInstance("TLS");
KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore store = KeyStore.getInstance("JKS");
String keystoreFile="hello.keystore";
String keyPass="changeit";
store.load(new FileInputStream(keystoreFile),keyPass.toCharArray());
keyFactory.init(store, keyPass.toCharArray());
TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustFactory.init(store);
KeyManager[] keyManagers=new KeyManager[1];
keyManagers=keyFactory.getKeyManagers();
TrustManager[] trustManagers=trustFactory.getTrustManagers();
ssl.init(keyManagers, trustManagers, new SecureRandom());
HttpsConfigurator configurator = new HttpsConfigurator(ssl);
HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress("localhost", 8440),8440);
httpsServer.setHttpsConfigurator(configurator);
HttpContext httpContext = httpsServer.createContext("/Hello");
httpsServer.start();
Endpoint endpoint = Endpoint.create(new HelloWorld());
endpoint.publish(httpContext);
} catch (NoSuchAlgorithmException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (KeyStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeyManagementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Java6开发的web service,发布https的wsdl地址
共5个文件
class:1个
project:1个
classpath:1个
5星 · 超过95%的资源 需积分: 9 43 下载量 85 浏览量
2011-11-02
12:56:36
上传
评论
收藏 5KB RAR 举报
温馨提示
配合http://blog.csdn.net/greenqingqingws/article/details/6927794博客的源代码。供大家参考。
资源推荐
资源详情
资源评论
收起资源包目录
HelloWorld.rar (5个子文件)
HelloWorld
src
HelloWorld.java 3KB
bin
HelloWorld.class 4KB
.classpath 232B
.project 386B
hello.keystore 1KB
共 5 条
- 1
青青木屋
- 粉丝: 295
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页