adapter结构异常记录

adapter结构异常记录,记录在这个类里,记录数据日志,在148行:

com.creditharmony.adapter.core.service.GeneralHttpService

package com.creditharmony.adapter.core.service;

import java.util.Properties;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.creditharmony.apporveadapter.bean.BaseInfo;
import com.creditharmony.apporveadapter.bean.BaseOutInfo;
import com.creditharmony.apporveadapter.bean.GeneralHttpInfoModel;
import com.creditharmony.apporveadapter.bean.GeneralReturnInfo;
import com.creditharmony.adapter.constant.Constant;
import com.creditharmony.apporveadapter.constant.ErrorType;
import com.creditharmony.adapter.constant.MsgKey;
import com.creditharmony.apporveadapter.exception.AdapterException;
import com.creditharmony.adapter.utils.AdapterUtils;
import com.creditharmony.adapter.utils.Messages;
import com.creditharmony.common.util.PropertyUtil;
import com.creditharmony.common.util.SpringContextHolder;

/**
 * @Class Name GeneralHttpService
 * @author yourname
 * @Create In 2016年12月3日
 */
@Controller
public class GeneralHttpService {
    /** 业务挡板测试区分名. */
    private static final String BAFFLE_FIX = "_Baffle";

    /** 日志. */
    private static final Logger logger = Logger.getLogger(GeneralHttpService.class);

    /** 属性文件. */
    static Properties properties = PropertyUtil.getProperties(Constant.CONFIG_PROPERTY);

    /** HttpServletRequest. */
    @Autowired
    private HttpServletRequest request;

    /** 参数记录处理. */
    @Autowired
    private IParamRecord paramRecord;

    /**
     * Client端调用统一接口.
     * 实现分发器效果
     *
     * @param paramObj 调用参数
     * @return 返回参数
     */
    @ResponseBody
    @RequestMapping(value = "http/generalHttpService", method = RequestMethod.POST)
    public String exec(@RequestParam("content") String content) {

        // 取得唯一序列号
        String serialNum = AdapterUtils.getSerialNum();
        // 获得调用客户端IP地址
        String clientIp = getClientIP(request, serialNum);
        // 大金融的报文转为Model对象
        GeneralHttpInfoModel paramObj = JSON.parseObject(content, GeneralHttpInfoModel.class);

        logger.info(Messages.get(MsgKey.GENERALSERVICE_INPARAM, new String[] { content }));
        // 参数日志记录: 传入参数
        paramRecord.doInParamRecord(
                serialNum,
                content,
                clientIp,
                paramObj.getServiceName());

        // 取得业务参数Json
        String paramStr = paramObj.getParam();

        logger.info(Messages.get(MsgKey.GENERALSERVICE_INPARAM, new String[] { paramStr }));
        // 参数日志记录: 传入参数
        paramRecord.doInParamRecord(
                serialNum,
                paramStr,
                clientIp,
                paramObj.getServiceName());

        /*
         * 处理:取得业务实现类
         * 利用传入的serviceName,通过反射方式取得该业务实际类
         */
        IBaseService baseService = this.initService(paramObj.getServiceName());

        /*
         * 处理:调用实际业务处理
         * 通过父类抽象方法调用实现子类具体业务调用
         */
        GeneralReturnInfo out = new GeneralReturnInfo();
        BaseOutInfo outParam = null;
        // 返回对象参数
        String outParamStr = "";
        try {

            // 将传入的JSON报文转为Bean对象
            BaseInfo inBean = (BaseInfo) JSON.parseObject(paramStr, doCreatInObject(paramObj.getInClassName()).getClass());
            inBean.setSerialNum(serialNum);
            outParam = baseService.exec(inBean);
            out.setOutParam(JSON.toJSONString(outParam, SerializerFeature.WriteMapNullValue));

            outParamStr = JSON.toJSONString(out, SerializerFeature.WriteMapNullValue);

            /*
             * 处理:返回参数记录处理.
             */
            paramRecord.doOutParamRecord(
                    serialNum,
                    outParamStr);
            logger.info(Messages.get(MsgKey.GENERALSERVICE_OUTPARAM, new String[] { outParamStr }));
        } catch (Exception e) {
            boolean isNewExeption = e instanceof AdapterException;

            AdapterException businessException = null;
            // 将新产生的例外封装
            if (isNewExeption == false) {
                businessException = new AdapterException(ErrorType.BUSSINESS_ERROR, e, "接口服务端产生异常.");
            } else {
                businessException = (AdapterException) e;
            }

            out.setErrorType(businessException.getErrorType());
            out.setErrorMsg(businessException.getMessage());
            out.setBaseOutInfo(businessException.getInfoOutObj());
            StringBuilder paramSb = new StringBuilder();

            // 取得返回对象日志
            paramSb.append("errorType=").append(out.getErrorType())
                    .append(", errorMsg=").append(out.getErrorMsg());
            outParamStr = paramSb.toString();

            /*
             * 处理:异常错误记录处理.
             */
            logger.error(Messages.get(
                    MsgKey.ERROR_SYSTEM_STACK, new String[] { businessException.getExceptionStackTrace() }));
            paramRecord.doExceptionRecord(serialNum, businessException);

            /*
             * 处理:返回参数记录处理.
             */
            paramRecord.doOutParamRecord(
                    serialNum,
                    outParamStr);
            logger.info(Messages.get(MsgKey.GENERALSERVICE_OUTPARAM, new String[] { outParamStr }));
        }
        return outParamStr;
    }

