/**
* 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. [Nowcoder212D]禁书目录_概率期望

    禁书目录 题目大意:清教需要定期给Index清除记忆,在此之前需要把当中的十万三千本禁书取出来......不幸的是,禁书一旦离开了Index就非常脆弱,具体来说,每一本禁书都有一个魔力值 ai ,其记 ...

  2. Analyzing Polyline -- Codeforces Round #123 (Div. 2)

    题意:https://codeforc.es/problemset/problem/195/D 求折线段数. 思路: 对pos进行sort,对不同区间段加k,两个dp处理不同k>0 or k&l ...

  3. javascript的一些有用函数记录,不断更新。。。

    addLoadEvent函数: 众所周知,html文档加载完后会立即执行一个onload函数.但是onload函数只能包含一个被执行的函数,也就是你需要在加载完文档后执行的一个自己的函数.在实际中ht ...

  4. 2019牛客暑期多校训练营(第二场) - B - Eddy Walker 2 - BM算法

    参考于: https://www.luogu.org/problemnew/solution/P4723 shadowice1984 (太难) https://www.cnblogs.com/zhgy ...

  5. PBOC第八部分和第十一部分关于TYPEA总结(二)——传输协议(ISO14443-4)

    二.传输协议(ISO14443-4)(8,P50 11,P30) 1.选择应答请求(RATS) 使用RATS命令和PICC协商通讯的最大帧长度(FSD和FSC).帧等待时间(FWT)和启动帧保护时间( ...

  6. 长沙理工大学第十二届ACM大赛-重现赛 大家一起来数二叉树吧 (组合计数)

    大意: 求n结点m叶子二叉树个数. 直接暴力, $dp[i][j][k][l]$表示第$i$层共$j$节点, 共$k$叶子, 第$i$层有$l$个叶子的方案数, 然后暴力枚举第$i$层出度为1和出度为 ...

  7. python 列表反转

    反转: 将原列表反转,返回None: li = [1, 2, 3]li.reverse()print(li)# [3, 2, 1]1234不改变原列表,返回反转后的新列表: li = [1, 2, 3 ...

  8. 鼠标右键点击弹出菜单(jQuery)

    禁用浏览器默认事件,此处是兼容写法 $(document).contextmenu(function (e) { var event = e || window.event; if (event.pr ...

  9. js扩展Date对象的方法,格式化日期格式(prototype)

    扩展:Date.prototype.format = function(format){     var o =  {     "M+" : this.getMonth()+1, ...

  10. 转载Linux常用命令

    转自:https://blog.csdn.net/deng_xj/article/details/88803148 Linux常用shell命令 [root@dengxj]#各项含义[用户名@计算机名 ...