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时,若 ...
随机推荐
- oracle——学习之路(oracle内置函数)
oracle与很多内置函数,主要分为单行函数与集合函数. 首先要提一下dual表,它oracle的一个表,没有什么实质的东西,不能删除它,否则会造成Oracle无法启动等问题,他有很大用处,可以利用它 ...
- SQL Server 2019 Linux Docker 在主机上以其他非根用户的身份运行容器
docker logs mssql2019SQL Server 2019 will run as non-root by default.This container is running as us ...
- 基于 CentOS 7 搭建 GitLab
⒈更新软件包 yum update -y ⒉安装 ssh服务并启动 yum install -y curl policycoreutils-python openssh-server systemct ...
- 拨开Python迷雾
Python方向及能力要求 web就业方向:Python基础.Python高级.前端开发. web开发爬虫方向:Python基础.Python高级.前端开发.web开发. 爬虫开发数据挖掘/分析方 ...
- Graph、DFS、BFS
Graph.java package Graph; import LinearLIst.bag.Bag; import edu.princeton.cs.algs4.In; public class ...
- WPF的硬件加速
wpf根据硬件 可以做出三档的渲染 dx7以下 第0档 不支持硬件加速 dx7-dx9 第1档, 不支持所有硬件加速,但支持一部分 dx9 以上 支持所有硬件加速 可以用编程的方式取代 当前设备处于 ...
- springboot指定redis库编号配置实现
yml配置 spring: redis: database: #shiro host: 127.0.0.1 port: timeout: password: null redis-cache: dat ...
- MapReduces计数实验
实验内容 现有某电商网站用户对商品的收藏数据,记录了用户收藏的商品id以及收藏日期,名为buyer_favorite1. buyer_favorite1包含:买家id,商品id,收藏日期这三个字段,数 ...
- O039、Unshelve Instance 操作详解
参考https://www.cnblogs.com/CloudMan6/p/5529915.html 上一节我们 shelve Instance 到 Glance,本节学习如何通过 unshelv ...
- springBoot2.x 支持跨域请求配置
提供三种配置方式: 1.配置过滤器,实现 WebMvcConfigurer接口(springboot2.x的方式) @Configuration public class GlobalCorsConf ...