/**
* Program : WebServiceUtil.java
* Author : leigq
* Create : 2010-11-12 上午09:02:05
*
* Copyright 2010 by Embedded Internet Solutions Inc.,
* All rights reserved.
*
* This software is the confidential and proprietary information
* of Embedded Internet Solutions Inc.("Confidential Information").
* You shall not disclose such Confidential Information and shall
* use it only in accordance with the terms of the license agreement
* you entered into with Embedded Internet Solutions Inc.
*
*/ package cn.ipanel.apps.portalBackOffice.util; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import org.apache.log4j.Logger; import cn.ipanel.apps.portalBackOffice.define.Defines;
import cn.ipanel.apps.portalBackOffice.domain.WSAddress; /**
* webService 工具类
*/
public class WebServiceUtil { private Properties properties = new Properties(); private static Logger logger = Logger.getLogger(WebServiceUtil.class); public WebServiceUtil() {
properties = PropertyManager.getConfig();
} /**
* 获取WebService配置信息,返回的数据格式为
* @return List<WSAddress>
*/
public List<WSAddress> getWebServers() {
List<WSAddress> result = new ArrayList<WSAddress>(); Enumeration<?> enu = properties.propertyNames();
Pattern pattern = Pattern.compile("^(wsAddress)X?");
CONTINUE_POINT: while (enu.hasMoreElements()) {
try {
String key = (String) enu.nextElement();
Matcher matcher = pattern.matcher(key);
if (!matcher.find())
continue; String propertityValue = (String) properties.get(key);
// 如果不是以';'分隔的,则不处理
if (propertityValue.indexOf(";") == -1)
continue; String[] values = propertityValue.split(";");
// 如果不是三段规则,则不处理
if (values.length != 4)
continue; for (int i = 0; i < values.length; i++)
if (values[i] == null || values[i].trim().length() == 0)
continue CONTINUE_POINT; result.add(new WSAddress(key, values[0], values[1], values[2],values[3]));
} catch (Exception e) {
logger.warn(e);
}
}
return result;
} /**
* 检测此key值是否已经被使用,若重复使用相同key值,会以新的配置覆盖旧的配置
* @param key
* @return
*/
public boolean checkKeyIsExist(String key) {
Set<Object> keys = properties.keySet();
if (keys.contains(key))
return true;
return false;
}
/**
* 保存WebService配置到property文件
* @param wsAddress
* @return
*/
public boolean storWSAddress(WSAddress wsAddress){
if (wsAddress == null || checkWSAddressValue(wsAddress))
throw new RuntimeException("参数不正确,请检查."); String wsProperty = wsAddress.getAddress() + ";" + wsAddress.getAccessFolder() + ";" + wsAddress.getPublishFolder() + ";" + wsAddress.getVisitURL();
String wsKey = wsAddress.getWsName(); properties.setProperty(wsKey, wsProperty);
try {
properties.store(new FileOutputStream(new File(Defines.CONFIG_FILE_PATH)), null);
} catch (IOException e) {
throw new RuntimeException("属性配置存储失败,请检查.");
}
return true;
}
/**
* 移除webService配置
* @param key
* @return
* @throws FileNotFoundException
* @throws IOException
*/
public boolean removeWSAddress(String key){
try {
properties.remove(key);
properties.store(new FileOutputStream(new File(Defines.CONFIG_FILE_PATH)), "");
return true;
} catch (FileNotFoundException e) {
throw new RuntimeException("配置文件未找到,请检查.");
} catch (IOException e) {
throw new RuntimeException("文件存储失败,请检查.");
} } /**
* 检测参数是否正确,任何错误或空值都抛异常
* @param wsAddress
*/
private boolean checkWSAddressValue(WSAddress wsAddress) {
String wsName = wsAddress.getWsName();
if (wsName == null || wsName.trim().length() == 0)
throw new RuntimeException("参数: wsName为空,请检查."); String publishFolder = wsAddress.getPublishFolder();
if (publishFolder == null || publishFolder.trim().length() == 0 || publishFolder.indexOf(";") != -1)
throw new RuntimeException("参数: publishFolder为空或包含非法字符:';',请检查."); String address = wsAddress.getAddress();
if (address == null || address.trim().length() == 0 || address.indexOf(";") != -1)
throw new RuntimeException("参数: wsAddress为空或包含非法字符:';',请检查."); String accessFolder = wsAddress.getAccessFolder();
if (accessFolder == null || accessFolder.trim().length() == 0 || accessFolder.indexOf(";") != -1)
throw new RuntimeException("参数: accessFolder为空或包含非法字符:';',请检查.");
String visitURL = wsAddress.getVisitURL();
if (visitURL == null || visitURL.trim().length() == 0 || visitURL.indexOf(";") != -1)
throw new RuntimeException("参数: visitURL为空或包含非法字符:';',请检查.");
return false;
}
}

