axis2---5--2

来源:互联网 发布:js 定义json对象 编辑:程序博客网 时间:2024/04/30 02:30
/** * 获得指定文件的byte数组 */public static byte[] getBytes(String filePath) {byte[] buffer = null;try {File file = new File(filePath);FileInputStream fis = new FileInputStream(file);ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);byte[] b = new byte[1000];int n;while ((n = fis.read(b)) != -1) {bos.write(b, 0, n);}fis.close();bos.close();buffer = bos.toByteArray();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return buffer;}/** * 根据byte数组,生成文件 */public static void getFile(byte[] bfile, String filePath, String fileName) {BufferedOutputStream bos = null;FileOutputStream fos = null;File file = null;try {File dir = new File(filePath);if (!dir.exists() && dir.isDirectory()) {// 判断文件目录是否存在dir.mkdirs();}file = new File(filePath + "\\" + fileName);fos = new FileOutputStream(file);bos = new BufferedOutputStream(fos);bos.write(bfile);} catch (Exception e) {e.printStackTrace();} finally {if (bos != null) {try {bos.close();} catch (IOException e1) {e1.printStackTrace();}}if (fos != null) {try {fos.close();} catch (IOException e1) {e1.printStackTrace();}}}}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 = "test-server.keystore";String keyPass = "testserver";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("10.50.131.59", 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 blocke1.printStackTrace();} catch (KeyStoreException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (KeyManagementException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}

0 0