Java-WebServiceUtil工具类
/**
* 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工具类的更多相关文章
- Java Properties工具类详解
1.Java Properties工具类位于java.util.Properties,该工具类的使用极其简单方便.首先该类是继承自 Hashtable<Object,Object> 这就奠 ...
- Java json工具类,jackson工具类,ObjectMapper工具类
Java json工具类,jackson工具类,ObjectMapper工具类 >>>>>>>>>>>>>>> ...
- Java日期工具类,Java时间工具类,Java时间格式化
Java日期工具类,Java时间工具类,Java时间格式化 >>>>>>>>>>>>>>>>>&g ...
- Java并发工具类 - CountDownLatch
Java并发工具类 - CountDownLatch 1.简介 CountDownLatch是Java1.5之后引入的Java并发工具类,放在java.util.concurrent包下面 http: ...
- MinerUtil.java 爬虫工具类
MinerUtil.java 爬虫工具类 package com.iteye.injavawetrust.miner; import java.io.File; import java.io.File ...
- MinerDB.java 数据库工具类
MinerDB.java 数据库工具类 package com.iteye.injavawetrust.miner; import java.sql.Connection; import java.s ...
- 小记Java时间工具类
小记Java时间工具类 废话不多说,这里主要记录以下几个工具 两个时间只差(Data) 获取时间的格式 格式化时间 返回String 两个时间只差(String) 获取两个时间之间的日期.月份.年份 ...
- Java Cookie工具类,Java CookieUtils 工具类,Java如何增加Cookie
Java Cookie工具类,Java CookieUtils 工具类,Java如何增加Cookie >>>>>>>>>>>>& ...
- UrlUtils工具类,Java URL工具类,Java URL链接工具类
UrlUtils工具类,Java URL工具类,Java URL链接工具类 >>>>>>>>>>>>>>>&g ...
- java日期工具类DateUtil-续一
上篇文章中,我为大家分享了下DateUtil第一版源码,但就如同文章中所说,我发现了还存在不完善的地方,所以我又做了优化和扩展. 更新日志: 1.修正当字符串日期风格为MM-dd或yyyy-MM时,若 ...
随机推荐
- C语言I—2019秋作业第一周作业
1.你对软件工程专业或者计算机科学与技术专业了解是怎样? 软件工程专业是一门研究用工程化方法构建和维护有效的.实用的和高质量的软件的学科.它涉及到程序设计语言,数据库,软件开发工具,系统平台,标准,设 ...
- tinymce 中我输入的内容 清空问题
<tinymce v-model="formItem.hDtContent" ref="content" @accessory="handlea ...
- sd卡挂载方法:
cd mnt//Sdcard创建目录mkdir -m 777 Sdcard//节点挂载mount /dev/msa1 /mnt/Sdcard//抓包./tcpdump -i eth0 tcp por ...
- Maximum Frequency Stack
Implement FreqStack, a class which simulates the operation of a stack-like data structure. FreqStack ...
- Update语句的Output从句结构
原文:Update语句的Output从句结构 一,先看1个列子 ) dbo.Table_1 set status = 'C' --2,选择前3条数据output deleted.id,deleted. ...
- 去除MFC特性之一
先对文件读取路径进行去除,然后对程序中出现的其他地方进行慢慢去除. #include "WavIo.h" #include "mfcc.h" #include ...
- Linux就该这么学——新手必须掌握的命令之文件目录管理命令组
touch命令 用途 : 用于创建空白文件或设置文件的时间 格式 : touch [选项] [文件] 参数 作用 -a 仅修改”读取时间”(atime) -m 仅修改”修改时间”(mtime) -d ...
- 进阶Java编程(5)基础类库
Java基础类库 1,StringBuffer类 String类是在所有项目开发之中一定会使用到的一个功能类,并且这个类拥有如下的特点: ①每一个字符串的常量都属于一个String类的匿名对象,并且不 ...
- 进阶Java编程(3)线程的同步与死锁
线程的同步与死锁 1,同步问题引出 在多线程的处理之中,可以利用Runnable描述多个线程操作的资源,而Thread描述每一个线程对象,对于当多个线程访问统一资源的时候如果处理不当就会产生数据的错误 ...
- C#开发微信公众平台-就这么简单(转载)(附原文链接)
一直使用的是一百八的诺鸡鸭,没有想去接触看起来风风火火的移动互联网:但因工作需要维护一个微信公众订阅号,考虑以前有做网站的基础,就想着做个简单的微信后台管理:看了官方的开发文档,比狗哥地图的短许多,又 ...