Java-WebServiceUtil工具类
来源:互联网 发布:网络投资与理财收益 编辑:程序博客网 时间:2024/06/05 23:58
/** * 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; }}
阅读全文
1 0
- Java-WebServiceUtil工具类
- WebServiceUtil
- WebServiceUtil
- java文件工具类
- java日期工具类
- java 绝对路径工具类
- java工具类
- Java 数据处理工具类
- java日期工具类
- java工具类Assert
- 一些Java工具类
- anroid&java工具类
- java StringUtil 工具类
- java身份证号工具类
- java 日期工具类
- Java开发工具类
- java 加密工具类
- java集合工具类
- struts2框架
- 5G主要技术场景与六大关键技术
- HashMap和TreeMap排序
- 数据库水平分表 数据库分片
- 在pycharm中切换python版本的方法
- Java-WebServiceUtil工具类
- Linux下C语言的gdb调试
- 关于序列化以及NonSerializedAttribute的一点总结
- 解决使用Maven项目,无法正确编译的问题
- Spring--Collection装配
- 关于JAVA配置的碎碎念
- 夜灵的Html笔记Day08——css属性详细设置、雪碧图、定位
- Android Studio签名打包发布
- Java-ZipUtil工具类