Java-WebServiceUtil工具类的更多相关文章

  1. Java Properties工具类详解

    1.Java Properties工具类位于java.util.Properties,该工具类的使用极其简单方便.首先该类是继承自 Hashtable<Object,Object> 这就奠 ...

  2. Java json工具类,jackson工具类,ObjectMapper工具类

    Java json工具类,jackson工具类,ObjectMapper工具类 >>>>>>>>>>>>>>> ...

  3. Java日期工具类,Java时间工具类,Java时间格式化

    Java日期工具类,Java时间工具类,Java时间格式化 >>>>>>>>>>>>>>>>>&g ...

  4. Java并发工具类 - CountDownLatch

    Java并发工具类 - CountDownLatch 1.简介 CountDownLatch是Java1.5之后引入的Java并发工具类,放在java.util.concurrent包下面 http: ...

  5. MinerUtil.java 爬虫工具类

    MinerUtil.java 爬虫工具类 package com.iteye.injavawetrust.miner; import java.io.File; import java.io.File ...

  6. MinerDB.java 数据库工具类

    MinerDB.java 数据库工具类 package com.iteye.injavawetrust.miner; import java.sql.Connection; import java.s ...

  7. 小记Java时间工具类

    小记Java时间工具类 废话不多说,这里主要记录以下几个工具 两个时间只差(Data) 获取时间的格式 格式化时间 返回String 两个时间只差(String) 获取两个时间之间的日期.月份.年份 ...

  8. Java Cookie工具类,Java CookieUtils 工具类,Java如何增加Cookie

    Java Cookie工具类,Java CookieUtils 工具类,Java如何增加Cookie >>>>>>>>>>>>& ...

  9. UrlUtils工具类,Java URL工具类,Java URL链接工具类

    UrlUtils工具类,Java URL工具类,Java URL链接工具类 >>>>>>>>>>>>>>>&g ...

  10. java日期工具类DateUtil-续一

    上篇文章中,我为大家分享了下DateUtil第一版源码,但就如同文章中所说,我发现了还存在不完善的地方,所以我又做了优化和扩展. 更新日志: 1.修正当字符串日期风格为MM-dd或yyyy-MM时,若 ...

随机推荐

  1. Design Linked List

    Design your implementation of the linked list. You can choose to use the singly linked list or the d ...

  2. 【Redis】Redis持久化

    Redis数据持久化 Redis的特性: 易扩展,大数据高性能,多样灵活的数据模型,受限内存 Redis默认端口: 6379 Redis数据持久化分为有两种: RDB: 每隔一段时间就把内存数据写入磁 ...

  3. Ubuntu 下几种软件安装的方法小结

    1.tar.gz软件包的安装 1)解压tar.gz包 .tar.gz -C /home/Desktop # 将软件包名.tar.gz解压到指定的目录下 2)进入解压后的文件目录下      执行“./ ...

  4. E.XKC's basketball team(The Preliminary Contest for ICPC Asia Xuzhou 2019)

    https://nanti.jisuanke.com/t/41387 解: 离散化+线段树. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); ...

  5. PHP 协程:Go + Chan + Defer

    Swoole4为PHP语言提供了强大的CSP协程编程模式.底层提供了3个关键词,可以方便地实现各类功能. Swoole4提供的PHP协程语法借鉴自Golang,在此向GO开发组致敬 PHP+Swool ...

  6. js 中的 number 为何很怪异

    js 中的 number 为何很怪异 声明:需要读者对二进制有一定的了解 对于 JavaScript 开发者来说,或多或少都遇到过 js 在处理数字上的奇怪现象,比如: > 0.1 + 0.2 ...

  7. Linux命令-文件管理篇-cat

    1.cat 说明 cat 是一个文本文件查看和连接工具.查看一个文件的内容,用cat比较简单,就是cat 后面直接接文件名. 2.使用权限 所有使用者 <!-- more --> 3.ca ...

  8. Centos7.3安装Mysql5.7.26(glibc即linux通用版)

    1.检查防火墙是否关闭 //查看防火墙状态 firewall-cmd --state //关闭防火墙 systemctl stop firewalld systemctl disable firewa ...

  9. url请求

    --[[local g = require 'library.global'--__ml_ss = mlc.prefix.ml_psession..tostring(os.time());local ...

  10. 22-Perl Socket 编程

    1.Perl Socket 编程Socket又称"套接字",应用程序通常通过"套接字"向网络发出请求或者应答网络请求,使主机间或者一台计算机上的进程间可以通讯. ...