    /**
     * 反射传入Bean对象.
     * @param className 传入Bean包名+类名
     * @return Bean对象
     */
    private Object doCreatInObject(String className) {
        Object obj = null;
        try {
            Class<?> c = Class.forName(className);
            obj = c.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return obj;
    }

    /**
     * 获取客户端IP地址.
     *
     * @param serialNum 请求唯一序列号
     * @return IP地址
     */
    private String getClientIP(HttpServletRequest request, String serialNum) {
        try {
            if (request.getHeader("x-forwarded-for") == null) {
                return request.getRemoteAddr();
            }
            return request.getHeader("x-forwarded-for");
        } catch (Exception e) {
            // 异常错误记录
            AdapterException businessException = new AdapterException(e);
            paramRecord.doExceptionRecord(serialNum, businessException);
        }
        return "";
    }

    /**
     * 业务处理类实现.
     * 通过反射,实现业务对象
     * @param serviceName 业务实现类名
     * @return 业务实现类
     */
    private IBaseService initService(String serviceName) {

        String serviceId = "";
        boolean isBaffle = Boolean.parseBoolean(properties.getProperty(serviceName + BAFFLE_FIX));
        // true的场合, 运行挡板程序
        if (isBaffle) {
            // 测试挡板程序
            serviceId = serviceName + BAFFLE_FIX;
        } else {
            serviceId = serviceName;
        }
        IBaseService baseService = SpringContextHolder.getBean(serviceId);
        return baseService;
    }
}

  

时间: 2024-10-27 06:38:18

adapter结构异常记录的相关文章

spring异常记录-----java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils

今天在练习怎样SSH中进行单元測试的时候出现下列异常: SEVERE: Exception starting filter Struts2 java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:211

异常处理——把异常记录下来,log4j的使用

转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6399191.html 在我们的项目运行过程中,偶尔会有预料不到的异常发生.如果能在发生异常时把异常的详细情况,比如什么时候在哪一行代码发生了什么异常,严重级别是多少之类的信息记录下来,那么我们就可以在维护时根据这个记录异常的文件针对性地去修复这些异常了.log4j为我们解决了这个问题. log4j是apache提供给我们的一个处理异常的插件,利用它,我们可以在某些可能出现运行错误的地方用代码做好处理异常的准

Android Adapter的一些记录

一.摘要 An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set. 这是Android官方对Adapter的

Android异常记录--Unable to resolve superclass

当引用到*.jar文件时,报错“Unable to resolve superclass ...” " Just started to get this issue after upgrading to ADT 17. Discovered that external .jar files need to be in a 'libs' (with an s) folder otherwise their classes are not included in the .dex file that

sping异常记录----Could not execute JDBC batch update; nested exception is org.hibernate.excepti

今天在练习如何SSH中进行单元测试的时候出现下列异常: org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.springframe

异常记录(写txt日志文件)

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace WebBuild_CRM.Common { public class ExceptionRecord { public static void RecordException(Exception ex) { FileStream fileStream = null; Str

PHP的日志记录-错误与异常记录

提到 Nginx + PHP 服务的错误日志,我们通常能想到的有 Nginx 的 access 日志.error 日志以及 PHP 的 error 日志.虽然看起来是个很简单的问题,但里面其实又牵扯到应用配置以及日志记录位置的问题,如果是在 ubuntu 等系统下使用 apt-get 的方式来安装,其自有一套较为合理的的配置文件可用.再者运行的应用程序中的配置也会影响到日志记录的方式及内容. 错误与异常的区别 关于错误与异常,兄弟连来给大家举一个简单的例子来理解: <?php try { 1 /

Expo大作战(十七)--expo结合哨兵(sentry)进行错误异常记录

简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人修改补充+demo测试的形式,对expo进行一次大补血!欢迎加入expo兴趣学习交流群:597732981 [之前我写过一些列关于expo和rn入门配置的东i西,大家可以点击这里查看:从零学习rn开发] 相关文章: Expo大作战(一)--什么是expo,如何安装expo clinet和xde,xd

柳叶刀重磅出击!全外显子测序在胎儿结构异常的评估Whole-exome sequencing in the evaluation of fetal structural anomalies: a prospective cohort study

柳叶刀发表的文献解读:Whole-exome sequencing in the evaluation of fetal structural anomalies: a prospective cohort study 背景介绍 随着超声波在产科护理中的应用,胎儿结构异常的鉴别已成为例行公事.当发现异常时,进一步评估核型.全染色体非整倍体与染色体微阵列(CMA)上较小的微缺失和复制(CNV),则是非常的重要.目前研究发现,大约32%结构异常胎儿具有临床相关的异常核型,6%的结构异常胎儿能找到致病