`
jiagyao
  • 浏览: 96019 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
oracle数据库备份及恢复
1.1.1 物理数据库备份(Oracle)
步骤 1	以oracle用户登陆到数据库所在服务器,执行如下备份命令备份sysdb用户:
oracle% exp sysdb/sysdb@oracle owner=sysdb rows=y compress=n buffer=65536 feedback=100000 file=exp_sysdb.dmp
步骤 2	以oracle用户登陆到数据库所在服务器,执行如下备份命令备份userdb用户:
oracle% exp userdb/userdb@oracle owner=userdb rows=y compress=n buffer=65536 feedback=100000 file=exp_userdb.dmp
步骤 3	以oracle用户登陆到数据库所在服务器,执行如下备份命令备份cbpdb用户:
oracle% exp cbpdb/cbpdb@oracle owner=cbpdb rows=y compress=n buffer=65536 feedback=100000 file=exp_cbpdb.dmp
1.1.2 备份BMP
步骤 1	以root用户登录BMP,执行以下命令 (主机)
# cd ~bmp/..
# tar -cvf - bmp|gzip -cf > ENIP_210_BMP_bak.tar.gz
# mkdir bmpbackup
# mv ENIP_210_BMP_bak.tar.gz ./bmpbackup
步骤 2	以root用户登录BMP,执行以下命令(主备机)
# crontab -l > /enip/bmpbackup/crontab_bmp.txt
1.1.3 备份CBP
步骤 1	以root用户登录CBP,执行以下命令:(主备机)
# cd ~cbp/..
# tar -cvf - cbp |gzip -cf > ENIP_210_CBP_bak.tar.gz
# mkdir cbpbackup
# mv ENIP_210_CBP_bak.tar.gz ./cbpbackup
步骤 2	以root用户登录CBP机器,执行以下命令:(主备机)
# cd ~smdb/..
# tar -cvf - smdb |gzip -cf >  ENIP_210_SMDB_bak.tar.gz
# mv ENIP_210_SMDB_bak.tar.gz ./cbpbackup
步骤 3	以root用户登录CBP机器,执行以下命令(主备机)
# cd ${HOME}
# crontab -l > ${HOME}/crontab_cbp.txt
步骤 4	以smdb用户登录CBP,执行以下命令(主备机)
smdb% cd ${HOME}
smdb% crontab -l > ${HOME}/crontab_smdb.txt
java mail java mail
/**
 * [Product]
 *     SystemWarning
 * [Copyright]
 *     Copyright © 2010 ICSS All Rights Reserved.
 * [FileName]
 *     JavaMailSend.java
 * [History]
 *     Version  Date      Author     Content
 *     -------- --------- ---------- ------------------------
 *     1.0.0    Sep 2, 2010   zhucq    最初版本
 */
package com.huawei.ocqs.syscheck;

import java.util.Date;
import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;

import com.huawei.ocqs.util.StringEncode;

/**
 * <b>Summary: </b>
 *      java发送邮件的基本类
 * <b>Remarks: </b>
 *      用来作为OCQS的巡检,巡检内容包括:入库是否正常,话单统计,话务量统计,主机空间大小,局数据比对结果等。
 */
public class JavaMailSend {
	
	private String smtp;
	private String servername;
	private String serverpaswd;
	private String to; 
	private String from;

	/**
	 * <b>Summary: </b>
	 *     获取to的值
	 * @return to 
	 */
	public String getTo() {
		return to;
	}

	/** 
	 * <b>Summary: </b>
	 *     设置 to 的值 
	 * @param to 
	 */
	public void setTo(String to) {
		this.to = to;
	}

	
    
    /**
     * <b>Summary: </b>
     *     sendmail(发送邮件)
     * @param subject
     * @param text
     * @param filenames
     * @param mimeType 
     */
    @SuppressWarnings("static-access")
	public void sendmail(String subject,String text, String[] filenames, String mimeType) {
        try {
            Properties props = new Properties();

            javax.mail.Session mailSession = null; // 邮件会话对象
            javax.mail.internet.MimeMessage mimeMsg = null; // MIME邮件对象

            props = java.lang.System.getProperties(); // 获得系统属性对象
            props.put("mail.smtp.host", smtp); // 设置SMTP主机
            props.put("mail.smtp.auth", "true"); // 是否到服务器用户名和密码验证
            // 到服务器验证发送的用户名和密码是否正确
            SmtpAuthenticator myEmailAuther = new SmtpAuthenticator(servername,
                    serverpaswd);
            // 设置邮件会话 注意这里将认证信息放进了Session的创建参数里
            mailSession = javax.mail.Session.getInstance(props,
                    (Authenticator) myEmailAuther);
            // 设置传输协议
            javax.mail.Transport transport = mailSession.getTransport("smtp");
            // 设置from、to等信息
            mimeMsg = new javax.mail.internet.MimeMessage(mailSession);
            if (null != from && !"".equals(from)) {
                InternetAddress sentFrom = new InternetAddress(from);
                mimeMsg.setFrom(sentFrom); // 设置发送人地址
            }
            String[] toMails=to.split(";");
            InternetAddress[] sendTo = new InternetAddress[toMails.length];
            for (int i = 0; i < toMails.length; i++) {
                sendTo[i] = new InternetAddress(toMails[i]);
                System.out.println("sendTo[i]="+sendTo[i]);
            }

            mimeMsg.setRecipients(
                    javax.mail.internet.MimeMessage.RecipientType.TO, sendTo);
            mimeMsg.setSubject(subject, "gb2312");

            MimeBodyPart messageBodyPart1 = new MimeBodyPart();
            // messageBodyPart.setText(UnicodeToChinese(text));
            messageBodyPart1.setContent(text, mimeType);

            // 附件传输格式
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(messageBodyPart1);
            if(filenames!=null){
	            for (int i = 0; i < filenames.length; i++) {
	                MimeBodyPart messageBodyPart2 = new MimeBodyPart();
	
	                String filename = filenames[i].split(";")[0];
	                String displayname = filenames[i].split(";")[1];
	                // 得到数据源
	                FileDataSource fds = new FileDataSource("./log/"+filename);
	                // BodyPart添加附件本身
	                messageBodyPart2.setDataHandler(new DataHandler(fds));
	                // BodyPart添加附件文件名
	                messageBodyPart2.setFileName(MimeUtility
	                        .encodeText(displayname));
	                multipart.addBodyPart(messageBodyPart2);
	            }
            }
            mimeMsg.setContent(multipart);
            // 设置信件头的发送日期
            mimeMsg.setSentDate(new Date());
            mimeMsg.saveChanges();
            // 发送邮件
            transport.send(mimeMsg);
            transport.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
    
    }

    /**
     * Smtp认证
     */
    class SmtpAuthenticator extends Authenticator {
        String username = null;
        String password = null;

        /**
         * SMTP身份验证
         * @param username
         * @param password
         */
        public SmtpAuthenticator(String username, String password) {
            super();
            this.username = username;
            this.password = password;
        }

        /**
         * @return pass
         */
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(this.username, this.password);
        }
    }

	/**
	 * <b>Summary: </b>
	 *     获取smtp的值
	 * @return smtp 
	 */
	public String getSmtp() {
		return smtp;
	}

	/** 
	 * <b>Summary: </b>
	 *     设置 smtp 的值 
	 * @param smtp 
	 */
	public void setSmtp(String smtp) {
		this.smtp = smtp;
	}

	/**
	 * <b>Summary: </b>
	 *     获取servername的值
	 * @return servername 
	 */
	public String getServername() {
		return servername;
	}

	/** 
	 * <b>Summary: </b>
	 *     设置 servername 的值 
	 * @param servername 
	 */
	public void setServername(String servername) {
		this.servername = servername;
	}

	/**
	 * <b>Summary: </b>
	 *     获取serverpaswd的值
	 * @return serverpaswd 
	 */
	public String getServerpaswd() {
		return serverpaswd;
	}

	/** 
	 * <b>Summary: </b>
	 *     设置 serverpaswd 的值 
	 * @param serverpaswd 
	 */
	public void setServerpaswd(String serverpaswd) {
		this.serverpaswd = serverpaswd;
	}

	/**
	 * <b>Summary: </b>
	 *     获取from的值
	 * @return from 
	 */
	public String getFrom() {
		return from;
	}

	/** 
	 * <b>Summary: </b>
	 *     设置 from 的值 
	 * @param from 
	 */
	public void setFrom(String from) {
		this.from = from;
	}

	
	/** 
	 * <b>Summary: </b>
	 *     复写方法 toString
	 * @return 该类的属性值
	 * @see java.lang.Object#toString() 
	 */
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return StringEncode.toString(this);
	}

}
动态语法查询 动态语法查询
package com.huawei.tuxedo.util;

import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.Map;
import org.apache.log4j.Logger;

import com.huawei.common.exception.AppException;

/**
 * @author  调用动态语法MDYNQUERY服务
 * 
 */
public class DynQueryService {

	/**
	 * 错误码
	 */
	private int errorCode = 0;

	/**
	 * 错误消息
	 */
	private String errorMsg = "";

	/**
	 * 日志服务
	 */
	private static Logger logger = Logger.getLogger(DynQueryService.class);

	public int getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	/**
	 * 调用动态语法查询
	 * @param paramMap  单值 0否 1是
	 * @param pageIndex  页面指针
	 * @param pageSize  页面最大数
	 * @return DynQueryGetBo
	 * @throws AppException
	 */
	public DynQueryGetBo queryData(Map paramMap, int titleFlag, int pageIndex, int pageSize) throws AppException {
		DynQueryGetBo dynQueryGetBo = new DynQueryGetBo();

		if (paramMap == null || paramMap.size() == 0) {
			return null;
		}
		String[][] result = null;
		String szErrText = "";
		JMwc mwc = new JMwc();
		mwc.MW_ClearBuffer();
		Iterator iterator = paramMap.keySet().iterator();
		String name = "";
		String value = "";
		int nRet = 0, rowCount = 0, colCount = 0;
		int i = 0, j = 0;

		while (iterator.hasNext()) {
			name = (String) iterator.next();
			value = (String) paramMap.get(name);
			mwc.MW_SetValue(name, value);
		}

		mwc.MW_SetValue("TITLE_FLAG", String.valueOf(titleFlag));
		mwc.MW_SetValue("PAGE_INDEX", String.valueOf(pageIndex));
		mwc.MW_SetValue("PAGE_SIZE", String.valueOf(pageSize));

		nRet = mwc.MW_CallProgram("MDYNQUERY");
		errorCode = mwc.MW_GetErrSysCode();
		errorMsg = mwc.MW_GetErrorMsg();

		if (nRet != 0) {
			szErrText = mwc.MW_GetErrorMsg();
			logger.error(szErrText);
			errorMsg = "调用服务MDYNQUERY 失败,原因是:" + mwc.MW_GetErrorMsg();
			String msg1 = null, msg2 = null, msg3 = null, msg4 = null, msg5 = null, msg6 = null;
			try {
				msg1 = new String(errorMsg.getBytes("UTF-8"), "iso-8859-1");
				msg2 = new String(errorMsg.getBytes("UTF-8"), "GBK");
				msg3 = new String(errorMsg.getBytes("GBK"), "iso-8859-1");
				msg4 = new String(errorMsg.getBytes("GBK"), "UTF-8");
				msg5 = new String(errorMsg.getBytes("iso-8859-1"), "GBK");
				msg6 = new String(errorMsg.getBytes("iso-8859-1"), "UTF-8");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			logger.error("errorCode=[" + errorCode + "]" + errorMsg);
			logger.error("1:" + msg1);
			logger.error("2:" + msg2);
			logger.error("3:" + msg3);
			logger.error("4:" + msg4);
			logger.error("5:" + msg5);
			logger.error("6:" + msg6);
			throw new AppException(errorMsg, errorCode);

		}
		rowCount = mwc.MW_GetRows();
		colCount = mwc.MW_GetColCount();

		result = new String[rowCount][colCount];

		if (rowCount <= 0) {
			szErrText = "取不到符合条件的记录";
			logger.info(szErrText);
		} else {
			for (i = 0; i < rowCount; i++) {
				mwc.MW_FetchRow();
				for (j = 0; j < colCount; j++) {
					result[i][j] = mwc.MW_GetColValue(j + 1);
				}
			}
		}
		//取单值		
		dynQueryGetBo.setDataList(result);
		dynQueryGetBo.setRecordCount(strToInt(mwc.MW_GetValue("RECORD_COUNT")));
		dynQueryGetBo.setPageCount(strToInt(mwc.MW_GetValue("PAGE_COUNT")));
		dynQueryGetBo.setPageIndex(strToInt(mwc.MW_GetValue("PAGE_INDEX")));
		dynQueryGetBo.setPageSize(strToInt(mwc.MW_GetValue("PAGE_SIZE")));

		return dynQueryGetBo;
	}

	/**
	 * 调用动态语法查询,默认不取标题无页面大小的限制
	 * @param paramMap
	 * @return DynQueryGetBo
	 * @throws AppException
	 */
	public DynQueryGetBo queryData(Map paramMap) throws AppException {
		return queryData(paramMap, 0, 0, 10000);
	}

	private int strToInt(String data) {
		try {
			return Integer.parseInt(data);
		} catch (Exception ex) {
			return 0;
		}
	}
}
调用tuxedo服务的类 调用tuxedo服务的类
package com.huawei.tuxedo.util;


import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.ArrayList;

import org.apache.log4j.Logger;

import com.huawei.common.Macro;
import com.huawei.common.exception.AppException;

/**
 * 功能:调用tuxedo服务的类
 *
 * 
 * @since 2006-10-25
 */
public class TuxedoServiceBean
{
	private String serviceName = ""; // 调用Tuxedo服务名
	private int errorCode = 0; 
	private String errorMsg = "";// 错误消息
	private JMwc jmwc = new JMwc();
	private Logger log401 = Logger.getLogger(Macro.LOG4J_FILE_COMMON);

	/**
	 *
	 */
	public TuxedoServiceBean()
	{
		jmwc.MW_ClearBuffer();
	}

	/**
	 * @param theServiceName
	 */
	public TuxedoServiceBean(String theServiceName)
	{
		jmwc.MW_ClearBuffer();
		this.serviceName = theServiceName;
	}

	/**
	 * @param theServiceName
	 * @param theInParam
	 */
	public TuxedoServiceBean(String theServiceName, String[][] theInParam)
	{
		jmwc.MW_ClearBuffer();
		this.serviceName = theServiceName;
		try
		{
			setInParam(theInParam);
		}
		catch (AppException e)
		{
			errorMsg = e.getMessage();
			errorCode = Macro.ERROR_CODE_SYS;
			//log401.error(errorMsg);
			e.printStackTrace();
		}
	}

	/**
	 * 功能:调用tuxedo服务
	 *
	 *
	 * @since 2006-10-25
	 * @throws AppException
	 */
	public  void callService() throws AppException
	{
		if (serviceName == null || serviceName.length() == 0)
		{
			errorMsg = "无效的服务名: " + serviceName;
			errorCode = Macro.ERROR_CODE_SYS;
			log401.error(errorMsg);
			throw new AppException(errorMsg, errorCode);
		}

		// 调用后台服务
		System.out.println("invoke " + serviceName + "...");
		int nRet = jmwc.MW_CallProgram(serviceName);
		errorMsg = jmwc.MW_GetErrorMsg();
		errorCode = jmwc.MW_GetErrSysCode();
		if (nRet < 0)
		{
			errorMsg = "调用服务 " + serviceName + " 失败,原因是:" + jmwc.MW_GetErrorMsg();
			String msg1=null, msg2=null, msg3=null, msg4=null, msg5=null, msg6=null;
			try {
				msg1 = new String(errorMsg.getBytes("UTF-8"),"iso-8859-1");
				msg2 = new String(errorMsg.getBytes("UTF-8"),"GBK");
				msg3 = new String(errorMsg.getBytes("GBK"),"iso-8859-1");
				msg4 = new String(errorMsg.getBytes("GBK"),"UTF-8");
				msg5 = new String(errorMsg.getBytes("iso-8859-1"),"GBK");
				msg6 = new String(errorMsg.getBytes("iso-8859-1"),"UTF-8");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
			log401.error("errorCode=["+errorCode+"]"+errorMsg);
			log401.error("1:"+msg1);
			log401.error("2:"+msg2);
			log401.error("3:"+msg3);
			log401.error("4:"+msg4);
			log401.error("5:"+msg5);
			log401.error("6:"+msg6);
			throw new AppException(errorMsg, errorCode);
		}
	}

	/**
	 * 功能:设置tuxedo服务的传入参数
	 *
	 *
	 * @since 2006-10-25
	 * @param argName
	 * @param argValue
	 * @throws AppException
	 */
	private void setInParam(String argName, String argValue)
			throws AppException
	{
		if (argName == null)
		{
			errorMsg = "方法setInParam()的参数argName为空.";
			errorCode = Macro.ERROR_CODE_SYS;
			throw new AppException(errorMsg, errorCode);
		}

		if (jmwc.MW_SetValue(argName, argValue == null ? "0" : argValue) == false)
		{
			errorCode = Macro.ERROR_CODE_SYS;
			throw new AppException("调用 jmwc.MW_SetValue() 失败.", errorCode);
		}
	}

	/**
	 * 功能:设置tuxedo服务的传入参数
	 *
	 *
	 * @since 2006-10-25
	 * @param theInParam
	 * @throws AppException
	 */
	public void setInParam(String[][] theInParam) throws AppException
	{
		if (theInParam == null || theInParam.length == 0)
		{
			errorMsg = "方法setInParam()的参数theInParam为空.";
			errorCode = Macro.ERROR_CODE_SYS;
			//log401.error(errorMsg);
			throw new AppException(errorMsg, errorCode);
		}

		for (int i = 0; i < theInParam.length; i++)
		{
			setInParam(theInParam[i][0], theInParam[i][1]);
		}
	}

	/**
	 * 功能:设置tuxedo服务的传入参数
	 *
	 * @author ff
	 * @since 2006-10-25
	 * @param theInParam
	 * @throws AppException
	 */
	public void setInParamList(String[][] theInParam) throws AppException
	{
		if (theInParam == null || theInParam.length == 0
				|| theInParam[0].length == 0)
		{
			errorMsg = "方法setInParamList()的参数theInParam为空.";
			errorCode = Macro.ERROR_CODE_SYS;
			//log401.error(errorMsg);
			throw new AppException(errorMsg, errorCode);
		}

		int nWidth[] = new int[theInParam[0].length];
		for (int j = 0; j < nWidth.length; j++)
		{
			nWidth[j] = theInParam[0][j].length() + 100;
		}

		if (jmwc.MW_SetColCount(nWidth) == false)
		{
			errorCode = Macro.ERROR_CODE_SYS;
			throw new AppException("调用 jmwc.MW_SetValue() 失败.", errorCode);
		}

		for (int i = 0; i < theInParam.length; i++)
		{
			jmwc.MW_AddRow();
			for (int j = 0; j < theInParam[0].length; j++)
			{
				if (theInParam[i][j] == null)
				{
					errorMsg = "setInParamList()的参数argName为空.";
					errorCode = Macro.ERROR_CODE_SYS;
					//log401.error(errorMsg);
					throw new AppException(errorMsg, errorCode);
				}

				if (jmwc.MW_SetColValue(j+1, theInParam[i][j]) == false)
				{
					errorCode = Macro.ERROR_CODE_SYS;
					throw new AppException("调用 jmwc.MW_SetValue() 失败.", errorCode);
				}
			}
		}
	}

	/**
	 * 功能:获得tuxedo服务执行后的返回值
	 *
	 *
	 * @since 2006-10-25
	 * @param argName
	 * @return
	 * @throws AppException
	 */
	private String getReResultValue(String argName) throws AppException
	{
		String argValue = null;

		try
		{
			argValue = jmwc.MW_GetValue(argName);
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			errorCode = Macro.ERROR_CODE_SYS;
			throw new AppException("调用 jmwc.MW_GetValue() 失败.原因是:"
					+ ex.getMessage(), errorCode);
		}

		return argValue;
	}

	/**
	 * 功能:获得tuxedo服务执行后的返回值
	 *
	 * @author ff
	 * @since 2006-10-25
	 * @param theReResultName
	 * @return
	 * @throws AppException
	 */
	public String[][] getSingleReResultValue(String[] theReResultName)
			throws AppException
	{
		String[][] reResultValue;

		if (theReResultName == null || theReResultName.length == 0)
		{
			errorMsg = "方法getReResultValue()的参数theReResultName为空.";
			errorCode = Macro.ERROR_CODE_SYS;
			throw new AppException(errorMsg, errorCode);
		}

		// 调用Tuxdeo服务
		this.callService();

		reResultValue = new String[theReResultName.length][2];

		for (int i = 0; i < theReResultName.length; i++)
		{
			reResultValue[i][0] = theReResultName[i];
			reResultValue[i][1] = getReResultValue(theReResultName[i]);
		}

		// 清除缓存
		try
		{
			jmwc.MW_ClearBuffer();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			errorCode = Macro.ERROR_CODE_SYS;
			throw new AppException("调用jmwc.MW_ClearBuffer()失败.原因是:"
					+ ex.getMessage(), errorCode);
		}

		return reResultValue;
	}

	/**
	 * 功能:获得tuxedo服务执行后的返回值
	 *
	 * 
	 * @since 2006-10-25
	 * @param theReResultName
	 * @return
	 * @throws AppException
	 */
	public String[][] getReResultValue(String[] theReResultName)
			throws AppException
	{
		String[][] reResultValue;

		if (theReResultName == null || theReResultName.length == 0)
		{
			errorMsg = "方法getReResultValue()的参数theReResultName为空.";
			errorCode = Macro.ERROR_CODE_SYS;
			//log401.error(errorMsg);
			throw new AppException(errorMsg, errorCode);
		}

		// 调用Tuxdeo服务
		this.callService();

		// 行数
		int rowCount = 0;
		try
		{
			rowCount = jmwc.MW_GetRows();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			errorCode = Macro.ERROR_CODE_SYS;
			throw new AppException("调用 jmwc.MW_GetRows() 失败.原因是:"
					+ ex.getMessage(), errorCode);
		}
		
		if (rowCount == 0)
		{
			errorCode = Macro.ERROR_CODE_NODATA;
			throw new AppException("jmwc.MW_GetRows() 获得的行数为0.", errorCode);
		}

		reResultValue = new String[rowCount][theReResultName.length];

		for (int i = 0; i < rowCount; i++)
		{
			// 读一行
			if (jmwc.MW_FetchRow() == false)
			{
				break;
			}

			// 获得返回值
			for (int j = 0; j < theReResultName.length; j++)
			{
				reResultValue[i][j] = getReResultValue(theReResultName[j]);
			}
		}

		// 清除缓存
		try
		{
			jmwc.MW_ClearBuffer();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			errorCode = Macro.ERROR_CODE_SYS;
			throw new AppException("调用jmwc.MW_ClearBuffer()失败.原因是:"
					+ ex.getMessage(), errorCode);
		}

		return reResultValue;
	}

	/**
	 * 功能:获得tuxedo服务执行后的返回值
	 *
	 * 
	 * @since 2006-10-25
	 * @return
	 * @throws AppException
	 */
	public String[][] getReResultValue() throws AppException
	{
		String[][] reResultValue = null;

		// 调用Tuxdeo服务
		this.callService();

		// 行数
		int rowCount = 0;
		int colCount = 0;

		try
		{
			rowCount = jmwc.MW_GetRows();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			errorCode = Macro.ERROR_CODE_SYS;
			throw new AppException("调用jmwc.MW_GetRows()失败.原因是:"
					+ ex.getMessage(), errorCode);
		}

		try
		{
			colCount = jmwc.MW_GetColCount();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			errorCode = Macro.ERROR_CODE_SYS;
			throw new AppException("调用jmwc.MW_GetColCount()失败.原因是:"
					+ ex.getMessage(), errorCode);
		}

		if (rowCount == 0)
		{
			errorCode = Macro.ERROR_CODE_NODATA;
			throw new AppException("查询结果记录数为零.", errorCode);
		}

		if (colCount == 0)
		{
			errorCode = Macro.ERROR_CODE_NODATA;
			throw new AppException("查询结果字段数为零.", errorCode);
		}

		reResultValue = new String[rowCount][colCount];

		for (int i = 0; i < rowCount; i++)
		{
			// 读一行
			if (jmwc.MW_FetchRow() == false)
			{
				break;
			}

			// 获得返回值
			for (int j = 0; j < colCount; j++)
			{
				reResultValue[i][j] = jmwc.MW_GetColValue(j + 1);
			}
		}

		// 清除缓存
		try
		{
			jmwc.MW_ClearBuffer();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			errorCode = Macro.ERROR_CODE_SYS;
			throw new AppException("调用jmwc.MW_ClearBuffer()清除缓存失败.原因是:"
					+ ex.getMessage(), errorCode);
		}

		return reResultValue;
	}

        /**
         * 功能:获得tuxedo服务执行后的返回值,含单列名取得的值和多行多列返回值
         *
         * @author 苏丽丽
         * @since 2009-03-09
         * @param theReResultName 取单列用的列名数组
         * @param retSigleVal 单列值HashMap
         * @param retArrVal 多行多列,采用ArrayList存储,再放入HashMap中
         * @return
         * @throws AppException
         */
        public void getMutiResultValue(String[] theReResultName,
                HashMap retSingleVal,HashMap retArrVal)
                        throws AppException
	{
            //校验入参
            if (theReResultName == null || retSingleVal == null || retArrVal == null)
            {
            	errorCode = Macro.ERROR_CODE_SYS;
                throw new AppException("方法getMutiResultValue() 入参不合法.",
                		   errorCode);
            }

            // 调用Tuxdeo服务
            this.callService();

            // 行数
            int rowCount = 0;
            int colCount = 0;

            //取单列
            for(int k=0; k<theReResultName.length; k++)
            {
                String szSingleVal = "";
                szSingleVal = getReResultValue(theReResultName[k]);
                retSingleVal.put(theReResultName[k],szSingleVal);
            }

            try
            {
                    rowCount = jmwc.MW_GetRows();
            }
            catch (Exception ex)
            {
                    ex.printStackTrace();
                    errorCode = Macro.ERROR_CODE_SYS;
                    throw new AppException("调用jmwc.MW_GetRows()失败.原因是:"
                                    + ex.getMessage(), errorCode);
            }

            try
            {
                    colCount = jmwc.MW_GetColCount();
            }
            catch (Exception ex)
            {
                    ex.printStackTrace();
                    errorCode = Macro.ERROR_CODE_SYS;
                    throw new AppException("调用jmwc.MW_GetColCount()失败.原因是:"
                                    + ex.getMessage(), errorCode);
            }

            if (rowCount == 0 || colCount == 0)
            {
            }

            for (int i = 0; i < rowCount; i++)
            {
                ArrayList arrList = new ArrayList(colCount);
                String szKeyName = String.valueOf(i);

                // 读一行
                if (jmwc.MW_FetchRow() == false)
                {
                        break;
                }

                // 获得返回值
                for (int j = 0; j < colCount; j++)
                {
                      String szRetVal = jmwc.MW_GetColValue(j + 1);
                      arrList.add(szRetVal);
                }

                //将列表放入HashMap
                retArrVal.put(szKeyName, arrList);
            }

            // 清除缓存
            try
            {
                    jmwc.MW_ClearBuffer();
            }
            catch (Exception ex)
            {
                    ex.printStackTrace();
                    errorCode = Macro.ERROR_CODE_SYS;
                    throw new AppException("调用jmwc.MW_ClearBuffer()清除缓存失败.原因是:"
                                    + ex.getMessage(), errorCode);
            }

            return;
        }
        
        
        /**
         * 功能:获得tuxedo服务执行后的返回值,只含单列值
         *
         * @author 林金地
         * @since 2010-06-13
         * @param theReResultName 取单列用的列名数组
         * @param retSigleVal 单列值HashMap
         * @return
         * @throws AppException
         */
        public void getSingleResultValue(String[] theReResultName,HashMap retSingleVal)
        	throws AppException
        {
            //校验入参
            if (theReResultName == null || retSingleVal == null)
            {
            	errorCode = Macro.ERROR_CODE_SYS;
                   throw new AppException("方法getSingleResultValue() 入参不合法.",errorCode);
            }

            // 调用Tuxdeo服务
            this.callService();
            //取单列
            for(int k=0; k<theReResultName.length; k++)
            {
                String szSingleVal = "";
                szSingleVal = getReResultValue(theReResultName[k]);
                retSingleVal.put(theReResultName[k],szSingleVal);
            }
            
            // 清除缓存
            try
            {
                    jmwc.MW_ClearBuffer();
            }
            catch (Exception ex)
            {
                    ex.printStackTrace();
                    errorCode = Macro.ERROR_CODE_SYS;
                    throw new AppException("调用jmwc.MW_ClearBuffer()清除缓存失败.原因是:"
                                    + ex.getMessage(), errorCode);
            }

            return;
        }
        

	/**
	 * 功能:获得tuxedo服务名
	 *
	 * 
	 * @since 2006-10-25
	 * @param serviceName
	 */
	public void setServiceName(String serviceName)
	{
		this.serviceName = serviceName;
	}

	/**
	 * 功能:获得错误消息
	 *
	 *
	 * @since 2006-10-25
	 * @return
	 */
	public String getErrorMsg()
	{
		return errorMsg;
	}

	public int getErrorCode() {
		return errorCode;
	}


}
tuxedo调用WTC服务 Factory封装 wtc
package com.huawei.tuxedo.util;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.apache.log4j.Logger;

//import org.apache.log4j.Logger;

import weblogic.wtc.gwt.TuxedoConnection;
import weblogic.wtc.gwt.TuxedoConnectionFactory;
import weblogic.wtc.jatmi.ApplicationToMonitorInterface;
import weblogic.wtc.jatmi.Reply;
import weblogic.wtc.jatmi.TPException;
import weblogic.wtc.jatmi.TPReplyException;
import weblogic.wtc.jatmi.TypedString;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2003
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author unascribed
 * @version 1.0
 */

public class SF
{
	private static Logger log = Logger.getLogger(SF.class);

	public SF()
	{
	}

	public static byte[] CallProgram(String szAppServ, String szUser,
			String szPass, String szService, String szInBuf)
			throws TPException, TPReplyException 
	{
		Context ctx;
		TuxedoConnectionFactory tcf;
		TuxedoConnection myTux;
		TypedString myData;
		Reply myRtn = null;
		try
		{
			/*
			 * String provider_url = "t3://135.224.83.27:7131"; Properties
			 * properties = new Properties();
			 * properties.put(Context.INITIAL_CONTEXT_FACTORY,
			 * "weblogic.jndi.WLInitialContextFactory");
			 * properties.put(Context.PROVIDER_URL, provider_url); ctx = new
			 * InitialContext(properties);
			 */
			ctx = new InitialContext();
			tcf = (TuxedoConnectionFactory) ctx
					.lookup("tuxedo.services.TuxedoConnection");
		}
		catch (NamingException ne)
		{
			log.error("初始化Tuxedo连接工厂失败,原因是:" + ne.getMessage());
			throw new TPException(TPException.TPENOENT,
					"Could not get TuxedoConnectionFactory . ");
		}

		myTux = tcf.getTuxedoConnection();
		myData = new TypedString(szInBuf);
		try
		{
			myRtn = myTux.tpcall(szService, myData,
					ApplicationToMonitorInterface.TPNOTRAN);
		}
		catch (TPReplyException tre)
		{
			log.error("调用Tuxedo服务,执行tpcall()失败,原因是:" + tre.getMessage());
			throw tre;
		}
		catch (TPException te)
		{
			log.error("调用Tuxedo服务,执行tpcall()失败,原因是:" + te.getMessage());
			throw te;
		}
		catch (Exception ee)
		{
			log.error("调用Tuxedo服务,执行tpcall()失败,原因是:" + ee.getMessage());
			throw new TPException(TPException.TPESYSTEM, "Exception: " + ee);
		}

		myData = (TypedString) myRtn.getReplyBuffer();
		log.info("SF.java CallProgram Return["+myData.toString()+"]");
		myTux.tpterm(); // Closing the association with Tuxedo

		return (myData.toString().getBytes());
	}
}
JMwc 调用WTC 调用wtc
package com.huawei.tuxedo.util;

/**
 * <p>
 * Title: JMwc
 * </p>
 * <p>
 * Description:调用TUXEDO的相关服务,直接拼字符串方式调用
 * </p>
 * <p>
 * Copyright: Copyright (c) 2002
 * </p>
 * <p>
 * Company: Longshine CO. Ltd.
 * </p>
 * 
 * 
 * @version 1.0 modified by ,2005/10/17 reason:尽量减少内存使用,采取方式如下: 1
 *          默认申请内存6K,以满足大部分业务的需求; 2
 *          初始参数可以指定输出缓冲的大小(多行数据的缓冲空间),可以将内存申请的多少交给应用程序,以适应少量的大数据传送请求; 3
 *          增加在需要时动态增加内存的功能,以满足不修改应用程序下的超长数据传输要求。 4
 *          规范化接口调用,防止应用程序反复调用MW_init导致的重复内存申请开销
 */
public class JMwc {
	private int m_cbOutBuffer = 6000; // 输出缓冲的大小,默认为6K(4K基础缓冲+2K的多行数据缓冲)
	// private int m_cbInBuffer = 0; //输入缓冲的大小,初值没用
	public static int MAX_FIELD_NUM = 50; // 至多50个单个的项
	public static int MW_RC_LONG_PKG = 999; // 后台返回超长数据的响应
	public static int MAX_BASE_LENGTH = 4000;
	public static int MAX_SINGLE_NAME_LEN = 16; // 单值的名字长度,历史默认是10位,可能会被截断
	// 返回值是否需要去除空格(调用GetValue/GetColValue的时候)
	// 0全部去除,1去除左加的空格,2去除右边的空格
	private int AUTO_TRIM = CConst.ALL_TRIM;
 
	boolean m_bFlagPackage = false; // 默认为按前台营收方式打包,true为直接拼字符串的方式
	// 没有用的局部变量,全部去除
	// String m_szAppAddress = "//172.20.0.100:17000";
	// String m_szUserName = "";
	// String m_szUserRole = "";
	// String m_szUserPass = "";
	// String m_szAppPass = "";
	int m_iTimeOut = 300;
	byte m_pOutBuffer[];
	byte m_pInBuffer[];
	String m_szErrMsg = "";
	int m_iErrSysCode = 0;

	// 拆分数据包要用到的变量
	// 定义对输入数据的处理变量
	int m_nInRows; /* 输入的总行数 */
	int m_nInCurRow; /* 输入Buffer的当前行数 */
	int m_nInTotalWidth; /* 输入数据的数组总宽度 */
	int m_nInColumns; /* 输入的列数 */
	int m_nInSingles; /* 输入的单个项目的个数 */
	int m_nInBeginArray; /* 输入数组的开始位置 */
	int m_nInArrayWidth[]; /* 每一列的宽度,最多支持40列 */
	int m_nInArrayOffset[]; /* 每一列的开始偏移量 */
	int m_nInFieldLen[]; /* 单个项目的长度 */
	int m_nInFieldOffset[]; /* 单个项目的偏移量 */
	String m_szInFieldName[]; /* 单个项目的名称 */

	// 合并数据包要用到的变量
	// 定义对输出数据的处理变量
	int m_nRows;
	int m_nColumns;
	int m_nWidthTotal;
	int m_nArrayBegin; /* 数组在pBufferOut的开始位置 */
	int m_nArrayWidth[]; /* 每一列的宽度,最多支持40列 */
	int m_nArrayOffset[];
	int m_nFieldNum; /* 单个数据的个数 */
	int m_nCurBaseLen; /* 当前Base Buffer中的数据长度 */
	int m_nFieldLen[]; /* 输出的单个项目的长度 */
	int m_nFieldOffSet[]; /* 输出的单个项目的偏移 */
	byte m_szFieldName[]; /* 单个项目的名称 */
	byte m_szBaseBuffer[];
	int m_nTotalBytes;

	// 处理超长数据要用到的变量
	int m_nInFileRows = 0;
	int m_nInBufferRows = 0;
	String m_szFileName = "";

	public JMwc() {
		MW_Init2();
		return;
	}

	// 入参abFlag:是否直接拼字符串方式
	public JMwc(boolean abFlag) {
		MW_Init2();
		m_bFlagPackage = abFlag;
		return;
	}

	/*
	 * 指定输出缓冲区中多行数据的缓冲大小的构造函数
	 */
	public JMwc(int anRowBufferSize) {
		m_cbOutBuffer = MAX_BASE_LENGTH + anRowBufferSize;
		MW_Init2();
		return;
	}

	// 入参abFlag:是否直接拼字符串方式
	public JMwc(int anRowBufferSize, boolean abFlag) {
		m_cbOutBuffer = MAX_BASE_LENGTH + anRowBufferSize;
		MW_Init2();
		m_bFlagPackage = abFlag;
		return;
	}

	/**
	 * 初始化函数,不再对外提供调用
	 */
	private void MW_Init2() {
		m_bFlagPackage = false;
		m_nInArrayWidth = new int[MAX_FIELD_NUM];
		m_nInArrayOffset = new int[MAX_FIELD_NUM];
		m_nInFieldLen = new int[MAX_FIELD_NUM];
		m_nInFieldOffset = new int[MAX_FIELD_NUM];
		m_szInFieldName = new String[MAX_FIELD_NUM];

		m_nArrayWidth = new int[MAX_FIELD_NUM];
		m_nArrayOffset = new int[MAX_FIELD_NUM];
		m_nFieldLen = new int[MAX_FIELD_NUM];
		m_nFieldOffSet = new int[MAX_FIELD_NUM];
		m_szFieldName = new byte[MAX_FIELD_NUM * (MAX_SINGLE_NAME_LEN+4)];
		m_pOutBuffer = new byte[m_cbOutBuffer];
		m_szBaseBuffer = new byte[MAX_BASE_LENGTH];

		MW_ClearBuffer();
		return;
	}

	// 供外部调用的初始化
	public void MW_Init() {
		MW_ClearBuffer();
		return;
	}

	// 设置是否去除空格,default=true
	public void MW_SetAutoTrim(int aiTrimType) {
		AUTO_TRIM = aiTrimType;
		return;
	}

	// 调用指定的SERVICE,并返回响应包
	public int MW_CallProgram(String aszServiceName) {

		if (m_cbOutBuffer > CConst.MAX_BUFF_LEN) {
			m_szErrMsg = "buff is over maxLength";
			Util.writeBuffOverMaxLen(new String(m_pOutBuffer));
			return -1;
		}
		DoBufferOut();
		// System.out.println("OUT2:"+new String(m_pOutBuffer,0,m_nTotalBytes));
		return MW_CallProgram(aszServiceName, new String(m_pOutBuffer, 0,
				m_nTotalBytes));
	}

	// 调用指定的SERVICE,并返回响应包
	public int MW_CallProgram(String aszServiceName, String aszStringArgs) {
		m_szErrMsg = "";
		m_nInRows = 0; /* 输入的总行数 */
		m_nInCurRow = 0; /* 输入Buffer的当前行数 */
		m_nInTotalWidth = 0; /* 输入数据的数组总宽度 */
		m_nInColumns = 0; /* 输入的列数 */
		m_nInSingles = 0; /* 输入的单个项目的个数 */
		m_nInBeginArray = 0; /* 输入数组的开始位置 */
		try {
			m_pInBuffer = SF.CallProgram("", "", "", aszServiceName,
					aszStringArgs);
		} catch (Exception e) {
			System.err.println("MW_CallProgram() " + e.getMessage());
			e.printStackTrace();
			// m_szErrMsg = "系统错误!请检查WEB服务器与应用服务器的连接是否正常.";
			m_szErrMsg = "SYSTEMERROR:(" + e.getMessage() + ")";
			m_szErrMsg = "调用服务失败";

			// m_cbInBuffer = 0;
			m_nInRows = 0; /* 输入的总行数 */
			m_nInCurRow = 0; /* 输入Buffer的当前行数 */
			m_nInTotalWidth = 0; /* 输入数据的数组总宽度 */
			m_nInColumns = 0; /* 输入的列数 */
			m_nInSingles = 0; /* 输入的单个项目的个数 */
			m_nInBeginArray = 0; /* 输入数组的开始位置 */

			return -1;
		}

		// m_cbInBuffer = m_pInBuffer.length;
		return DoBufferIn();
	} // End of CallProgram

	public void MW_ClearBuffer() {
		int i = 0;

		for (i = 0; i < m_cbOutBuffer; i++)
			m_pOutBuffer[i] = 0x20; // 0x20:空格
		for (i = 0; i < (MAX_FIELD_NUM * (MAX_SINGLE_NAME_LEN+4)); i++)
			m_szFieldName[i] = 0x20;
		for (i = 0; i < MAX_BASE_LENGTH; i++)
			m_szBaseBuffer[i] = 0x20;
		m_nRows = 0;
		m_nColumns = 0;
		m_nArrayBegin = 0; /* 数组在pBufferOut的开始位置 */
		m_nFieldNum = 0; /* 单个数据的个数 */
		// m_cbInBuffer = 0;
		m_pInBuffer = new byte[0];
		m_nTotalBytes = 0;
		m_nCurBaseLen = 0;

		return;
	}

	// 取得服务端的响应包,当调用CallProgram成功时调用本函数以取得响应包
	public String MW_GetBuffer() {
		return (new String(m_pInBuffer));
	}

	// 当调用CallProgram失败时调用本函数以取得错误消息
	public String MW_GetErrorMsg() {
		return m_szErrMsg;
	}

	// 取得错误代码。该代码对应后台CMidware::terminate(int aiReturn,int aiErrsys,char
	// *aszErrsysText,BOOL abRollBackDB)的第二个参数aiErrsys
	public int MW_GetErrSysCode() {
		return m_iErrSysCode;
	}

	// 以下为按前台营收的方式设置请求包或拆解响应包
	// 为服务设置指定名称的值
	public boolean MW_SetValue(String aszFieldName, String aszValue) {
		int nThisLen = 0;

		if (m_bFlagPackage == true)
			return false; // 直接拼字符串的中间件方式时不能调用此方法
		if (m_nFieldNum >= MAX_FIELD_NUM)
			return false; // 单个的个数超出
		if (m_nCurBaseLen + aszValue.length() > MAX_BASE_LENGTH)
			return false; // 数据超长
		/* 设名称,10位 */
		nThisLen = aszFieldName.length();
		if (nThisLen > MAX_SINGLE_NAME_LEN)
			nThisLen = MAX_SINGLE_NAME_LEN;
		System.arraycopy(aszFieldName.getBytes(), 0, m_szFieldName,
				m_nFieldNum * (MAX_SINGLE_NAME_LEN+4), nThisLen);

		/* 设长度4位 */
		nThisLen = aszValue.length();
		if (nThisLen > 4000)
			nThisLen = 4000;
		System.arraycopy((String.valueOf(nThisLen)).getBytes(), 0,
				m_szFieldName, m_nFieldNum * (MAX_SINGLE_NAME_LEN+4) + MAX_SINGLE_NAME_LEN,
				(String.valueOf(nThisLen)).length());
		m_nFieldNum++;

		/* 设数据,按实际大小存放,最大nLen */
		System.arraycopy(aszValue.getBytes(), 0, m_szBaseBuffer, m_nCurBaseLen,
				nThisLen);
		m_nCurBaseLen += nThisLen;

		return true;
	}

	// 为服务指定数组的宽度及列数
	public boolean MW_SetColCount(int[] nWidth) {
		int i;

		m_nColumns = nWidth.length;
		m_nRows = 0;

		for (i = 0; i < m_nColumns; i++) {
			m_nArrayWidth[i] = nWidth[i];
			m_nArrayOffset[i] = m_nWidthTotal;
			m_nWidthTotal += m_nArrayWidth[i];
		}
		m_nArrayBegin = 8 + 8 + 18 + m_nColumns * 3; // 数组数据的开始位置

		return true;
	}

	// 为服务增加一行入参
	public boolean MW_AddRow() {
		m_nRows++;
		// 超长时需要重新申请内存,每次增加4K
		if ((m_nArrayBegin + m_nWidthTotal * m_nRows) > (m_cbOutBuffer - MAX_BASE_LENGTH)) {
			byte[] pTempBuffer = m_pOutBuffer;
			m_pOutBuffer = new byte[m_cbOutBuffer + 4000];
			System.arraycopy(pTempBuffer, 0, m_pOutBuffer, 0, m_cbOutBuffer);
			// 只对新增加的赋初值
			for (int i = m_cbOutBuffer; i < m_cbOutBuffer + 4000; i++)
				m_pOutBuffer[i] = 0x20; // 0x20:空格
			m_cbOutBuffer += 4000;
		}
		if (m_cbOutBuffer > CConst.MAX_BUFF_LEN) {
			Util.writeBuffOverMaxLen(new String(m_pOutBuffer));
			return false;
		}
		return true;
	}

	// 为服务设定当前行的第nCol列的值
	public boolean MW_SetColValue(int nCol, String pValue) {
		int nThisLen = 0;

		if (nCol > m_nColumns)
			return false;
		nThisLen = (pValue.length() > m_nArrayWidth[nCol - 1]) ? m_nArrayWidth[nCol - 1]
				: pValue.length();
		System.arraycopy(pValue.getBytes(), 0, m_pOutBuffer, m_nArrayBegin
				+ m_nWidthTotal * (m_nRows - 1) + m_nArrayOffset[nCol - 1],
				nThisLen);
		return true;
	}

	// 调用服务之前立即执行的打包过程
	private boolean DoBufferOut() {
		/*
		 * 输出Buffer的内容 总字节数(8)ai_return(4)errpb(6位)errsys(6位)Icon(1)Button(1)
		 * 数组行数(6)数组列数(2)每一列的宽度(n * 3),如果行数 = 0;则后面的将没有; 数组数据
		 * MsgPbLen(2)MsgPb()MsgSysLen(2)MsgSys()
		 * :如果errpb!=0有MsgPb,如果有errsys!=0有MsgSys 单个数据的个数(2)不可能超过50个数据
		 * Name(MAX_SINGLE_NAME_LEN)DataLen(4) szBaseBuffer的1000之后是单个数据的实际数据块 Data(根据长度决定)
		 */
		// 计算总长度
		int lTotalLen = 0;
		int nCurLen = 0;
		int i = 0;

		if (m_bFlagPackage)
			return true; // 不需要打包的直接返回
		nCurLen = 0;
		lTotalLen = 8 + 8 + m_nColumns * 3 + m_nRows * m_nWidthTotal + 2
				+ m_nFieldNum * (MAX_SINGLE_NAME_LEN+4) + m_nCurBaseLen;
		lTotalLen += 18;
		i = (String.valueOf(lTotalLen)).length();
		if (i > 8)
			i = 8;
		System.arraycopy((String.valueOf(lTotalLen)).getBytes(), 0,
				m_pOutBuffer, nCurLen, i);
		// ai_return(4)errpb(6位)errsys(6位)Icon(1)Button(1)均为0,不设置值,以空格填充
		nCurLen += 8 + 4 + 6 + 6 + 1 + 1;
		System.arraycopy((String.valueOf(m_nRows)).getBytes(), 0, m_pOutBuffer,
				nCurLen, (String.valueOf(m_nRows)).length());
		nCurLen += 6;
		System.arraycopy((String.valueOf(m_nColumns)).getBytes(), 0,
				m_pOutBuffer, nCurLen, (String.valueOf(m_nColumns)).length());
		nCurLen += 2;
		// 将各列的宽度拼入Buffer
		for (i = 0; i < m_nColumns; i++) {
			System.arraycopy((String.valueOf(m_nArrayWidth[i])).getBytes(), 0,
					m_pOutBuffer, nCurLen, (String.valueOf(m_nArrayWidth[i]))
							.length());
			nCurLen += 3;
		}
		nCurLen += m_nRows * m_nWidthTotal;
		// 单项的个数
		System.arraycopy((String.valueOf(m_nFieldNum)).getBytes(), 0,
				m_pOutBuffer, nCurLen, (String.valueOf(m_nFieldNum)).length());
		nCurLen += 2;
		// 单项的FieldName
		System.arraycopy(m_szFieldName, 0, m_pOutBuffer, nCurLen,
				m_nFieldNum * (MAX_SINGLE_NAME_LEN+4));
		nCurLen += m_nFieldNum * (MAX_SINGLE_NAME_LEN+4);
		// 单项的数据
		System.arraycopy(m_szBaseBuffer, 0, m_pOutBuffer, nCurLen,
				m_nCurBaseLen);
		nCurLen += m_nCurBaseLen;
		System.arraycopy("ABC#".getBytes(), 0, m_pOutBuffer, nCurLen, 4);
		nCurLen += 4;
		m_nTotalBytes = nCurLen;
		return true;
	}

	// 调用服务
	// 调用服务之后立即执行的解包过程
	private int DoBufferIn() {
		/*
		 * 输入Buffer的内容 总字节数(8位)ai_return(4)errpb(6位)errsys(6位)Icon(1)Button(1)
		 * 上述长度 = 26,其中Icon和Button用0、1、2、3、4...代替 数组行数(6)数组列数(2)每一列的宽度(n *
		 * 3),如果行数 = 0;则后面的将没有; 数组的开始的总长度:26 + 8 + n * 3 数组(数组函数*WidthTotal)
		 * 数组之后的数据 MsgPbLen(2)MsgPb()MsgSysLen(2)MsgSys()
		 * :如果errpb!=0有MsgPb,如果有errsys!=0有MsgSys 单个数据的个数(2)不可能超过50个数据
		 * Name(MAX_SINGLE_NAME_LEN)DataLen(4) szBaseBuffer的1000之后是单个数据的实际数据块 Data(根据长度决定)
		 */
		// 分解返回的结果到本地变量
		int nCurLen = 0;
		// int lErrSys = 0;
		// int iIcon = 0;
		// int iButton = 0;
		int nLen = 0;
		int iReturn = 0;
		int lErrPb = 0;
		int nTotalLen = 0;
		int i = 0;

		m_szErrMsg = "";
		if (m_bFlagPackage)
			return 0; // 不需要打包的直接返回

		// System.out.println("----0" + new String(m_pInBuffer,0,8));
		//nTotalLen 1-8位
		nTotalLen = 0;
		nCurLen = 0;
		try {
			nTotalLen = Integer
					.parseInt((new String(m_pInBuffer, 0, 8)).trim());
		} catch (Exception e) {
			System.err.println("DoBufferIn() " + e.getMessage());
			e.printStackTrace();
			m_szErrMsg = "数据包错误!" + e.getMessage();
			return -1;
		}
		nCurLen += 8;

		// System.out.println("----10#" + String.valueOf(nTotalLen) + "#" +
		// new String(m_pInBuffer));
		// 最后四位必须是ABC#
		if (m_pInBuffer[nTotalLen] != 'A' || m_pInBuffer[nTotalLen + 1] != 'B'
				|| m_pInBuffer[nTotalLen + 2] != 'C'
				|| m_pInBuffer[nTotalLen + 3] != '#') {
			m_szErrMsg = "数据不完整,可能是通信中数据丢失!";
			return -1;
		}

		// System.out.println("----20");
		// 取iReturn值、ERRPB、ERRSYS的值
		//iReturn4位: 9-12位
		try {
			iReturn = Integer.parseInt((new String(m_pInBuffer, nCurLen, 4))
					.trim());
		} catch (Exception e) {
			System.err.println("DoBufferIn() " + e.getMessage());
			e.printStackTrace();
			m_szErrMsg = "数据包错误!" + e.getMessage();
			return -1;
		}
		nCurLen += 4;
		
		//lErrPb 6位 13-18
		try {
			lErrPb = Integer.parseInt((new String(m_pInBuffer, nCurLen, 6))
					.trim());
		} catch (Exception e) {
			System.err.println("DoBufferIn() " + e.getMessage());
			e.printStackTrace();
			m_szErrMsg = "数据包错误!" + e.getMessage();
			return -1;
		}
		nCurLen += 6;
		//m_iErrSysCode 6位 19-24
		try {
			m_iErrSysCode = Integer.parseInt((new String(m_pInBuffer, nCurLen,
					6)).trim());
		} catch (Exception e) {
			System.err.println("DoBufferIn() " + e.getMessage());
			e.printStackTrace();
			m_szErrMsg = "数据包错误!" + e.getMessage();
			return -1;
		}
		nCurLen += 6;
		
		
		// 忽略ICON、BUTTON 25,26
		nCurLen += 2;
		// System.out.println("----30");

		// 行数&列数
		m_nInRows = 0;
		m_nInCurRow = 0;
		m_nInColumns = 0;
		m_nInSingles = 0;
		m_nInTotalWidth = 0;
		
		//m_nInRows 6位 27-32
		try {
			m_nInRows = Integer.parseInt((new String(m_pInBuffer, nCurLen, 6))
					.trim());
		} catch (Exception e) {
			System.err.println("DoBufferIn() " + e.getMessage());
			e.printStackTrace();
			m_szErrMsg = "数据包错误!" + e.getMessage();
			return -1;
		}
		nCurLen += 6;
		
		//m_nInColumns 2位 33-34
		try {
			m_nInColumns = Integer
					.parseInt((new String(m_pInBuffer, nCurLen, 2)).trim());
		} catch (Exception e) {
			System.err.println("DoBufferIn() " + e.getMessage());
			e.printStackTrace();
			m_szErrMsg = "数据包错误!" + e.getMessage();
			return -1;
		}
		nCurLen += 2;
		// System.out.println("----40");

		// 取得每一列的宽度
		for (i = 0; i < m_nInColumns; i++) {
			try {
				m_nInArrayWidth[i] = Integer.parseInt((new String(m_pInBuffer,
						nCurLen, 3)).trim());
			} catch (Exception e) {
				System.err.println("DoBufferIn() " + e.getMessage());
				e.printStackTrace();
				m_szErrMsg = "数据包错误!" + e.getMessage();
				return -1;
			}
			nCurLen += 3;

			m_nInArrayOffset[i] = m_nInTotalWidth;
			m_nInTotalWidth += m_nInArrayWidth[i];
		}
		m_nInBeginArray = nCurLen;
		// System.out.println("----50");

		// 数据包超长时所有数组内容均在文件中
		if (m_iErrSysCode == MW_RC_LONG_PKG && iReturn == -1)
			m_nInFileRows = m_nInRows;
		else {
			m_nInBufferRows = m_nInRows;
			m_nInFileRows = 0;
		}

		nCurLen += m_nInTotalWidth * (m_nInRows - m_nInFileRows);
		if (lErrPb != 0) {
			try {
				nLen = Integer.parseInt((new String(m_pInBuffer, nCurLen, 2))
						.trim());
			} catch (Exception e) {
				System.err.println("DoBufferIn() " + e.getMessage());
				e.printStackTrace();
				m_szErrMsg = "数据包错误!" + e.getMessage();
				return -1;
			}
			nCurLen += 2;

			try {
				m_szErrMsg = new String(m_pInBuffer, nCurLen, nLen,
						CConst.DEFAULT_ENCODING);
			} catch (Exception e) {
				System.err.println("DoBufferIn() " + e.getMessage());
				e.printStackTrace();
				m_szErrMsg = new String(m_pInBuffer, nCurLen, nLen);
			}

			// add by zlg 判断是否是oracle sql 出错信息。若是,则截取
			i = 0;
			i = m_szErrMsg.indexOf("ora");
			if (i < 0) {
				i = m_szErrMsg.indexOf("ORA");
			}
			if (i > 0) {
				m_szErrMsg = "数据库操作出错!";
			}

			nCurLen += nLen;
		}
		if (m_iErrSysCode != 0) {
			try {
				nLen = Integer.parseInt((new String(m_pInBuffer, nCurLen, 2))
						.trim());
			} catch (Exception e) {
				System.err.println("DoBufferIn() " + e.getMessage());
				e.printStackTrace();
				m_szErrMsg = "数据包错误!" + e.getMessage();
				return -1;
			}
			nCurLen += 2;
			try {
				m_szErrMsg = m_szErrMsg
						+ new String(m_pInBuffer, nCurLen, nLen,
								CConst.DEFAULT_ENCODING);

			} catch (Exception e) {
				System.err.println("DoBufferIn() " + e.getMessage());
				e.printStackTrace();
				m_szErrMsg = m_szErrMsg
						+ new String(m_pInBuffer, nCurLen, nLen);
			}
			// add by zlg 判断是否是oracle sql 出错信息。若是,则截取
			i = 0;
			i = m_szErrMsg.indexOf("ora");
			if (i < 0) {
				i = m_szErrMsg.indexOf("ORA");
			}
			if (i > 0) {
				m_szErrMsg = "数据库操作出错!";
			}

			nCurLen += nLen;
		}
		// System.out.println("----60");

		// 处理单个项目的总数
		try {
			m_nInSingles = Integer
					.parseInt((new String(m_pInBuffer, nCurLen, 2)).trim());
		} catch (Exception e) {
			System.err.println("DoBufferIn() " + e.getMessage());
			e.printStackTrace();
			m_szErrMsg = "数据包错误!" + e.getMessage();
			return -1;
		}
		nCurLen += 2;

		System.out.println("----70");
		// 单个项目的名称、长度
		for (i = 0; i < m_nInSingles; i++) {
			m_nInFieldLen[i] = 0;
			m_szInFieldName[i] = (new String(m_pInBuffer, nCurLen, MAX_SINGLE_NAME_LEN)).trim();
			nCurLen += MAX_SINGLE_NAME_LEN;

			try {
				m_nInFieldLen[i] = Integer.parseInt((new String(m_pInBuffer,
						nCurLen, 4)).trim());
			} catch (Exception e) {
				System.err.println("DoBufferIn() " + e.getMessage());
				e.printStackTrace();
				m_szErrMsg = "数据包错误!" + e.getMessage();
				return -1;
			}
			nCurLen += 4;
		}
		// 单个项目的实际偏移量
		nTotalLen = nCurLen;
		for (i = 0; i < m_nInSingles; i++) {
			m_nInFieldOffset[i] = nTotalLen;
			nTotalLen += m_nInFieldLen[i];
		}
		// System.out.println("----90");

		return iReturn;
	}

	// 据名字取得后台服务设置的响应值
	public String MW_GetValue(String pFieldName) {
		return MW_GetValue(pFieldName, CConst.DEFAULT_ENCODING);
	}

	// 据名字取得后台服务设置的响应值
	public String MW_GetValue(String pFieldName, String enc) {
		int i = 0;
		int nFieldNameLen = 0;
		boolean bFind = false;
		String szTemp;

		if (m_bFlagPackage == true)
			return ""; // 直接拼字符串的中间件方式时不能调用此方法

		nFieldNameLen = (pFieldName.length() > MAX_SINGLE_NAME_LEN) ? MAX_SINGLE_NAME_LEN : pFieldName.length();
		szTemp = pFieldName.substring(0, nFieldNameLen);
		for (i = 0; i < m_nInSingles; i++) {
			if (m_szInFieldName[i].compareTo(szTemp) == 0) {
				bFind = true;
				break;
			}
		}
		if (bFind == true) {
			try {
				// m_nGetValueCount ++;
				return Util.trim(new String(m_pInBuffer, m_nInFieldOffset[i],
						m_nInFieldLen[i], enc), AUTO_TRIM);
			} catch (Exception e) {
				System.err.println("MW_GetValue() " + e.getMessage());
				e.printStackTrace();
				return "";
			}
		} else
			return "";
	}

	public int MW_GetRows() {
		if (m_bFlagPackage == true)
			return 0; // 直接拼字符串的中间件方式时不能调用此方法
		return m_nInRows;
	}

	// FetchRow
	public boolean MW_FetchRow() {
		if (m_nInCurRow >= m_nInRows)
			return false;
		// m_nGetColValueCount = 0;
		m_nInCurRow++;
		// if(m_nInCurRow > m_nInRows - m_nInFileRows)
		// { //需要从文件中重新取
		// }

		return true;
	}

	// 取得后台服务设置的当前行的第N列值
	public String MW_GetColValue(int nCol) {
		return MW_GetColValue(nCol, CConst.DEFAULT_ENCODING);
	}

	// 取得服务端返回的列数
	public int MW_GetColCount() {
		return m_nInColumns;
	}

	// 取得服务端返回的各列宽度
	public int[] MW_GetColWidth() {
		return m_nInArrayWidth;
	}

	// 取得后台服务设置的当前行的第N列值
	public String MW_GetColValue(int nCol, String enc) {
		int nOffset = 0;
		int nDataLen = 0;
		int j = 0;

		// 当前行已超出,或当前列已超出
		if (m_nInCurRow <= 0 || m_nInCurRow > m_nInRows || nCol > m_nInColumns)
			return "";

		if (m_nInCurRow > m_nInRows - m_nInFileRows)
			return "";
		j = m_nInCurRow % m_nInBufferRows; /* 在当前缓冲区中的第几行 */
		if (j == 0)
			j = m_nInBufferRows;

		nDataLen = m_nInArrayWidth[nCol - 1];
		nOffset = m_nInBeginArray + (j - 1) * m_nInTotalWidth
				+ m_nInArrayOffset[nCol - 1];
		try {
			// System.out.print("m_pInBuffer = "+new String(m_pInBuffer,enc));
			return Util.trim(new String(m_pInBuffer, nOffset, nDataLen, enc),
					AUTO_TRIM);
		} catch (Exception e) {
			System.err.println("MW_GetColValue() " + e.getMessage());
			e.printStackTrace();
			return "";
		}

	}

	// 以下为直接拼字符串的时候按序号设置请求包或读取后台响应包
	// 设置输出的单个项目的长度
	public boolean MW_SetOutFieldLen(int[] aiFieldLen) {
		int i;

		if (m_bFlagPackage == false)
			return false; // 只有直接拼字符串方式时才能调用
		m_nCurBaseLen = 0;
		try {
			m_nFieldNum = aiFieldLen.length;
		} catch (Exception e) {
			System.err.println("MW_SetOutFieldLen() " + e.getMessage());
			e.printStackTrace();
			return false;
		}

		for (i = 0; i < m_nFieldNum; i++) {
			m_nFieldLen[i] = aiFieldLen[i];
			m_nFieldOffSet[i] = m_nCurBaseLen;
			m_nCurBaseLen += aiFieldLen[i];
		}

		for (i = 0; i < m_nCurBaseLen; i++) {
			m_pOutBuffer[i] = 0x20;
		}
		m_nTotalBytes = m_nCurBaseLen;

		return true;
	}

	// 设置输出的单个项目
	public boolean MW_SetOutField(int iSeq, String pValue) {
		int nPos = 0;
		int nStrLen = 0;

		if (m_bFlagPackage == false)
			return false; // 只有直接拼字符串方式时才能调用
		if (m_nCurBaseLen <= 0 || m_nFieldNum <= 0 || m_nFieldNum < iSeq
				|| iSeq <= 0)
			return false;

		if (pValue.length() == 0)
			return true;
		nPos = m_nFieldOffSet[iSeq - 1];
		nStrLen = pValue.length();
		if (nStrLen > m_nFieldLen[iSeq - 1]) {
			nStrLen = m_nFieldLen[iSeq - 1];
		}

		if (nPos >= 0) {
			System.arraycopy(pValue.getBytes(), 0, m_pOutBuffer, nPos, nStrLen);
		}
		return true;
	}

	// 设置输入的单个项目的长度
	public boolean MW_SetInFieldLen(int[] aiFieldLen) {
		int i = 0;
		// int lTemp = 0;

		if (m_bFlagPackage == false)
			return false; // 只有直接拼字符串方式时才能调用
		 System.out.println("MW_SetInFieldLen TEST 1");
		m_nInBeginArray = 0;
		m_nInSingles = aiFieldLen.length;
		for (i = 0; i < m_nInSingles; i++) {
			 System.out.println("i="+String.valueOf(i)+"--aiFieldLen="+String.valueOf(aiFieldLen[i]));
			m_nInFieldLen[i] = aiFieldLen[i];
			m_nInFieldOffset[i] = m_nInBeginArray;
			m_nInBeginArray += aiFieldLen[i];
		}

		return true;
	}

	// 设置输入的数组的长度
	public boolean MW_SetInWidth(int[] aiFieldLen) {
		int i = 0;

		if (m_bFlagPackage == false)
			return false; // 只有直接拼字符串方式时才能调用
		m_nInColumns = aiFieldLen.length;
		for (i = 0; i < m_nInColumns; i++) {
			m_nInArrayWidth[i] = aiFieldLen[i];
			m_nInArrayOffset[i] = m_nInTotalWidth;
			m_nInTotalWidth += aiFieldLen[i];
		}

		return true;
	}

	public boolean MW_SetInRows(int alRows) {
		if (m_bFlagPackage == false)
			return false; // 只有直接拼字符串方式时才能调用
		if (alRows < 0)
			return false;

		m_nInRows = alRows;
		m_nInBufferRows = m_nInRows;
		return true;
	}

	// 取得单个的输入项目
	public String MW_GetSingleValue(int iSeq) {
		return MW_GetSingleValue(iSeq, CConst.DEFAULT_ENCODING);
	}

	// 取得单个的输入项目
	public String MW_GetSingleValue(int iSeq, String enc) {
		if (m_bFlagPackage == false)
			return ""; // 只有直接拼字符串方式时才能调用
		if (iSeq <= 0 || iSeq > m_nInSingles)
			return "";
		else {
			try {
				return Util.trim(new String(m_pInBuffer,
						m_nInFieldOffset[iSeq - 1], m_nInFieldLen[iSeq - 1],
						enc), AUTO_TRIM);
			} catch (Exception e) {
				System.err.println("MW_GetSingleValue() " + e.getMessage());
				e.printStackTrace();
				return "";
			}
		}
	}

}
系统交易权限校验 axis2 权限校验validatefilter
package com.huawei.logical;

/**
 * 功能:系统交易权限校验
 * 用法:要在AbmServiceMessageReceiverInOut.invokeBusinessLogic()中调用
 *
 * @since 2011-10-24
 */
import javax.servlet.http.HttpServletRequest;

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.log4j.Logger;
import org.apache.axiom.om.OMElement;

import com.huawei.common.Macro;
import com.huawei.common.SysPara;

public class ValidateFilter {
	Logger log = Logger.getLogger(Macro.LOG4J_FILE_COMMON);
	
	public ValidateFilter(org.apache.axis2.description.AxisOperation op) throws AxisFault{
		log.info("ValidateFilter created.");
		if (op == null) {
			throw new org.apache.axis2.AxisFault(
					"Operation is not located, if this is doclit style the SOAP-ACTION should specified via the SOAP Action to use the RawXMLProvider");
		}
		java.lang.String methodName;
		if ((op.getName() != null) && ((methodName = org.apache.axis2.util.JavaUtils.xmlNameToJava(op.getName().getLocalPart())) != null)) {
			log.debug("methodName: " + methodName);
		} else {
			throw new org.apache.axis2.AxisFault("methodName is not found!");
		}
		log.info(methodName.toLowerCase());
		log = Logger.getLogger(methodName.toLowerCase());
	}
	
	/*
	 * 功能:打印请求报文和响应报文
	 * */
	public void logMsg(org.apache.axis2.context.MessageContext msgContext){
		org.apache.axiom.soap.SOAPBody soapBody = msgContext.getEnvelope().getBody();
		log.error(soapBody.toString());
	}
	
	/**
	 * 功能:权限过滤校验
	 * 描述:如果对端没有传入interfaceId,则根据应用配置的默认interfaceId鉴权,并根据addInterfaceElementFlag判断是否要添加interfaceId标签到报文中
	 * 入参:
	 * msgContext: 请求消息
	 * addInterfaceElementFlag:  Macro.NOT_ADD_INTERFACE_ELEMENT-不添加<interfaceId>; Macro.ADD_INTERFACE_ELEMENT-添加
	 * testFlag: "TEST"-不鉴权;其他-鉴权
	 * return: 1.success:鉴权通过 2.other:鉴权不通过,存放失败原因  modifiyed by lcl on 2011.11.17
	 * */
	public String doValidate(org.apache.axis2.context.MessageContext msgContext, int addInterfaceElementFlag, String testFlag)  {
		// Find the axisOperation that has been set by the Dispatch phase.
		log.debug("doValidate start....................");
		org.apache.axis2.description.AxisOperation op = msgContext.getOperationContext().getAxisOperation();
		if (op == null) {
			return "Operation is not located, if this is doclit style the SOAP-ACTION should specified via the SOAP Action to use the RawXMLProvider";
		}
		org.apache.axiom.soap.SOAPBody soapBody = msgContext.getEnvelope().getBody();
		log.debug(soapBody.toString());
		OMElement element = soapBody.getFirstElement().getFirstElement();//获取两次,获取至in0
		log.debug("element.toString()================="+element.toString());
		java.util.Iterator<OMElement> it = element.getChildrenWithName(new javax.xml.namespace.QName("", "interfaceId"));
		OMElement interfaceElement = null;
		String interfaceId = null;
		if (it.hasNext()) {
			interfaceElement = it.next();
			interfaceId = interfaceElement.getText();
			log.debug(interfaceElement.toString());
			log.debug("interfaceElement: " + interfaceId);
			if("".equals(interfaceId)){//加载默认的interfaceId ---modified by lcl on 2011.11.03
				interfaceId = SysPara.getInstance().getInterfaceId();
				log.debug("The default interfaceId is " + interfaceId);
				interfaceElement.setText(interfaceId);
				log.debug("After adding the default interfaceId:\n"+msgContext.getEnvelope().getBody().toString());
			}
			log.debug("interfaceElement.toString()="+interfaceElement.toString());
		} else {
			log.info("<interfaceId> is not found!");
			interfaceId = SysPara.getInstance().getInterfaceId();
			if(addInterfaceElementFlag == Macro.ADD_INTERFACE_ELEMENT){
				addInterfaceIdElement(element);
			}
		}

		java.lang.String methodName;
		if ((op.getName() != null) && ((methodName = org.apache.axis2.util.JavaUtils.xmlNameToJava(op.getName().getLocalPart())) != null)) {
			log.debug("methodName: " + methodName);
		} else {
			return ("methodName is not found!");
		}
		if ("TEST".equals(testFlag)) {
			return Macro.SUCCESS;
		}
		//根据interfaceId和methodName对交易鉴权
		MessageContext mc = MessageContext.getCurrentMessageContext();
		HttpServletRequest request = (HttpServletRequest) mc.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
		//log.debug("remote  ip:  " + request.getRemoteAddr());

		if (SysPara.getInstance().getInterfaceInfo(interfaceId) == null) {
			log.info("InterfaceId is not authorized! ["+interfaceId+"]");		
			return "InterfaceId is not authorized!";
		}
		//由于部署到weblogic的F5上无法获取真实的客户端ip地址,故作废关于ip的校验
		/*if (SysPara.getInstance().getInterfaceInfo(interfaceId).checkIp(request.getRemoteAddr()) == false) {
			log.info("Remote IP is not authorized! ["+request.getRemoteAddr()+"]");
			return "Remote IP is not authorized!";
		}*/

		if (SysPara.getInstance().getInterfaceInfo(interfaceId).checkService(methodName) == false) {
			log.info(methodName + " is not authorized to " + interfaceId + ".The service Id is " + Macro.getServiceId(methodName));
			return methodName + " is not authorized to " + interfaceId + ".The service Id is " + Macro.getServiceId(methodName);
		}
		return Macro.SUCCESS;
	}
	
	/*
	 * 功能:添加从配置文件中读取的默认interfaceId到指定位置,即element的子元素
	 * 入参:OMElement element <interfaceId>的元素
	 * 返回:
	 * */
	private boolean addInterfaceIdElement(OMElement element){
		log.debug("add <interfaceId>!");
		OMElement interfaceElement = null;
		String interfaceId = null;
		/*添加系统默认的interfaceId Begin. ---added by lcl on 2011.11.02*/
		log.debug("load the default <interfaceId> Begin.");
		interfaceElement = element.getOMFactory().createOMElement("interfaceId", element.getOMFactory().createOMNamespace("", ""));//新增一个节点
		interfaceElement.setText(SysPara.getInstance().getInterfaceId());//从内存获取
		log.debug("interfaceElement.toString()="+interfaceElement.toString());
		element.addChild(interfaceElement);
		log.debug("The default <interfaceId> is " + SysPara.getInstance().getInterfaceId());
		log.debug("load the default <interfaceId> End.");
		/*添加系统默认的interfaceId End.*/
		return true;
	}
	
	
}
SysPara syspara 常用数据缓存内存
package com.huawei.common;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.log4j.Logger;

import com.huawei.tuxedo.util.BeanExeSelect;
import com.huawei.tuxedo.util.TuxedoServiceBean;

/**
 * 功能:系统参数类
 * 
 * 
 * @since 2011-10-24
 */
public class SysPara {
	// 已经自行实例化
	private static final SysPara instance = new SysPara();
	private Logger log = Logger.getLogger(Macro.LOG4J_FILE_COMMON);
	private Map<String, InterfaceInfo> interfaceInfoMap;
	private String interfaceId;//interfaceId的默认值 --added by lcl on 2011.11.02
	private TuxedoServiceBean tsb;
	private BeanExeSelect beanExeSelect = null;
	private String activeBalanceGroupId="";//营销活动余额类型大类节点ID
	/**add  20120806  begin **/
	private static Map<String,String> treeStructItem994Map;//加载tree_struct_item_t表中tree_type_id=994的数据
	private static Map<String,String> treeStructMap;//加载tree_struct_t表中数据
	/**add  20120806  end **/
	
	// 私有的默认构造子
	private SysPara() {
		log.info("SysPara init");
		tsb = new TuxedoServiceBean();
		beanExeSelect = new BeanExeSelect();
		freshPara();
		loadTreeStructInfo();//add 20120806
	}

	// 静态工厂方法
	public static SysPara getInstance() {
		return instance;
	}

	// 刷新参数
	synchronized public boolean freshPara() {
		//清空原有数据
		if (interfaceInfoMap != null) {
			interfaceInfoMap.clear();
			interfaceInfoMap = null;
		}
		interfaceInfoMap = new HashMap<String, InterfaceInfo>();
		// 加载配置文件中默认参数 --added by lcl on 2011.11.02
		if (this.loadWsConfig() == false) {
			return false;
		}
		// 加载接口信息
		if (this.freshInterfaceInfo() == false) {
			return false;
		}
		// 加载交易权限参数
		if (this.freshInterfaceService() == false) {
			return false;
		}
		Collection<InterfaceInfo> collectionInterface = interfaceInfoMap.values();
		Iterator<InterfaceInfo> it = collectionInterface.iterator();
		for (; it.hasNext();) {
			it.next().printInfo();
		}
		return true;
	}

	private boolean freshInterfaceInfo() {
		// 加载接口信息
		beanExeSelect = new BeanExeSelect();
		beanExeSelect.setSQL("SELECT a.interface_id,a.interface_name,a.staff_id,a.site_id,b.begin_ip,b.end_ip "
				+ "FROM BILL_INTERFACE_INFO_T a,STAFF_BIND_IP_T b " + "WHERE a.staff_id=b.staff_id AND a.site_id=b.site_id "
				+ "AND a.interface_type='" + Macro.INTERFACE_TYPE_WEBSERVICE + "' order by a.interface_id");
		beanExeSelect.setServiceName("GSELECT_S");
		if (beanExeSelect.callService() == 0) {
			String[][] result = beanExeSelect.getResult();
			if (result == null) {
				return false;
			}
			for (int i = 0; i < result.length; i++) {
				String tmpInterfaceId = result[i][0];
				InterfaceInfo tmpInterface = interfaceInfoMap.get(tmpInterfaceId);
				if (tmpInterface == null) {
					tmpInterface = new InterfaceInfo();
					tmpInterface.setInterfaceId(tmpInterfaceId);
					tmpInterface.setInterfaceName(result[i][1]);
					tmpInterface.setStaffId(result[i][2]);
					tmpInterface.setSiteId(Integer.parseInt(result[i][3]));
				}
				tmpInterface.addIpList(result[i][4], result[i][5]);
				this.interfaceInfoMap.remove(tmpInterface.getInterfaceId());
				this.interfaceInfoMap.put(tmpInterface.getInterfaceId(), tmpInterface);
			}
		} else {
			log.error("freshPara() error!---beanExeSelect.callService() error!");
			return false;
		}
		return true;

	}

	private boolean loadActiveBalanceGroupId() {
		// 加载接口信息
		beanExeSelect = new BeanExeSelect();
		log.debug("SQL:select  PARA from BILL_SYSTEM_PARAMETERS_T where para_type = 'QUERY' and para_flag = 'RET_BALANCE_TYPE_GROUP'");
		beanExeSelect.setSQL("select  PARA from BILL_SYSTEM_PARAMETERS_T where para_type = 'QUERY' and para_flag = 'RET_BALANCE_TYPE_GROUP'");
		beanExeSelect.setServiceName("GSELECT_S");
		//int nBalanceTypeID=-1;
		if (beanExeSelect.callService() == 0) {
			String[][] result = beanExeSelect.getResult();
			if (result == null || result.length ==0) {
				return false;
			}
			//营销活动余额类型大类节点ID
			activeBalanceGroupId=result[0][0];
			log.debug("activeBalanceGroupId:"+activeBalanceGroupId);
			return true;
		} else {
			log.error("取营销活动余额类型大类节点ID失败!---beanExeSelect.callService() error!");
			return true;
		}
	}

	
	private boolean freshInterfaceService() {
		// 加载接口交易权限信息
		beanExeSelect = new BeanExeSelect();
		beanExeSelect
				.setSQL("SELECT a.interface_id,b.ctrl_flag " + "FROM BILL_INTERFACE_INFO_T a, BILL_REGION_CONTROL_t b "
						+ "WHERE a.staff_id=b.staff_id " + "AND a.interface_type='" + Macro.INTERFACE_TYPE_WEBSERVICE
						+ "' order by a.interface_id");
		beanExeSelect.setServiceName("GSELECT_S");
		if (beanExeSelect.callService() == 0) {
			String[][] result = beanExeSelect.getResult();
			if (result == null) {
				return false;
			}
			for (int i = 0; i < result.length; i++) {
				String tmpInterfaceId = result[i][0];
				InterfaceInfo tmpInterface = interfaceInfoMap.get(tmpInterfaceId);
				if (tmpInterface == null) {
					log.error("Please freshInterfaceInfo first.");
					continue;
				}
				tmpInterface.addService(result[i][1]);
				this.interfaceInfoMap.remove(tmpInterface.getInterfaceId());
				this.interfaceInfoMap.put(tmpInterface.getInterfaceId(), tmpInterface);
			}
		} else {
			log.error("freshInterfaceService() error!---beanExeSelect.callService() error!");
			return false;
		}
		return true;

	}

	public InterfaceInfo getInterfaceInfo(String interfaceId) {
		return interfaceInfoMap.get(interfaceId);
	}

	/**
	 * 从properties配置文件加载WebService系统参数
	 * 
	 * @return
	 * @Author: l90080613
	 */
	public boolean loadWsConfig() {
		String fileName = "wsconfig.properties";
		Configuration config = new Configuration(fileName);
		this.interfaceId = config.getValue("INTERFACE_ID");
		if (this.interfaceId == null) {
			return false;
		}
		return true;
	}


	/**
	 * 获取默认的接口标识
	 * @return
	 * @Author: l90080613
	 */
	public String getInterfaceId() {
		return interfaceId;
	}
	
	/**
	 * 获取营销活动余额类型大类节点ID
	 * @return
	 * @Author: l90080613
	 */
	public String getActiveBalanceGroupId() {
		
		loadActiveBalanceGroupId();		
		return activeBalanceGroupId;
	}
	
	/**
	 * 打印内存中已加载的接口标识
	 * 
	 * @Author: l90080613
	 */
	public void printInteraceId(){
		Collection<InterfaceInfo> c = interfaceInfoMap.values();
        Iterator it = c.iterator();
        for (; it.hasNext();) {
           InterfaceInfo interfaceInfo = (InterfaceInfo)it.next();
           interfaceInfo.printInfo();
        }
	}
	
	/**
	 * 加载费用展示树数据
	 *  
	 * @return
	 */
	synchronized public boolean loadTreeStructInfo() {
		
		log.info("加载费用展示树数据.......");
		//清空原有数据
		if (treeStructItem994Map != null) {
			treeStructItem994Map.clear();
			treeStructItem994Map = null;
		}
		treeStructItem994Map = new HashMap<String, String>();
		
		if (treeStructMap != null) {
			treeStructMap.clear();
			treeStructMap = null;
		}
		treeStructMap = new HashMap<String, String>();
		
		// 加载tree_struct_item_t数据
		if (this.loadTreeStructItem994Data() == false) {
			return false;
		}
		// 加载、tree_struct_t数据
		if (this.loadTreeStructMapData() == false) {
			return false;
		}
		log.info("加载费用展示树数据完成......");
		return true;
	}
	
	
	/**
	 * 加载费用展示树(tree_struct_item_t)
	 * 
	 *(where tree_type_id=994)
	 *
	 * treeStructItem994Map<itemId,nodeId>
	 * 
	 * @return  
	 */
	private boolean loadTreeStructItem994Data() {
		// 加载接口信息
		beanExeSelect = new BeanExeSelect();
		log.debug("SQL:select item_id,node_id from tree_struct_item_t t where t.tree_type_id = '994'");
		beanExeSelect.setSQL("select item_id,node_id from tree_struct_item_t t where t.tree_type_id = '994'");
		beanExeSelect.setServiceName("GSELECT_S");
		if (beanExeSelect.callService() == 0) {
			String[][] result = beanExeSelect.getResult();
			if (result == null || result.length ==0) {
				return false;
			}
			for (int i = 0; i < result.length; i++) {
				String itemId = result[i][0];
				String nodeId = result[i][1];
				treeStructItem994Map.put(itemId, nodeId);
			}
			return true;
		} else {
			log.error("取tree_struct_item_t表中tree_type_id=994数据失败!---beanExeSelect.callService() error!");
			return true;
		}
	}
	
	/**
	 * 加载树信息(tree_struct_t)
	 * 
	 * treeStructMap<nodeId,nodeName>
	 * 
	 * @return  
	 */
	private boolean loadTreeStructMapData() {
		// 加载接口信息
		beanExeSelect = new BeanExeSelect();
		log.debug("SQL:select node_id,node_name from tree_struct_t t where t.tree_type_id = '994'");
		beanExeSelect.setSQL("select node_id,node_name from tree_struct_t t where t.tree_type_id = '994'");
		beanExeSelect.setServiceName("GSELECT_S");
		if (beanExeSelect.callService() == 0) {
			String[][] result = beanExeSelect.getResult();
			if (result == null || result.length ==0) {
				return false;
			}
			for (int i = 0; i < result.length; i++) {
				String nodeId = result[i][0];
				String nodeName = result[i][1];
				treeStructMap.put(nodeId, nodeName);
			}
			return true;
		} else {
			log.error("取加载树信息(tree_struct_t)失败!---beanExeSelect.callService() error!");
			return true;
		}
	}
	
	
	public Map<String, String> getTreeStructItem994Map() {
		return treeStructItem994Map;
	}

	public void setTreeStructItem994Map(Map<String, String> treeStructItem994Map) {
		this.treeStructItem994Map = treeStructItem994Map;
	}

	public Map<String, String> getTreeStructMap() {
		return treeStructMap;
	}

	public void setTreeStructMap(Map<String, String> treeStructMap) {
		this.treeStructMap = treeStructMap;
	}

}
Configuration configuration
package com.huawei.common;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * 读取properties文件
 * 
 * 
 * @date 201001
 * 
 *       
 */
public class Configuration {
	private Properties propertie;
	private FileInputStream inputFile;
	private FileOutputStream outputFile;
	private Logger logger = Logger.getLogger(Macro.LOG4J_FILE_COMMON);
	private String defaultFileName = "wsconfig.properties";//默认的配置文件

	/**
	 * 初始化Configuration类
	 * 
	 * @param fileName
	 *            文件名,不包含路径。默认根路径为axis2.war中的WEB-INF/services目录
	 */
	public Configuration(String fileName) {
		propertie = new Properties();
		if (fileName == null || "".equals(fileName)) {
			fileName = defaultFileName;
		}
		String path = this.getClass().getClassLoader().getResource("").getPath();
		String file = path + "../services/" + fileName;
		logger.info(file + " is loading...");
		try {
			inputFile = new FileInputStream(file);
			propertie.load(inputFile);
			inputFile.close();
		} catch (FileNotFoundException ex) {
			logger.error("FileNotFoundException.File " + file + " dos not exist!");
			ex.printStackTrace();
		} catch (IOException ex) {
			logger.error("IOException.File " + file + " loaded error");
			ex.printStackTrace();
		}
	}

	/**
	 * 初始化Configuration类
	 * 
	 * @param path
	 *            要读取的配置文件的路径,如“D:/XXX/XXX/”
	 * @param fileName
	 *            文件名称
	 */
	public Configuration(String path, String fileName) {
		propertie = new Properties();
		String file = path + fileName;
		try {
			inputFile = new FileInputStream(file);
			propertie.load(inputFile);
			inputFile.close();
		} catch (FileNotFoundException ex) {
			logger.error("FileNotFoundException.File " + file + " dos not exist!");
			ex.printStackTrace();
		} catch (IOException ex) {
			logger.error("IOException.File " + file + " loaded error");
			ex.printStackTrace();
		}
	}

	/**
	 * 重载函数,得到key的值
	 * 
	 * @param key
	 *            取得其值的键
	 * @return key的值
	 */
	public String getValue(String key) {
		if (propertie.containsKey(key)) {
			String value = propertie.getProperty(key);//得到某一属性的值
			return value;
		} else
			return "";
	}

	/**
	 * 获取WebService需要调用的类,即CLASSNAME
	 * 
	 * @param serverID
	 *            WebService服务标识ID
	 * @return key的值
	 */
	public String getWsClassName(String serverID) {
		if (propertie.containsKey(serverID + ".CLASSNAME")) {
			String value = propertie.getProperty(serverID + ".CLASSNAME");//得到某一属性的值
			return value;
		} else
			return "";
	}

	/**
	 * 获取WebService需要调用的方法,即METHOD
	 * 
	 * @param serverID
	 *            WebService服务标识ID
	 * @param methodID
	 *            WebService方法标识ID
	 * @return 调用的方法名
	 */
	public String getWsMethodName(String serverID, String methodID) {
		if (propertie.containsKey(serverID + ".METHOD." + methodID)) {
			String value = propertie.getProperty(serverID + ".METHOD." + methodID);//得到某一属性的值
			return value;
		} else
			return "";
	}

	/**
	 * 获取WebService需要调用的服务URL,即SERV_URL
	 * 
	 * @param serverID
	 *            WebService服务标识ID
	 * @return 服务URL
	 */
	public String getWsServUrl(String serverID) {
		if (propertie.containsKey(serverID + ".SERV_URL")) {
			String value = propertie.getProperty(serverID + ".SERV_URL");//得到某一属性的值
			return value;
		} else
			return "";
	}

	/**
	 * 获取WebService需要调用的命名空间,即NAMESPACE
	 * 
	 * @param serverID
	 *            WebService服务标识ID
	 * @return 命名空间
	 */
	public String getWsNameSpace(String serverID) {
		if (propertie.containsKey(serverID + ".NAMESPACE")) {
			String value = propertie.getProperty(serverID + ".NAMESPACE");//得到某一属性的值
			return value;
		} else
			return "";
	}

	/**
	 * 重载函数,得到key的值
	 * 
	 * @param fileName
	 *            properties文件的路径+文件名
	 * @param key
	 *            取得其值的键
	 * @return key的值
	 */
	public String getValue(String fileName, String key) {
		try {
			String value = "";
			inputFile = new FileInputStream(fileName);
			propertie.load(inputFile);
			inputFile.close();
			if (propertie.containsKey(key)) {
				value = propertie.getProperty(key);
				return value;
			} else
				return value;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return "";
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		} catch (Exception ex) {
			ex.printStackTrace();
			return "";
		}
	}

	/**
	 * 清除properties文件中所有的key和其值
	 */
	public void clear() {
		propertie.clear();
	}

	/**
	 * 改变或添加一个key的值,当key存在于properties文件中时该key的值被value所代替, 当key不存在时,该key的值是value
	 * 
	 * @param key
	 *            要存入的键
	 * @param value
	 *            要存入的值
	 */
	public void setValue(String key, String value) {
		propertie.setProperty(key, value);
	}

	/**
	 * 将更改后的文件数据存入指定的文件中,该文件可以事先不存在。
	 * 
	 * @param fileName
	 *            文件路径+文件名称
	 * @param description
	 *            对该文件的描述
	 */
	public void saveFile(String fileName, String description) {
		try {
			outputFile = new FileOutputStream(fileName);
			propertie.store(outputFile, description);
			outputFile.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}
}
Global site tag (gtag.js) - Google Analytics